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

Method getDataFromDatasource

lib/Service/DataloadService.php:400–462  ·  view source on GitHub ↗

* get the data from data source * to be used in simulation or execution * * @param int $dataloadId * @param string|null $file * @return array|NotFoundResponse * @throws NotFoundResponse * @throws \OCP\DB\Exception */

(int $dataloadId, ?string $file = null, bool $enforceOwnership = true)

Source from the content-addressed store, hash-verified

398 * @throws \OCP\DB\Exception
399 */
400 public function getDataFromDatasource(int $dataloadId, ?string $file = null, bool $enforceOwnership = true)
401 {
402 $dataloadMetadata = $this->getDataloadMetadata($dataloadId, $enforceOwnership);
403
404 if (!empty($dataloadMetadata)) {
405
406 if ($dataloadMetadata['datasource'] !== 0) {
407 $dataloadMetadata['link'] = $dataloadMetadata['option']; //remap until data source table is renamed link=>option
408 unset($dataloadMetadata['cacheKey']);
409 if ($file !== null && $file !== '') {
410 $option = json_decode($dataloadMetadata['link'], true);
411 if (!is_array($option)) {
412 $option = [];
413 }
414 $option['link'] = $file;
415 $option['file'] = $file;
416 $dataloadMetadata['link'] = json_encode($option);
417 $this->logger->info('Analytics flow dataload file override', [
418 'dataloadId' => $dataloadId,
419 'datasetId' => $dataloadMetadata['dataset'],
420 'datasourceId' => $dataloadMetadata['datasource'],
421 'file' => $file,
422 'filename' => basename($file),
423 ]);
424 }
425
426 $result = $this->DatasourceController->read((int)$dataloadMetadata['datasource'], $dataloadMetadata, false);
427 $result['datasetId'] = $dataloadMetadata['dataset'];
428 $dataset = $this->DatasetService->read((int)$dataloadMetadata['dataset']);
429 if (is_array($dataset) && ($dataset['storageMode'] ?? 'legacy') === 'flexible_shared') {
430 $result['storageMode'] = 'flexible_shared';
431 $result['schemaVersion'] = (int)$dataset['schemaVersion'];
432 $result['storageMapping'] = json_decode((string)($dataloadMetadata['storage_mapping'] ?? ''), true);
433 $result['mappingPreview'] = $this->FlexibleStorageService->previewMapping(
434 (int)$dataloadMetadata['dataset'],
435 $dataloadMetadata['storage_mapping'] ?? null,
436 is_array($result['header'] ?? null) ? $result['header'] : [],
437 is_array($result['data'] ?? null) ? $result['data'] : []
438 );
439 }
440 } else {
441 // this is a deletion request. Just run the simulation and return the possible row count in the expected result array
442 $option = json_decode($dataloadMetadata['option'], true);
443
444 // deletion jobs are using the same dimension/option/value settings a report filter
445 $filter = array();
446 $filter['filteroptions'] = '{"filter":{"' . $option['filterDimension'] . '":{"option":"' . $option['filterOption'] . '","value":"' . $option['filterValue'] . '"}}}';
447 // Text variables like %xx% could be in use here
448 $filter = $this->VariableService->replaceFilterVariables($filter);
449
450 $result = [
451 'header' => '',
452 'dimensions' => '',
453 'data' => $this->StorageService->deleteWithFilterSimulate($dataloadMetadata['dataset'], json_decode($filter['filteroptions'], true)),
454 'error' => 0,
455 ];
456 }
457

Calls 6

getDataloadMetadataMethod · 0.95
previewMappingMethod · 0.80
infoMethod · 0.45
readMethod · 0.45