cleanup photos older than x hours
This commit is contained in:
parent
c796aea14e
commit
79789f41dd
@ -63,3 +63,5 @@ AWS_BUCKET=
|
|||||||
AWS_USE_PATH_STYLE_ENDPOINT=false
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
|
|
||||||
VITE_APP_NAME="${APP_NAME}"
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
PHOTO_RETENTION_HOURS=24
|
||||||
|
|||||||
28
app/Console/Commands/CleanupPhotos.php
Normal file
28
app/Console/Commands/CleanupPhotos.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\PhotoJob;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
class CleanupPhotos extends Command
|
||||||
|
{
|
||||||
|
protected $signature = 'photos:cleanup';
|
||||||
|
protected $description = 'Delete photos and their jobs older than the configured retention period';
|
||||||
|
|
||||||
|
public function handle(): void
|
||||||
|
{
|
||||||
|
$hours = config('fotobox.photo_retention_hours');
|
||||||
|
$cutoff = now()->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).");
|
||||||
|
}
|
||||||
|
}
|
||||||
17
config/fotobox.php
Normal file
17
config/fotobox.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Photo Retention
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Photos and their associated jobs older than this many hours will be
|
||||||
|
| automatically deleted by the photos:cleanup scheduled command.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'photo_retention_hours' => (int) env('PHOTO_RETENTION_HOURS', 24),
|
||||||
|
|
||||||
|
];
|
||||||
@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
use Illuminate\Foundation\Inspiring;
|
use Illuminate\Foundation\Inspiring;
|
||||||
use Illuminate\Support\Facades\Artisan;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
|
use Illuminate\Support\Facades\Schedule;
|
||||||
|
|
||||||
Artisan::command('inspire', function () {
|
Artisan::command('inspire', function () {
|
||||||
$this->comment(Inspiring::quote());
|
$this->comment(Inspiring::quote());
|
||||||
})->purpose('Display an inspiring quote');
|
})->purpose('Display an inspiring quote');
|
||||||
|
|
||||||
|
Schedule::command('photos:cleanup')->hourly();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user