From 5da53651d4de5bb08adef41efe642d65f8ed6963 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 25 May 2024 12:12:18 +0800 Subject: [PATCH 1/2] Laravel Vapor - Code Sync from Shipping Portal to use S3 Bucket to replace local storage --- .../Convert1688PurchaseOrderToProductList.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php b/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php index b956aa39..72e4aa83 100644 --- a/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php +++ b/app/Classes/Modules/Bookings/Services/Convert1688PurchaseOrderToProductList.php @@ -20,14 +20,28 @@ class Convert1688PurchaseOrderToProductList $productList = []; $shipping = 0; $discount = 0; + $text = ""; + $filepath = ""; + + $filesystemDriver = Storage::getDefaultDriver(); + $file = $file->file->file_info->original->file; + if($filesystemDriver === 's3'){ + $fileContent = Storage::disk('s3')->get($file); + $filepath = storage_path('app/temp.pdf'); + file_put_contents($filepath, $fileContent); + } + else{ + $filepath = Storage::disk('documents')->path($file); + } try { - $pdf = $parser->parseFile(Storage::disk('documents')->path($file->file->file_info->original->file)); + $pdf = $parser->parseFile($filepath); + $text = $pdf->getText(); } catch (Exception $exception) { throw new MalformedRequestException('Invalid file format.'); } - $text = $pdf->getText(); + if(str_contains($text, '订单详情单')) throw new MalformedRequestException('Can\'t process non english documents'); $tables = explode('Amount (yuan)', $text); From a6dc5d5203f6065b8079bcee6db4f4883115c575 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 25 May 2024 12:13:19 +0800 Subject: [PATCH 2/2] Laravel Vapor - New V2 command to do housekeeping at S3 Bucket --- .../V2/HouseKeepingS3FilesV2CommandJob.php | 52 +++++++++++++++++++ .../V2/HouseKeepingS3FilesV2Command.php | 23 ++++++++ app/Console/Kernel.php | 37 +++++++------ 3 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 app/Classes/Jobs/Commands/V2/HouseKeepingS3FilesV2CommandJob.php create mode 100644 app/Console/Commands/V2/HouseKeepingS3FilesV2Command.php diff --git a/app/Classes/Jobs/Commands/V2/HouseKeepingS3FilesV2CommandJob.php b/app/Classes/Jobs/Commands/V2/HouseKeepingS3FilesV2CommandJob.php new file mode 100644 index 00000000..4463208d --- /dev/null +++ b/app/Classes/Jobs/Commands/V2/HouseKeepingS3FilesV2CommandJob.php @@ -0,0 +1,52 @@ +allFiles($directory); + + foreach ($objects as $object) { + $s3->delete($object); + Log::info('[HouseKeepingS3FilesV2] Deleted object: ' . $object); + } + + Log::info('[HouseKeepingS3FilesV2] All files have been deleted.'); + + $endInner = Carbon::now(); + $elapsedTime = $startInner->diff($endInner)->format('%H:%I:%S'); + Log::info(Carbon::now() . ' [HouseKeepingS3FilesV2] Process ended. ElapsedTime: ' . $elapsedTime); + } + + $end = new Carbon(); + $elapsedTime = $start->diff($end)->format('%H:%I:%S'); + Log::info(Carbon::now() . ': End job - Housekeeping temporary files in S3 Bucket. ElapsedTime: ' . $elapsedTime . '.'); + } +} diff --git a/app/Console/Commands/V2/HouseKeepingS3FilesV2Command.php b/app/Console/Commands/V2/HouseKeepingS3FilesV2Command.php new file mode 100644 index 00000000..da15ff1b --- /dev/null +++ b/app/Console/Commands/V2/HouseKeepingS3FilesV2Command.php @@ -0,0 +1,23 @@ +everyFiveMinutes() ->withoutOverlapping(); - $schedule->command('email-do-to-vt-command') - ->dailyAt('10:00') + $schedule->command('housekeeping-s3-files-command') + ->everyFiveMinutes() ->withoutOverlapping(); - $schedule->command('seasonal-segmant-company-remove-command') - ->dailyAt('01:00') - ->withoutOverlapping(); + //cief todo: disable commands to avoid unintentional interfering with production starts + // $schedule->command('email-do-to-vt-command') + // ->dailyAt('10:00') + // ->withoutOverlapping(); - $schedule->command('delete-bulk-download-files-command') - ->hourly() - ->withoutOverlapping(); + // $schedule->command('seasonal-segmant-company-remove-command') + // ->dailyAt('01:00') + // ->withoutOverlapping(); - $schedule->command('new-user-registration-expire-check-command') - //->dailyAt('23:55') //cief todo: original, to be reverted back to this - ->everyFifteenMinutes() - ->withoutOverlapping(); + // $schedule->command('delete-bulk-download-files-command') + // ->hourly() + // ->withoutOverlapping(); - $schedule->command('booking-expired-command') - ->dailyAt('02:00') - ->withoutOverlapping(); + // $schedule->command('new-user-registration-expire-check-command') + // //->dailyAt('23:55') //cief todo: original, to be reverted back to this + // ->everyFifteenMinutes() + // ->withoutOverlapping(); + // $schedule->command('booking-expired-command') + // ->dailyAt('02:00') + // ->withoutOverlapping(); + //cief todo: disable commands to avoid unintentional interfering with production ends + + // DISABLED BY DEFAULT // $schedule->command('purchase-order-autofill-command') // ->dailyAt('03:00') // ->withoutOverlapping();