diff --git a/app/Console/Commands/MediaGarbageCollector.php b/app/Console/Commands/MediaGarbageCollector.php new file mode 100644 index 000000000..2a91c5148 --- /dev/null +++ b/app/Console/Commands/MediaGarbageCollector.php @@ -0,0 +1,60 @@ +where('created_at', '<', Carbon::now()->subHours(6)->toDateTimeString()) + ->orderBy('created_at','asc') + ->take(500) + ->get(); + + foreach($gc as $media) { + $path = storage_path("app/$media->media_path"); + $thumb = storage_path("app/$media->thumbnail_path"); + if(is_file($path)) { + unlink($path); + } + if(is_file($thumb)) { + unlink($thumb); + } + $media->forceDelete(); + } + } +}