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

Method import

lib/Service/ReportService.php:481–614  ·  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

479 * @throws Exception
480 */
481 public function import(?string $path = null, ?string $raw = null) {
482 if ($path !== '' and $path !== null) {
483 $file = $this->rootFolder->getUserFolder($this->userId)->get($path);
484 $data = $file->getContent();
485 } else if ($raw !== null) {
486 $data = $raw;
487 } else {
488 return 0;
489 }
490 $data = json_decode($data, true);
491 if (!is_array($data) || !is_array($data['report'] ?? null)) {
492 return 0;
493 }
494
495 $report = $data['report'];
496 $exportedDataset = is_array($data['dataset'] ?? null) ? $data['dataset'] : [];
497 $columnMap = [];
498 $descriptor = null;
499 isset($report['name']) ? $name = $report['name'] : $name = '';
500 isset($report['subheader']) ? $subheader = $report['subheader'] : $subheader = '';
501 $parent = 0;
502 $dataset = 0;
503 isset($report['type']) ? $type = (int)$report['type'] : $type = null;
504 isset($report['link']) ? $link = $report['link'] : $link = null;
505 isset($report['visualization']) ? $visualization = $report['visualization'] : $visualization = null;
506 isset($report['chart']) ? $chart = $report['chart'] : $chart = null;
507 isset($report['chartoptions']) ? $chartoptions = $report['chartoptions'] : $chartoptions = null;
508 isset($report['dataoptions']) ? $dataoptions = $report['dataoptions'] : $dataoptions = null;
509 isset($report['filteroptions']) ? $filteroptions = $report['filteroptions'] : $filteroptions = null;
510 isset($report['tableoptions']) ? $tableoptions = $report['tableoptions'] : $tableoptions = null;
511 isset($report['dimension1']) ? $dimension1 = $report['dimension1'] : $dimension1 = null;
512 isset($report['dimension2']) ? $dimension2 = $report['dimension2'] : $dimension2 = null;
513 isset($report['value']) ? $value = $report['value'] : $value = null;
514 $isFlexible = $type === DatasourceController::DATASET_TYPE_INTERNAL_DB && (
515 ($exportedDataset['storageMode'] ?? $exportedDataset['storage_mode'] ?? 'legacy') === 'flexible_shared'
516 || isset($data['flexible'])
517 );
518
519 if ($type === DatasourceController::DATASET_TYPE_INTERNAL_DB) { // New dataset
520 if ($isFlexible) {
521 $exportedColumns = $exportedDataset['columns'] ?? ($data['flexible']['columns'] ?? []);
522 $definitions = array_map(static fn (array $column): array => [
523 'name' => $column['name'],
524 'type' => $column['type'],
525 'role' => $column['role'],
526 'nullable' => $column['nullable'],
527 'defaultAggregation' => $column['defaultAggregation'] ?? null,
528 ], $exportedColumns);
529 $descriptor = $this->DatasetService->createFlexible($name, $definitions);
530 $dataset = (int)$descriptor['id'];
531 foreach ($exportedColumns as $index => $oldColumn) {
532 if (isset($oldColumn['ref'], $descriptor['columns'][$index]['ref'])) {
533 $columnMap[$oldColumn['ref']] = $descriptor['columns'][$index]['ref'];
534 }
535 }
536 $dimension1 = $this->remapFlexibleValue($dimension1, $columnMap);
537 $dimension2 = $this->remapFlexibleValue($dimension2, $columnMap);
538 $value = $this->remapFlexibleValue($value, $columnMap);

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
createFlexibleMethod · 0.45
readOwnMethod · 0.45
beginTransactionMethod · 0.45