* Get the data from backend; * pre-evaluation of valid datasetId within read & readPublic is trusted here * also used in Pagecontroller-indexPublicMin ToDo: make this private * * @param $reportMetadata * @return array * @throws Exception */
($reportMetadata)
| 309 | * @throws Exception |
| 310 | */ |
| 311 | #[NoAdminRequired] |
| 312 | public function getData($reportMetadata) { |
| 313 | $datasource = (int)$reportMetadata['type']; |
| 314 | $datasetId = (int)$reportMetadata['dataset']; |
| 315 | |
| 316 | $filterOptions = $reportMetadata['filteroptions']; // need to remember the filter with original text variables |
| 317 | $reportMetadata = $this->VariableService->replaceFilterVariables($reportMetadata); // replace %xx% dynamic variables |
| 318 | |
| 319 | try { |
| 320 | if ($datasource === DatasourceController::DATASET_TYPE_INTERNAL_DB) { |
| 321 | // Internal data |
| 322 | if ($datasetId !== 0) { |
| 323 | $result = $this->StorageService->read($datasetId, $reportMetadata); |
| 324 | } else { |
| 325 | $result['error'] = 'inconsistent report'; |
| 326 | } |
| 327 | } else { |
| 328 | // Realtime data |
| 329 | $result = $this->DatasourceController->read($datasource, $reportMetadata); |
| 330 | $result = DatasourceResultSanitizer::sanitize($result); |
| 331 | if (isset($result['filteroptions']) && is_string($result['filteroptions'])) { |
| 332 | $reportMetadata['filteroptions'] = $result['filteroptions']; |
| 333 | $filterOptions = $result['filteroptions']; |
| 334 | unset($result['filteroptions']); |
| 335 | } |
| 336 | |
| 337 | // datasource confirmed a stable cache key and no change |
| 338 | if (isset($result['cache']['notModified']) && $result['cache']['notModified'] === true) { |
| 339 | return $result; |
| 340 | } |
| 341 | } |
| 342 | } catch (\InvalidArgumentException $e) { |
| 343 | $result = ['error' => $e->getMessage(), 'data' => []]; |
| 344 | } |
| 345 | |
| 346 | $transformationOptions = json_decode((string)($reportMetadata['filteroptions'] ?? ''), true); |
| 347 | if (is_array($transformationOptions) && isset($transformationOptions['transformations']) && (string)($result['error'] ?? 0) === '0') { |
| 348 | try { |
| 349 | if (isset($transformationOptions['topN']) || isset($transformationOptions['timeAggregation'])) { |
| 350 | throw new \InvalidArgumentException('Calculated report measures cannot yet be combined with Top N or time aggregation.'); |
| 351 | } |
| 352 | $result = $this->TransformationService->execute($result, $transformationOptions['transformations'], $transformationOptions); |
| 353 | } catch (\InvalidArgumentException $e) { |
| 354 | $result['error'] = $e->getMessage(); |
| 355 | $result['data'] = []; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | // sort the data by a given column |
| 360 | if ($filterOptions && isset($result['data']) && !($result['queryProcessing']['backendProcessed'] ?? false)) { |
| 361 | $result['data'] = $this->sortByColumn($result['data'], $filterOptions); |
| 362 | } |
| 363 | |
| 364 | unset($reportMetadata['parent'], $reportMetadata['user_id'], $reportMetadata['link'], $reportMetadata['dimension1'], $reportMetadata['dimension2'], $reportMetadata['dimension3'], $reportMetadata['value'], $reportMetadata['password'], $reportMetadata['dataset'], $reportMetadata['cacheKey'], $reportMetadata['panoramaMappings']); |
| 365 | |
| 366 | $result['filterApplied'] = $reportMetadata['filteroptions']; |
| 367 | $reportMetadata['filteroptions'] = $filterOptions; // keep the original filters |
| 368 |
no test coverage detected