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