- Menambahkan command baru `webstatement:unlock-pdf` untuk membuka file PDF yang dilindungi password: - Dapat menerima parameter `directory` untuk menetapkan direktori file sumber. - Opsi `--password` untuk menentukan password yang digunakan dalam proses unlock, dengan default `123456`. - Menampilkan log proses unlock PDF dengan pesan sukses atau error. - Membuat job baru `UnlockPdfJob` untuk menangani proses unlock PDF secara asinkron: - Memindai direktori utama berdasarkan struktur folder (tahun dan ID). - Membuka proteksi file PDF dengan menggunakan library `qpdf`. - Menghasilkan file PDF yang telah didekripsi di direktori yang sama dengan nama file ekstensi `.dec.pdf`. - Melakukan logging untuk setiap file yang berhasil diproses atau ketika terjadi error. - Menghindari duplikasi dengan memeriksa keberadaan file decrypted sebelumnya. - Memperbarui `WebstatementServiceProvider`: - Mendaftarkan command `UnlockPdf` untuk digunakan dalam aplikasi. - Menambah jadwal otomatisasi harian pada pukul 09:30 untuk menjalankan command `webstatement:unlock-pdf`. - Logging hasil proses executables ke file `logs/unlock-pdf.log`. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
50 lines
1.2 KiB
PHP
50 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Webstatement\Console;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Modules\Webstatement\Jobs\UnlockPdfJob;
|
|
use Exception;
|
|
|
|
class UnlockPdf extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'webstatement:unlock-pdf {directory} {--password=123456 : Password for PDF files}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Unlock password-protected PDF files in the specified directory';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
try {
|
|
$directory = $this->argument('directory');
|
|
$password = $this->option('password');
|
|
|
|
$this->info('Starting PDF unlock process...');
|
|
|
|
// Dispatch the job
|
|
UnlockPdfJob::dispatch($directory, $password);
|
|
|
|
$this->info('PDF unlock job has been queued.');
|
|
|
|
return 0;
|
|
} catch (Exception $e) {
|
|
$this->error('Error processing PDF unlock: ' . $e->getMessage());
|
|
return 1;
|
|
}
|
|
}
|
|
}
|