Files
exchange-2.0/app/Classes/Jobs/Commands/V2/DeleteBulkInvoiceFilesV2CommandJob.php
T

52 lines
1.7 KiB
PHP

<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;
class DeleteBulkInvoiceFilesV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Delete all the bulk download files.');
$start = new Carbon();
$directories = [
storage_path('app/bulk_invoice'), //cief todo: should map to the equivalent in AWS S3 bucket
storage_path('app/bulk_whiteform'), //cief todo: should map to the equivalent in AWS S3 bucket
];
foreach ($directories as $directory) {
$start = new Carbon();
Log::info(Carbon::now() . ' Start cleaning - ' . $directory);
if (File::isDirectory($directory)) { //cief todo: should map to the equivalent in AWS S3 bucket
File::cleanDirectory($directory);
Log::info('All files have been deleted.');
} else {
Log::info('Directory does not exist.');
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ' Process ended. ElapsedTime: ' . $elapsedTime);
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Delete all the bulk download files. ElapsedTime: ' . $elapsedTime . '.');
}
}