38 lines
921 B
PHP
38 lines
921 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\StatistikoImport;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
class DeleteUnusedFiles extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'delete:unused-files';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Delete unused statistiko files';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$tasks = StatistikoImport::pluck('file_name')->toArray();
|
|
|
|
collect(Storage::disk('public')->allFiles('statistiko'))
|
|
->reject(fn (string $file) => $file === '.gitignore')
|
|
->reject(fn (string $file) => in_array($file, $tasks))
|
|
->each(fn ($file) => Storage::disk('public')->delete($file));
|
|
}
|
|
}
|