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 <ddeni05@gmail.com>
This commit is contained in:
Daeng Deni Mardaeni
2025-06-02 20:08:24 +07:00
parent d326cce6e0
commit 6b8f44db1d

View File

@@ -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());
}