|
|
@ -9,6 +9,8 @@ use Illuminate\Support\Facades\Log;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use App\Services\MediaService;
|
|
|
|
use App\Services\MediaService;
|
|
|
|
use App\Services\StatusService;
|
|
|
|
use App\Services\StatusService;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
|
|
|
|
|
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
|
|
|
|
|
|
|
|
class MediaS3GarbageCollector extends Command
|
|
|
|
class MediaS3GarbageCollector extends Command
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -88,6 +90,7 @@ class MediaS3GarbageCollector extends Command
|
|
|
|
$localDisk = Storage::disk('local');
|
|
|
|
$localDisk = Storage::disk('local');
|
|
|
|
|
|
|
|
|
|
|
|
foreach($gc as $media) {
|
|
|
|
foreach($gc as $media) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
if(
|
|
|
|
if(
|
|
|
|
$cloudDisk->exists($media->media_path)
|
|
|
|
$cloudDisk->exists($media->media_path)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
@ -108,6 +111,16 @@ class MediaS3GarbageCollector extends Command
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bar->advance();
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
} catch (FileNotFoundException $e) {
|
|
|
|
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} catch (NotFoundHttpException $e) {
|
|
|
|
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bar->finish();
|
|
|
|
$bar->finish();
|
|
|
|
$this->line(' ');
|
|
|
|
$this->line(' ');
|
|
|
@ -132,6 +145,7 @@ class MediaS3GarbageCollector extends Command
|
|
|
|
->where('id', '<', $minId)
|
|
|
|
->where('id', '<', $minId)
|
|
|
|
->chunk(50, function($medias) use($cloudDisk, $localDisk, $bar, $log) {
|
|
|
|
->chunk(50, function($medias) use($cloudDisk, $localDisk, $bar, $log) {
|
|
|
|
foreach($medias as $media) {
|
|
|
|
foreach($medias as $media) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
if($cloudDisk->exists($media->media_path)) {
|
|
|
|
if($cloudDisk->exists($media->media_path)) {
|
|
|
|
if( $localDisk->exists($media->media_path)) {
|
|
|
|
if( $localDisk->exists($media->media_path)) {
|
|
|
|
$localDisk->delete($media->media_path);
|
|
|
|
$localDisk->delete($media->media_path);
|
|
|
@ -149,6 +163,16 @@ class MediaS3GarbageCollector extends Command
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bar->advance();
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
} catch (FileNotFoundException $e) {
|
|
|
|
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} catch (NotFoundHttpException $e) {
|
|
|
|
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
$bar->advance();
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|