info('Starting issue management migration...'); $legacyConn = DB::connection('mysql_second'); // Get legacy issue management $legacyIssues = $legacyConn->table('issue_management')->get(); if ($legacyIssues->isEmpty()) { $this->warn('No issue management records found in legacy database.'); return; } $this->withProgressBar($legacyIssues, function ($legacy) { DB::table('issue_management')->updateOrInsert( ['id' => $legacy->id], [ 'media_monitoring_id' => $legacy->media_monitoring, 'location_id' => $legacy->locus, 'sub_location_id' => $legacy->sub_locus, 'classification_id' => $legacy->classification, 'sub_classification_id' => $legacy->sub_classification, 'issue' => $this->mapSentiment($legacy->issue), 'response' => $this->mapSentiment($legacy->response), 'description' => $legacy->description ?? '-', 'created_at' => $legacy->created_at ?? now(), 'updated_at' => $legacy->updated_at ?? now(), 'deleted_at' => $legacy->deleted_at, ] ); // Handle Departments (Legacy 'agency' field is string, can be multiple separated by comma) $agencyString = trim($legacy->agency); if (! empty($agencyString)) { $agencyNames = explode(',', $agencyString); foreach ($agencyNames as $agencyName) { $agencyName = trim($agencyName); if (empty($agencyName)) { continue; } $department = Department::firstOrCreate( ['name' => $agencyName], [ 'alias' => Str::limit($agencyName, 20, ''), 'is_active' => IsActive::ACTIVE, ] ); DB::table('department_issue_management')->updateOrInsert( [ 'department_id' => $department->id, 'issue_management_id' => $legacy->id, ], [ 'created_at' => now(), 'updated_at' => now(), ] ); } } }); $this->newLine(); $this->info('Issue management migration completed successfully!'); } private function mapSentiment(string $legacyValue): int { return match (strtolower($legacyValue)) { 'positif' => IssueSentiment::POSITIVE->value, 'negatif' => IssueSentiment::NEGATIVE->value, 'netral' => IssueSentiment::NEUTRAL->value, 'krisis' => IssueSentiment::CRISIS->value, default => IssueSentiment::NEUTRAL->value, }; } }