From 382d0862b85ad51864d3b6f2482e312cabf32289 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Thu, 4 Jun 2026 14:52:31 +0700 Subject: [PATCH] feat: enhance report migration process with improved proof handling and add migration command for report proofs --- app/Console/Commands/MigrateAllCommand.php | 1 + .../Commands/MigrateMediaOrdersCommand.php | 28 +++++++----- .../Commands/MigrateReportsCommand.php | 45 +++++++++++-------- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/app/Console/Commands/MigrateAllCommand.php b/app/Console/Commands/MigrateAllCommand.php index 4191e3c..e05aac7 100644 --- a/app/Console/Commands/MigrateAllCommand.php +++ b/app/Console/Commands/MigrateAllCommand.php @@ -37,6 +37,7 @@ public function handle() 'migrate:company' => '🏭 Migrating companies & partner media...', 'migrate:journalist' => '📰 Migrating journalists...', 'migrate:media-orders' => '📦 Migrating media orders...', + 'migrate:reports' => '📋 Migrating report proofs (bukti tayang)...', 'migrate:media-cooperation' => '🤝 Migrating media cooperation...', 'migrate:media-monitoring' => '🖥️ Migrating media monitoring...', 'migrate:issue-management' => '⚠️ Migrating issue management...', diff --git a/app/Console/Commands/MigrateMediaOrdersCommand.php b/app/Console/Commands/MigrateMediaOrdersCommand.php index ae60ded..8f8ca1ed 100644 --- a/app/Console/Commands/MigrateMediaOrdersCommand.php +++ b/app/Console/Commands/MigrateMediaOrdersCommand.php @@ -381,13 +381,21 @@ private function processReport(object $legacyReport, int $cooperationId, int $ta [$cleanTitle, $cleanLink] = $this->extractLinkData($legacyReport); - $exists = DB::table('reports') + $existingReportId = DB::table('reports') ->where('media_task_assignment_id', $mediaTaskAssignment->id) ->where('publication_date', $legacyReport->broadcast) ->where('link', $cleanLink) - ->exists(); + ->value('id'); + + if ($existingReportId) { + if (! isset($this->migratedReportIds[$existingReportId])) { + $report = Report::find($existingReportId); + if ($report) { + $this->migrateProof($report, $legacyReport); + $this->migratedReportIds[$existingReportId] = true; + } + } - if ($exists) { return; } @@ -404,13 +412,13 @@ private function processReport(object $legacyReport, int $cooperationId, int $ta $newReportId = (int) DB::getPdo()->lastInsertId(); - // // Migrate proof image if not already done - // if (! isset($this->migratedReportIds[$newReportId])) { - // $report = Report::find($newReportId); - // if ($report) { - // $this->migrateProof($report, $legacyReport); - // } - // } + if (! isset($this->migratedReportIds[$newReportId])) { + $report = Report::find($newReportId); + if ($report) { + $this->migrateProof($report, $legacyReport); + $this->migratedReportIds[$newReportId] = true; + } + } } /** diff --git a/app/Console/Commands/MigrateReportsCommand.php b/app/Console/Commands/MigrateReportsCommand.php index 6445dba..dac4103 100644 --- a/app/Console/Commands/MigrateReportsCommand.php +++ b/app/Console/Commands/MigrateReportsCommand.php @@ -143,14 +143,8 @@ private function processReport(object $legacy): void ->first(); if ($existing) { - if (! isset($this->migratedIds[$existing->id])) { - $report = Report::find($existing->id); - if ($report) { - $this->migrateProof($report, $legacy); - } - } - - $this->output->writeln('SKIP'); + $proofMigrated = $this->migrateProofIfNeeded($existing->id, $legacy); + $this->output->writeln($proofMigrated ? 'SKIP + IMG' : 'SKIP'); return; } @@ -168,31 +162,46 @@ private function processReport(object $legacy): void $newReportId = (int) DB::getPdo()->lastInsertId(); - if (! isset($this->migratedIds[$newReportId])) { - $report = Report::find($newReportId); - if ($report) { - $this->migrateProof($report, $legacy); - } - } + $proofMigrated = $this->migrateProofIfNeeded($newReportId, $legacy); - $this->output->writeln('DONE'); + $this->output->writeln($proofMigrated ? 'DONE + IMG' : 'DONE'); } catch (\Exception $e) { $this->output->writeln('FAILED: '.$e->getMessage().''); } } /** - * Migrate the proof image file from S3 to the Report media library. + * Register proof media for a report when not yet migrated. */ - private function migrateProof(Report $report, object $legacy): void + private function migrateProofIfNeeded(int $reportId, object $legacy): bool + { + if (isset($this->migratedIds[$reportId])) { + return false; + } + + $report = Report::find($reportId); + if (! $report) { + return false; + } + + return $this->migrateProof($report, $legacy); + } + + /** + * Migrate the proof image metadata (file stays on S3 legacy path). + */ + private function migrateProof(Report $report, object $legacy): bool { $legacyPath = trim($legacy->proof ?? ''); if (empty($legacyPath) || $legacyPath === '-' || $legacyPath === 'no-image.png') { - return; + return false; } $sourcePath = 'old-data/reports/'.$legacyPath; $this->importProofFile($report, $sourcePath, $legacy); + $this->migratedIds[$report->id] = true; + + return true; } /**