Добавил команду для чистки директории скачивания; Добавил эту комманду в ежедневный запуск

This commit is contained in:
Dhaverd 2025-06-03 22:36:18 +08:00
parent 58c8091447
commit 181dc108c1
2 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,42 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class ClearDownloads extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:clear-downloads';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Execute the console command.
*/
public function handle()
{
$this->info("Clearing download directory: " . env('PATH_TO_DOWNLOAD'));
$directory = new Filesystem();
$files = $directory->files(env('PATH_TO_DOWNLOAD'), false);
$counter = 0;
foreach ($files as $file){
if ($file->getFilename() !== '.gitignore'){
$this->info("rm " . $file->getRealPath());
unlink($file->getRealPath());
$counter++;
}
}
$this->info("Deleted " . $counter . " file(s)");
}
}

View File

@ -13,6 +13,7 @@ class Kernel extends ConsoleKernel
protected function schedule(Schedule $schedule): void
{
// $schedule->command('inspire')->hourly();
$schedule->command('app:clear-downloads')->daily();
}
/**