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

Method import

lib/Service/ReportService.php:472–618  ·  view source on GitHub ↗

* Import Report from File * * @param string|null $path * @param string|null $raw * @return int * @throws \OCP\Files\NotFoundException * @throws \OCP\Files\NotPermittedException * @throws Exception */

(?string $path = null, ?string $raw = null)

Source from the content-addressed store, hash-verified

470 * @throws Exception
471 */
472 public function import(?string $path = null, ?string $raw = null) {
473 if ($path !== '' and $path !== null) {
474 $file = $this->rootFolder->getUserFolder($this->userId)->get($path);
475 $data = $file->getContent();
476 } else if ($raw !== null) {
477 $data = $raw;
478 } else {
479 return 0;
480 }
481 $data = json_decode($data, true);
482 if (!is_array($data) || !is_array($data['report'] ?? null)) {
483 return 0;
484 }
485
486 // Validate every attached load before the import creates a dataset or report.
487 $dataloads = $data['dataload'] ?? [];
488 if (!is_array($dataloads)) {
489 throw new \InvalidArgumentException($this->l10n->t('Invalid data source options'));
490 }
491 foreach ($dataloads as $key => $dataload) {
492 $datasource = $dataload['datasource'] ?? null;
493 if (!is_int($datasource) && !(is_string($datasource) && ctype_digit($datasource))) {
494 throw new \InvalidArgumentException($this->l10n->t('Invalid data source options'));
495 }
496 $dataloads[$key]['option'] = $this->datasourceController->encodeOptionsForStorage(
497 (int)$datasource, $dataload['option'] ?? null, fromExport: true
498 );
499 }
500
501 $report = $data['report'];
502 $exportedDataset = is_array($data['dataset'] ?? null) ? $data['dataset'] : [];
503 $columnMap = [];
504 $descriptor = null;
505 isset($report['name']) ? $name = $report['name'] : $name = '';
506 isset($report['subheader']) ? $subheader = $report['subheader'] : $subheader = '';
507 $parent = 0;
508 $dataset = 0;
509 isset($report['type']) ? $type = (int)$report['type'] : $type = null;
510 isset($report['link']) ? $link = $report['link'] : $link = null;
511 isset($report['visualization']) ? $visualization = $report['visualization'] : $visualization = null;
512 isset($report['chart']) ? $chart = $report['chart'] : $chart = null;
513 isset($report['chartoptions']) ? $chartoptions = $report['chartoptions'] : $chartoptions = null;
514 isset($report['dataoptions']) ? $dataoptions = $report['dataoptions'] : $dataoptions = null;
515 isset($report['filteroptions']) ? $filteroptions = $report['filteroptions'] : $filteroptions = null;
516 isset($report['tableoptions']) ? $tableoptions = $report['tableoptions'] : $tableoptions = null;
517 isset($report['dimension1']) ? $dimension1 = $report['dimension1'] : $dimension1 = null;
518 isset($report['dimension2']) ? $dimension2 = $report['dimension2'] : $dimension2 = null;
519 isset($report['value']) ? $value = $report['value'] : $value = null;
520 $isFlexible = $type === DatasourceController::DATASET_TYPE_INTERNAL_DB && (
521 ($exportedDataset['storageMode'] ?? $exportedDataset['storage_mode'] ?? 'legacy') === 'flexible_shared'
522 || isset($data['flexible'])
523 );
524
525 if ($type === DatasourceController::DATASET_TYPE_INTERNAL_DB) { // New dataset
526 if ($isFlexible) {
527 $exportedColumns = $exportedDataset['columns'] ?? ($data['flexible']['columns'] ?? []);
528 $definitions = array_map(static fn (array $column): array => [
529 'name' => $column['name'],

Calls 15

remapFlexibleValueMethod · 0.95
remapFlexibleJsonMethod · 0.95
createMethod · 0.95
updateOptionsMethod · 0.95
floatvalueMethod · 0.95
setFavoriteMethod · 0.95
getUserFolderMethod · 0.80
getContentMethod · 0.80
getMethod · 0.45
tMethod · 0.45
createFlexibleMethod · 0.45