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