From d3bbed3ea6c6cffbf6abd27a58de2bd99b4e17e3 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sat, 25 May 2024 13:17:58 +0800 Subject: [PATCH] Laravel Vapor - Fix a problem with fetching file from S3 bucket path inconsistency --- .../Jobs/Commands/V2/EmailDoToVTV2CommandJob.php | 2 +- .../V2/TestAttachingS3FileAndSendEmailV2CommandJob.php | 2 +- .../ControllersLogic/DownloadBookingDocumentLogic.php | 10 +++++----- .../BulkDownloadCustomerInvoicesLogic.php | 2 +- .../BulkDownloadSupplierWhiteFormsLogic.php | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/Classes/Jobs/Commands/V2/EmailDoToVTV2CommandJob.php b/app/Classes/Jobs/Commands/V2/EmailDoToVTV2CommandJob.php index 38d20860..28912ae0 100644 --- a/app/Classes/Jobs/Commands/V2/EmailDoToVTV2CommandJob.php +++ b/app/Classes/Jobs/Commands/V2/EmailDoToVTV2CommandJob.php @@ -53,7 +53,7 @@ class EmailDoToVTV2CommandJob implements ShouldQueue //STEP 1: Go through each of the booking from query foreach ($bookings as $booking) { $file = $booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first(); - $fileContent = Storage::disk('s3')->get('documents/'.$file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($file->file->file_info->original->file); $zip->addFromString($booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); } diff --git a/app/Classes/Jobs/Commands/V2/TestAttachingS3FileAndSendEmailV2CommandJob.php b/app/Classes/Jobs/Commands/V2/TestAttachingS3FileAndSendEmailV2CommandJob.php index b2b70432..2c723213 100644 --- a/app/Classes/Jobs/Commands/V2/TestAttachingS3FileAndSendEmailV2CommandJob.php +++ b/app/Classes/Jobs/Commands/V2/TestAttachingS3FileAndSendEmailV2CommandJob.php @@ -56,7 +56,7 @@ class TestAttachingS3FileAndSendEmailV2CommandJob implements ShouldQueue $counter = 0; foreach ($bookings as $booking) { $file = $booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first(); - $fileContent = Storage::disk('s3')->get('documents/'.$file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($file->file->file_info->original->file); $zip->addFromString($booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); $counter++; diff --git a/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php index 54658308..d32656a0 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php @@ -59,21 +59,21 @@ class DownloadBookingDocumentLogic if ($document_type == 'INVOICEPODOSDO') { $supplier_deliver_order_file = $booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first(); } - $fileContent = Storage::disk('s3')->get('documents/'.$invoice_file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($invoice_file->file->file_info->original->file); $zip->addFromString('invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); - $fileContent = Storage::disk('s3')->get('documents/'.$purchase_file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($purchase_file->file->file_info->original->file); $zip->addFromString('purchase-order-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); - $fileContent = Storage::disk('s3')->get('documents/'.$deliver_file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($deliver_file->file->file_info->original->file); $zip->addFromString('deliver-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); - $fileContent = Storage::disk('s3')->get('documents/'.$supplier_deliver_order_file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($supplier_deliver_order_file->file->file_info->original->file); $zip->addFromString('supplier-deliver-order-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); } else { $file = $booking->documents()->where('document_type', $document_type)->first()->files()->first(); - $fileContent = Storage::disk('s3')->get('documents/'.$file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($file->file->file_info->original->file); $zip->addFromString($booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); } diff --git a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php index faca4dcd..f228957a 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadCustomerInvoicesLogic.php @@ -70,7 +70,7 @@ class BulkDownloadCustomerInvoicesLogic if ($zip->open($zip_file, ZipArchive::CREATE | ZipArchive::OVERWRITE)) { foreach ($invoicebookings as $booking) { $invoice_file = $booking->documents()->where('document_type', DocumentType::INVOICE)->whereNull('deleted_at')->first()->files()->first(); - $fileContent = Storage::disk('s3')->get('documents/'.$invoice_file->file->file_info->original->file); + $fileContent = Storage::disk('s3')->get($invoice_file->file->file_info->original->file); $zip->addFromString('invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf', $fileContent); } $zip->close(); diff --git a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php index ae1c035e..b464e32f 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/BulkDownloadSupplierWhiteFormsLogic.php @@ -57,7 +57,7 @@ class BulkDownloadSupplierWhiteFormsLogic $document = $group->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->whereNull('deleted_at')->first()->files()->first(); $created_at = $group->created_at->format('Y-m-d'); Log::info('BulkDownloadSupplierWhiteFormsLogic processing: ' . 'documents/'.$document->file->file_info->original->file); - if(!Storage::disk('s3')->exists('documents/'.$document->file->file_info->original->file)) + if(!Storage::disk('s3')->exists($document->file->file_info->original->file)) { Log::info('BulkDownloadSupplierWhiteFormsLogic file does not exist: ' . 'documents/'.$document->file->file_info->original->file); }