feat: enhance report migration process with improved proof handling and add migration command for report proofs

This commit is contained in:
Yoga Pangestu 2026-06-04 14:52:31 +07:00
parent 7bf5775ad9
commit 382d0862b8
3 changed files with 46 additions and 28 deletions

View File

@ -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...',

View File

@ -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;
}
}
}
/**

View File

@ -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('<info>SKIP</info>');
$proofMigrated = $this->migrateProofIfNeeded($existing->id, $legacy);
$this->output->writeln($proofMigrated ? '<info>SKIP + IMG</info>' : '<info>SKIP</info>');
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('<info>DONE</info>');
$this->output->writeln($proofMigrated ? '<info>DONE + IMG</info>' : '<info>DONE</info>');
} catch (\Exception $e) {
$this->output->writeln('<error>FAILED: '.$e->getMessage().'</error>');
}
}
/**
* 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;
}
/**