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

Method importFile

lib/Service/DataloadService.php:528–560  ·  view source on GitHub ↗

* Import data into dataset from an internal or external file * * @NoAdminRequired * @param int $objectId * @param $path * @param bool $isDataset * @return array|false * @throws \OCP\DB\Exception */

(int $objectId, $path, bool $isDataset)

Source from the content-addressed store, hash-verified

526 * @throws \OCP\DB\Exception
527 */
528 public function importFile(int $objectId, $path, bool $isDataset)
529 {
530 $datasetId = $this->getDatasetId($objectId, $isDataset);
531 if ($datasetId != '') {
532 $insert = $update = 0;
533 $reportMetadata = array();
534 $reportMetadata['link'] = $path;
535 $reportMetadata['user_id'] = $this->userId;
536 $result = $this->DatasourceController->read(DatasourceController::DATASET_TYPE_LOCAL_CSV, $reportMetadata, false);
537
538 if ($result['error'] === 0) {
539 foreach ($result['data'] as &$row) {
540 $action = $this->StorageService->update($datasetId, $row[0], $row[1], $row[2]);
541 $insert = $insert + $action['insert'];
542 $update = $update + $action['update'];
543 }
544 }
545
546 $result = [
547 'insert' => $insert,
548 'update' => $update,
549 'error' => $result['error'],
550 ];
551
552 // Update the Context Chat backend
553 $this->DatasetService->provider($datasetId);
554
555 //if ($result['error'] === 0) $this->ActivityManager->triggerEvent($dataset, ActivityManager::OBJECT_DATA, ActivityManager::SUBJECT_DATA_ADD_IMPORT);
556 return $result;
557 } else {
558 return false;
559 }
560 }
561
562 private function getDatasetId($objectId, bool $isDataset)
563 {

Callers 1

onEventMethod · 0.45

Calls 4

getDatasetIdMethod · 0.95
readMethod · 0.45
updateMethod · 0.45
providerMethod · 0.45

Tested by

no test coverage detected