added clean temp files schedule

This commit is contained in:
2023-09-10 21:06:00 +10:00
parent 484512f2c7
commit d1cc468dfa
2 changed files with 44 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
class CleanupTempFiles extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:cleanup-temp-files';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete temporary files that are older that 1 day';
/**
* Execute the console command.
*/
public function handle()
{
$keepTime = 1 * 24 * 60 * 60; // 1 Day
$currentTimeStamp = time();
$deletedFileCount = 0;
foreach (glob(storage_path('app/tmp/*')) as $filename) {
$fileModifiedTimeStamp = filemtime($filename);
if($currentTimeStamp - $fileModifiedTimeStamp > $keepTime) {
unlink($filename);
$deletedFileCount++;
}
}
$this->comment('Deleted ' . $deletedFileCount . ' files');
}
}

View File

@@ -15,6 +15,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->command('app:cleanup-temp-files')->everySecond();
}
/**