(IUser $user, IExportDestination $exportDestination, OutputInterface $output)
| 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)) { |
nothing calls this directly
no test coverage detected