2021-02-06 04:00:29 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\MediaPipeline;
|
|
|
|
|
|
|
|
use App\Media;
|
|
|
|
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\Redis;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
class MediaDeletePipeline implements ShouldQueue
|
|
|
|
{
|
|
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
|
|
|
|
protected $media;
|
|
|
|
|
2022-12-24 09:01:30 +00:00
|
|
|
public $timeout = 300;
|
|
|
|
public $tries = 3;
|
|
|
|
public $maxExceptions = 1;
|
2022-12-24 11:30:02 +00:00
|
|
|
public $deleteWhenMissingModels = true;
|
2022-12-24 09:01:30 +00:00
|
|
|
|
2021-02-06 04:00:29 +00:00
|
|
|
public function __construct(Media $media)
|
|
|
|
{
|
|
|
|
$this->media = $media;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$media = $this->media;
|
|
|
|
$path = $media->media_path;
|
|
|
|
$thumb = $media->thumbnail_path;
|
2021-05-19 04:45:04 +00:00
|
|
|
|
2021-02-06 04:00:29 +00:00
|
|
|
if(!$path) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$e = explode('/', $path);
|
|
|
|
array_pop($e);
|
|
|
|
$i = implode('/', $e);
|
|
|
|
|
2022-12-27 03:04:42 +00:00
|
|
|
if(config_cache('pixelfed.cloud_storage') == true) {
|
2021-02-06 04:00:29 +00:00
|
|
|
$disk = Storage::disk(config('filesystems.cloud'));
|
2022-11-14 08:47:53 +00:00
|
|
|
|
2022-12-24 11:30:02 +00:00
|
|
|
if($path && $disk->exists($path)) {
|
2022-11-14 08:47:53 +00:00
|
|
|
$disk->delete($path);
|
|
|
|
}
|
|
|
|
|
2022-12-24 11:30:02 +00:00
|
|
|
if($thumb && $disk->exists($thumb)) {
|
2022-11-14 08:47:53 +00:00
|
|
|
$disk->delete($thumb);
|
|
|
|
}
|
2021-02-06 04:00:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$disk = Storage::disk(config('filesystems.local'));
|
2022-12-24 11:30:02 +00:00
|
|
|
|
2022-11-14 08:47:53 +00:00
|
|
|
if($path && $disk->exists($path)) {
|
2021-02-06 04:00:29 +00:00
|
|
|
$disk->delete($path);
|
|
|
|
}
|
2022-12-24 11:30:02 +00:00
|
|
|
|
2022-11-14 08:47:53 +00:00
|
|
|
if($thumb && $disk->exists($thumb)) {
|
2021-02-06 04:00:29 +00:00
|
|
|
$disk->delete($thumb);
|
|
|
|
}
|
|
|
|
|
2022-12-27 03:04:42 +00:00
|
|
|
$media->delete();
|
2022-06-19 12:52:06 +00:00
|
|
|
|
2022-12-27 03:04:42 +00:00
|
|
|
return 1;
|
2021-02-06 04:00:29 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 04:45:04 +00:00
|
|
|
}
|