From 6b8f44db1daae515d4e0b01af78b9b11e70711a9 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Mon, 2 Jun 2025 20:08:24 +0700 Subject: [PATCH] feat(webstatement): tambahkan logika penghapusan dan penggantian file PDF setelah dekripsi - Menambahkan variabel `$finalPdfPath` untuk menyimpan lintasan file PDF akhir tanpa ekstensi `.dec`. - Mengimplementasikan logika baru untuk: 1. Menghapus file PDF terenkripsi setelah file berhasil didekripsi. 2. Mengganti nama file dekripsi dengan menghilangkan ekstensi `.dec`. - Menambahkan logging baru untuk mencatat aktivitas berikut: 1. Penghapusan file PDF terenkripsi setelah berhasil didekripsi. 2. Perubahan nama file dekripsi ke format final. - Tujuan perubahan ini adalah untuk: 1. Mengoptimalkan ruang penyimpanan dengan menghilangkan file terenkripsi setelah digunakan. 2. Memastikan hasil dekripsi langsung dapat digunakan tanpa perlu pengolahan manual tambahan. Signed-off-by: Daeng Deni Mardaeni --- app/Jobs/UnlockPdfJob.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Jobs/UnlockPdfJob.php b/app/Jobs/UnlockPdfJob.php index 62dc68d..fd7a955 100644 --- a/app/Jobs/UnlockPdfJob.php +++ b/app/Jobs/UnlockPdfJob.php @@ -108,6 +108,7 @@ class UnlockPdfJob implements ShouldQueue $filename = pathinfo($pdfFilePath, PATHINFO_FILENAME); $directory = pathinfo($pdfFilePath, PATHINFO_DIRNAME); $decryptedPdfPath = $directory . '/' . $filename . '.dec.pdf'; + $finalPdfPath = $directory . '/' . $filename . '.pdf'; // Skip if the decrypted file already exists if (File::exists($decryptedPdfPath)) { @@ -128,6 +129,17 @@ class UnlockPdfJob implements ShouldQueue } Log::info("Unlocked PDF: {$pdfFilePath} to {$decryptedPdfPath}"); + + // Remove the original encrypted file after successful decryption + if (File::exists($decryptedPdfPath)) { + // Delete the encrypted file + File::delete($pdfFilePath); + Log::info("Removed encrypted file: {$pdfFilePath}"); + + // Rename the decrypted file (remove .dec extension) + File::move($decryptedPdfPath, $finalPdfPath); + Log::info("Renamed decrypted file from {$decryptedPdfPath} to {$finalPdfPath}"); + } } catch (Exception $e) { Log::error("Error unlocking PDF {$pdfFilePath}: " . $e->getMessage()); }