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

Method export

lib/UserMigration/AnalyticsMigrator.php:34–55  ·  view source on GitHub ↗
(IUser $user, IExportDestination $exportDestination, OutputInterface $output)

Source from the content-addressed store, hash-verified

32 }
33
34 public function export(IUser $user, IExportDestination $exportDestination, OutputInterface $output): void {
35 $uid = $user->getUID();
36 $output->writeln('<info>Exporting Analytics data</info>');
37
38 $datasets = $this->fetchAllByUser('analytics_dataset', $uid);
39 $datasetIds = array_map(static fn (array $row): int => (int)$row['id'], $datasets);
40
41 $reports = $this->fetchAllByUser('analytics_report', $uid);
42 $reportIds = array_map(static fn (array $row): int => (int)$row['id'], $reports);
43
44 $payload = [
45 'datasets' => $datasets,
46 'reports' => $reports,
47 'dataloads' => $this->fetchAllByIds('analytics_dataload', 'dataset', $datasetIds),
48 'facts' => $this->fetchAllByIds('analytics_facts', 'dataset', $datasetIds),
49 'thresholds' => $this->fetchAllByIds('analytics_threshold', 'report', $reportIds),
50 'panoramas' => $this->fetchAllByUser('analytics_panorama', $uid),
51 ];
52
53 $encoded = json_encode($payload, JSON_THROW_ON_ERROR);
54 $exportDestination->addFileContents(self::EXPORT_FILE, $encoded);
55 }
56
57 public function import(IUser $user, IImportSource $importSource, OutputInterface $output): void {
58 if (!$importSource->pathExists(self::EXPORT_FILE)) {

Callers

nothing calls this directly

Calls 4

fetchAllByUserMethod · 0.95
fetchAllByIdsMethod · 0.95
addFileContentsMethod · 0.80
getUIDMethod · 0.45

Tested by

no test coverage detected