43 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
| <?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)");
 | |
|     }
 | |
| }
 |