cleanup photos older than x hours
This commit is contained in:
1 parent
c796aea14e
commit
79789f41dd
4 files changed
+50
No files matched your search
@@ -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).");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user