|
- <?php
-
- namespace App\Jobs\File;
-
- use App\Codes\QueueName;
- use App\Files\TmpFile;
- use Illuminate\Bus\Queueable;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Bus\Dispatchable;
- use Illuminate\Queue\InteractsWithQueue;
- use Illuminate\Queue\SerializesModels;
- use Illuminate\Support\Facades\Storage;
-
- class DeleteFile implements ShouldQueue
- {
- use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
-
- private string $fileId;
- private string $storagePath;
-
- /**
- * Create a new job instance.
- *
- * @return void
- */
- public function __construct(
- private TmpFile $file,
- ) {
- $this->onQueue(QueueName::JOB->value);
- $this->fileId = $file->getId();
- $this->storagePath = $file->getPath();
- logger("FILE削除JOB登録:" . $this->storagePath);
- }
-
- /**
- * Execute the job.
- *
- * @return void
- */
- public function handle()
- {
- if (Storage::exists($this->storagePath)) {
- Storage::delete($this->storagePath);
- info(sprintf("ファイル削除:%s ", $this->storagePath));
- }
- }
- }
|