From 79789f41dd1a51251a3ea7ec4e27866132ed47d6 Mon Sep 17 00:00:00 2001 From: Alexander Gabriel Date: Sun, 28 Jun 2026 15:23:39 +0200 Subject: [PATCH] cleanup photos older than x hours --- .env.example | 2 ++ app/Console/Commands/CleanupPhotos.php | 28 ++++++++++++++++++++++++++ config/fotobox.php | 17 ++++++++++++++++ routes/console.php | 3 +++ 4 files changed, 50 insertions(+) create mode 100644 app/Console/Commands/CleanupPhotos.php create mode 100644 config/fotobox.php diff --git a/.env.example b/.env.example index c0660ea..05c8340 100644 --- a/.env.example +++ b/.env.example @@ -63,3 +63,5 @@ AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" + +PHOTO_RETENTION_HOURS=24 diff --git a/app/Console/Commands/CleanupPhotos.php b/app/Console/Commands/CleanupPhotos.php new file mode 100644 index 0000000..4c1228f --- /dev/null +++ b/app/Console/Commands/CleanupPhotos.php @@ -0,0 +1,28 @@ +subHours($hours); + + $jobs = PhotoJob::where('created_at', '<', $cutoff)->get(); + + foreach ($jobs as $job) { + Storage::disk('public')->delete($job->image_path); + $job->delete(); + } + + $this->info("Deleted {$jobs->count()} photo(s) older than {$hours} hour(s)."); + } +} diff --git a/config/fotobox.php b/config/fotobox.php new file mode 100644 index 0000000..1848273 --- /dev/null +++ b/config/fotobox.php @@ -0,0 +1,17 @@ + (int) env('PHOTO_RETENTION_HOURS', 24), + +]; diff --git a/routes/console.php b/routes/console.php index 3c9adf1..a7c5e08 100644 --- a/routes/console.php +++ b/routes/console.php @@ -2,7 +2,10 @@ use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Schedule; Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); + +Schedule::command('photos:cleanup')->hourly();