ImageS3DeletePipeline.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Jobs\GroupsPipeline;
  3. use App\Models\GroupMedia;
  4. use App\Util\Media\Image;
  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 Storage;
  11. use Illuminate\Http\File;
  12. use Exception;
  13. use GuzzleHttp\Exception\ClientException;
  14. use Aws\S3\Exception\S3Exception;
  15. use GuzzleHttp\Exception\ConnectException;
  16. use League\Flysystem\UnableToWriteFile;
  17. class ImageS3DeletePipeline implements ShouldQueue
  18. {
  19. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  20. protected $media;
  21. static $attempts = 1;
  22. /**
  23. * Delete the job if its models no longer exist.
  24. *
  25. * @var bool
  26. */
  27. public $deleteWhenMissingModels = true;
  28. /**
  29. * Create a new job instance.
  30. *
  31. * @return void
  32. */
  33. public function __construct(GroupMedia $media)
  34. {
  35. $this->media = $media;
  36. }
  37. /**
  38. * Execute the job.
  39. *
  40. * @return void
  41. */
  42. public function handle()
  43. {
  44. $media = $this->media;
  45. if(!$media || (bool) config_cache('pixelfed.cloud_storage') === false) {
  46. return;
  47. }
  48. $fs = Storage::disk(config('filesystems.cloud'));
  49. if(!$fs) {
  50. return;
  51. }
  52. if($fs->exists($media->media_path)) {
  53. $fs->delete($media->media_path);
  54. }
  55. }
  56. }