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

Method import

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

446 * @throws Exception
447 */
448 public function import(?string $path = null, ?string $raw = null) {
449 if ($path !== '' and $path !== null) {
450 $file = $this->rootFolder->getUserFolder($this->userId)->get($path);
451 $data = $file->getContent();
452 } else if ($raw !== null) {
453 $data = $raw;
454 } else {
455 return 0;
456 }
457 $data = json_decode($data, true);
458
459 $report = $data['report'];
460 isset($report['name']) ? $name = $report['name'] : $name = '';
461 isset($report['subheader']) ? $subheader = $report['subheader'] : $subheader = '';
462 $parent = 0;
463 $dataset = 0;
464 isset($report['type']) ? $type = (int)$report['type'] : $type = null;
465 isset($report['link']) ? $link = $report['link'] : $link = null;
466 isset($report['visualization']) ? $visualization = $report['visualization'] : $visualization = null;
467 isset($report['chart']) ? $chart = $report['chart'] : $chart = null;
468 isset($report['chartoptions']) ? $chartoptions = $report['chartoptions'] : $chartoptions = null;
469 isset($report['dataoptions']) ? $dataoptions = $report['dataoptions'] : $dataoptions = null;
470 isset($report['filteroptions']) ? $filteroptions = $report['filteroptions'] : $filteroptions = null;
471 isset($report['tableoptions']) ? $tableoptions = $report['tableoptions'] : $tableoptions = null;
472 isset($report['dimension1']) ? $dimension1 = $report['dimension1'] : $dimension1 = null;
473 isset($report['dimension2']) ? $dimension2 = $report['dimension2'] : $dimension2 = null;
474 isset($report['value']) ? $value = $report['value'] : $value = null;
475
476 if ($type === DatasourceController::DATASET_TYPE_INTERNAL_DB) { // New dataset
477 $dataset = $this->DatasetService->create($name, $dimension1, $dimension2, $value);
478 }
479 $reportId = $this->create($name, $subheader, $parent, $type, $dataset, $link, $visualization, $chart, $dimension1, $dimension2, $value);
480 $this->updateOptions($reportId, $chartoptions, $dataoptions, $filteroptions, $tableoptions);
481 $report = $this->ReportMapper->readOwn($reportId);
482 $datasetId = $report['dataset'];
483
484 $this->DataloadMapper->beginTransaction();
485
486 foreach ($data['dataload'] as $dataload) {
487 isset($dataload['datasource']) ? $datasource = $dataload['datasource'] : $datasource = null;
488 isset($dataload['name']) ? $name = $dataload['name'] : $name = null;
489 isset($dataload['option']) ? $option = $dataload['option'] : $option = null;
490 $schedule = null;
491
492 $dataloadId = $this->DataloadMapper->create($datasetId, $datasource);
493 $this->DataloadMapper->update($dataloadId, $name, $option, $schedule);
494 }
495
496 foreach ($data['threshold'] as $threshold) {
497 isset($threshold['dimension']) ? $dimension = $threshold['dimension'] : $dimension = null;
498 isset($threshold['value']) ? $value = $threshold['value'] : $value = null;
499 isset($threshold['option']) ? $option = $threshold['option'] : $option = null;
500 isset($threshold['severity']) ? $severity = $threshold['severity'] : $severity = null;
501 isset($threshold['coloring']) ? $coloring = $threshold['coloring'] : $coloring = 'row';
502 $value = $this->floatvalue($value);
503 $this->ThresholdMapper->create($reportId, $dimension, $value, $option, $severity, $coloring);
504 }
505

Calls 12

createMethod · 0.95
updateOptionsMethod · 0.95
floatvalueMethod · 0.95
setFavoriteMethod · 0.95
getUserFolderMethod · 0.80
getContentMethod · 0.80
beginTransactionMethod · 0.80
commitMethod · 0.80
getMethod · 0.45
readOwnMethod · 0.45
updateMethod · 0.45
warningMethod · 0.45