From 47ec38bb96012f3bed930236541739870d49e07c Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 12 Oct 2023 19:09:56 +0800 Subject: [PATCH] delete all bulk download files --- .../Commands/DeleteBulkInvoiceFiles.php | 50 ++++++++----------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/app/Console/Commands/DeleteBulkInvoiceFiles.php b/app/Console/Commands/DeleteBulkInvoiceFiles.php index 52ebf121..a6e8dab1 100644 --- a/app/Console/Commands/DeleteBulkInvoiceFiles.php +++ b/app/Console/Commands/DeleteBulkInvoiceFiles.php @@ -8,9 +8,9 @@ use Illuminate\Support\Facades\File; class DeleteBulkInvoiceFiles extends Command { - protected $signature = 'delete:bulk-invoice-files'; + protected $signature = 'delete:bulk-download-files'; - protected $description = 'Delete all files in the storage/app/bulk_invoice directory'; + protected $description = 'Delete all the bulk download files'; public function __construct() { @@ -19,34 +19,26 @@ class DeleteBulkInvoiceFiles extends Command public function handle() { - $start = new Carbon(); - $this->logOutput('Process started'); + $directories = [ + storage_path('app/bulk_invoice'), + storage_path('app/bulk_whiteform'), + ]; - $directory = storage_path('app/bulk_invoice'); - - if (File::isDirectory($directory)) { - File::cleanDirectory($directory); - $this->info('All files in the bulk_invoice directory have been deleted.'); - } else { - $this->error('The bulk_invoice directory does not exist.'); + foreach ($directories as $directory) { + $start = new Carbon(); + $this->info(Carbon::now() . ' Start cleaning - ' . $directory); + + if (File::isDirectory($directory)) { + File::cleanDirectory($directory); + $this->info('All files have been deleted.'); + } else { + $this->info('Directory does not exist.'); + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + + $this->info(Carbon::now() . ' Process ended. ElapsedTime: ' . $elapsedTime); } - - $end = new Carbon(); - $elapsedTime = $start->diff($end)->format('%H:%I:%S'); - - $this->logOutput('Process ended. ElapsedTime: ' . $elapsedTime); - } - - public function logOutput($text) - { - if (is_array($text)) { - $text = implode(', ', $text); - } - - $this->info(Carbon::now() . ' : ' . $text); - - $filePath = storage_path('logs/delete-orders.log'); - $textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $text . PHP_EOL; - file_put_contents($filePath, $textToAppend, FILE_APPEND); } }