diff --git a/app/Console/Commands/StoryGC.php b/app/Console/Commands/StoryGC.php new file mode 100644 index 000000000..f6271bb15 --- /dev/null +++ b/app/Console/Commands/StoryGC.php @@ -0,0 +1,64 @@ +take(50)->get(); + + if($stories->count() == 0) { + exit; + } + + foreach($stories as $story) { + if(Storage::exists($story->path) == true) { + Storage::delete($story->path); + } + DB::transaction(function() use($story) { + StoryView::whereStoryId($story->id)->delete(); + $story->delete(); + }); + } + } +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 18057725e..1e3364afc 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -30,6 +30,7 @@ class Kernel extends ConsoleKernel $schedule->command('media:gc') ->hourly(); $schedule->command('horizon:snapshot')->everyFiveMinutes(); + $schedule->command('story:gc')->everyFiveMinutes(); } /**