From 01dd5db7f533ab7c2d96465ffa4d811d94a9b8d4 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Tue, 31 Dec 2019 21:58:21 -0700 Subject: [PATCH] Update scheduler, add StoryGC command --- app/Console/Commands/StoryGC.php | 64 ++++++++++++++++++++++++++++++++ app/Console/Kernel.php | 1 + 2 files changed, 65 insertions(+) create mode 100644 app/Console/Commands/StoryGC.php diff --git a/app/Console/Commands/StoryGC.php b/app/Console/Commands/StoryGC.php new file mode 100644 index 00000000..f6271bb1 --- /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 18057725..1e3364af 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(); } /**