From ff994a7c95480ee125bb451a9c8f449eb6922f95 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Tue, 9 Dec 2025 15:35:52 +0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20feat(CleanupSingleInspeksiComman?= =?UTF-8?q?d):=20Tambahkan=20command=20untuk=20cleanup=20inspeksi=20per=20?= =?UTF-8?q?permohonan?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Membuat artisan command untuk cleanup data inspeksi secara spesifik untuk 1 permohonan dan user tertentu dengan opsi sync/async - Command signature: `lpj:cleanup-single-inspeksi` dengan required arguments permohonan-id dan created-by - Opsi --sync untuk eksekusi synchronous dan --force untuk skip konfirmasi - Validasi input permohonanId dan createdBy harus angka positif - Integrasi dengan InspeksiCleanupService untuk cleanupSync() dan cleanupAsync() - Konfirmasi interaktif sebelum proses (dapat di-skip dengan --force) - Comprehensive logging dengan context permohonan_id dan created_by - Error handling dengan try-catch dan return Command::SUCCESS/FAILURE - Informasi mode eksekusi (Synchronous vs Queue) ditampilkan ke user - Pesan sukses yang jelas untuk monitoring progress di log --- .../Commands/CleanupSingleInspeksiCommand.php | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app/Console/Commands/CleanupSingleInspeksiCommand.php diff --git a/app/Console/Commands/CleanupSingleInspeksiCommand.php b/app/Console/Commands/CleanupSingleInspeksiCommand.php new file mode 100644 index 0000000..de4e117 --- /dev/null +++ b/app/Console/Commands/CleanupSingleInspeksiCommand.php @@ -0,0 +1,99 @@ + $this->argument('permohonan-id'), + 'created_by' => $this->argument('created-by'), + 'sync' => $this->option('sync') + ]); + + try { + $permohonanId = (int) $this->argument('permohonan-id'); + $createdBy = (int) $this->argument('created-by'); + $sync = $this->option('sync'); + $force = $this->option('force'); + + // Validasi input + if ($permohonanId <= 0) { + $this->error('Permohonan ID harus angka positif.'); + return Command::FAILURE; + } + + if ($createdBy <= 0) { + $this->error('Created By harus angka positif.'); + return Command::FAILURE; + } + + // Tampilkan info + $this->info('=== Cleanup Single Inspeksi ==='); + $this->info("Permohonan ID: {$permohonanId}"); + $this->info("Created By: {$createdBy}"); + $this->info("Mode: " . ($sync ? 'Synchronous' : 'Queue')); + $this->newLine(); + + // Konfirmasi jika tidak force + if (!$force && !$this->confirm('Lanjutkan dengan cleanup?')) { + $this->info('Cleanup dibatalkan.'); + return Command::SUCCESS; + } + + // Jalankan cleanup + $cleanupService = new InspeksiCleanupService(); + + if ($sync) { + $this->info('Menjalankan cleanup secara synchronous...'); + $cleanupService->cleanupSync($permohonanId, $createdBy); + $this->info('Cleanup selesai.'); + } else { + $this->info('Mengirim job ke queue...'); + $cleanupService->cleanupAsync($permohonanId, $createdBy); + $this->info('Job telah di-dispatch ke queue.'); + $this->info('Monitor progress di log.'); + } + + return Command::SUCCESS; + + } catch (\Exception $e) { + Log::error('CleanupSingleInspeksiCommand: Terjadi error saat proses cleanup', [ + 'permohonan_id' => $this->argument('permohonan-id'), + 'created_by' => $this->argument('created-by'), + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString() + ]); + + $this->error('Terjadi kesalahan: ' . $e->getMessage()); + return Command::FAILURE; + } + } +} \ No newline at end of file