領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 line
1.1KB

  1. <?php
  2. namespace App\Jobs\File;
  3. use App\Codes\QueueName;
  4. use App\Files\TmpFile;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. use Illuminate\Support\Facades\Storage;
  11. class DeleteFile implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. private string $fileId;
  15. private string $storagePath;
  16. /**
  17. * Create a new job instance.
  18. *
  19. * @return void
  20. */
  21. public function __construct(
  22. private TmpFile $file,
  23. ) {
  24. $this->onQueue(QueueName::JOB->value);
  25. $this->fileId = $file->getId();
  26. $this->storagePath = $file->getPath();
  27. logger("FILE削除JOB登録:" . $this->storagePath);
  28. }
  29. /**
  30. * Execute the job.
  31. *
  32. * @return void
  33. */
  34. public function handle()
  35. {
  36. if (Storage::exists($this->storagePath)) {
  37. Storage::delete($this->storagePath);
  38. info(sprintf("ファイル削除:%s ", $this->storagePath));
  39. }
  40. }
  41. }