(IUser $user, IImportSource $importSource, OutputInterface $output)
| 59 | } |
| 60 | |
| 61 | public function import(IUser $user, IImportSource $importSource, OutputInterface $output): void { |
| 62 | if (!$importSource->pathExists(self::EXPORT_FILE)) { |
| 63 | $output->writeln('<comment>No Analytics data found in archive</comment>'); |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | $raw = $importSource->getFileContents(self::EXPORT_FILE); |
| 68 | $payload = json_decode($raw, true, 512, JSON_THROW_ON_ERROR); |
| 69 | if (!is_array($payload)) { |
| 70 | throw new UserMigrationException('Invalid Analytics migration payload'); |
| 71 | } |
| 72 | |
| 73 | $uid = $user->getUID(); |
| 74 | $datasetMap = []; |
| 75 | $reportMap = []; |
| 76 | $reportDatasetMap = []; |
| 77 | foreach (($payload['reports'] ?? []) as $report) { |
| 78 | if (isset($report['id'], $report['dataset'])) { |
| 79 | $reportDatasetMap[(int)$report['id']] = (int)$report['dataset']; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | $this->db->beginTransaction(); |
| 84 | try { |
| 85 | $datasetMap = $this->importDatasets($uid, $payload['datasets'] ?? []); |
| 86 | $columnMaps = $this->importFlexibleStorage($payload, $datasetMap); |
| 87 | $reportMap = $this->importReports($uid, $payload['reports'] ?? [], $datasetMap, $columnMaps); |
| 88 | $this->importDataloads($uid, $payload['dataloads'] ?? [], $datasetMap, $columnMaps); |
| 89 | $this->importFacts($uid, $payload['facts'] ?? [], $datasetMap); |
| 90 | $this->importThresholds($uid, $payload['thresholds'] ?? [], $reportMap, $reportDatasetMap, $columnMaps); |
| 91 | $this->importPanoramas($uid, $payload['panoramas'] ?? [], $reportMap); |
| 92 | $this->db->commit(); |
| 93 | } catch (\Throwable $e) { |
| 94 | $this->db->rollBack(); |
| 95 | throw new UserMigrationException('Unable to import Analytics data', 0, $e); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | public function getId(): string { |
| 100 | return 'analytics'; |
nothing calls this directly
no test coverage detected