MCPcopy Create free account
hub / github.com/Rello/analytics / import

Method import

lib/UserMigration/AnalyticsMigrator.php:61–97  ·  view source on GitHub ↗
(IUser $user, IImportSource $importSource, OutputInterface $output)

Source from the content-addressed store, hash-verified

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';

Callers

nothing calls this directly

Calls 13

importDatasetsMethod · 0.95
importFlexibleStorageMethod · 0.95
importReportsMethod · 0.95
importDataloadsMethod · 0.95
importFactsMethod · 0.95
importThresholdsMethod · 0.95
importPanoramasMethod · 0.95
pathExistsMethod · 0.80
getFileContentsMethod · 0.80
getUIDMethod · 0.45
beginTransactionMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected