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

Method addDataV2

lib/Controller/ApiDataController.php:101–140  ·  view source on GitHub ↗

* add data via there real field names * @param int $datasetId * @return DataResponse * @throws \Exception */

(int $datasetId)

Source from the content-addressed store, hash-verified

99 * @throws \Exception
100 */
101 #[NoAdminRequired]
102 #[NoCSRFRequired]
103 #[CORS]
104 public function addDataV2(int $datasetId) {
105 $datasetId = $this->getDatasetIdFromRoute($datasetId);
106 $message = 'No -data- parameter';
107 $params = $this->request->getParams();
108 $datasetMetadata = $this->DatasetService->readOwn($datasetId);
109
110 $response = $this->deriveMaintenancePossible($datasetMetadata);
111 if ($response !== true) return $response;
112
113 $insert = $update = 0;
114 foreach ($params['data'] as $dataArray) {
115
116 $dimension1 = $this->deriveParameterNames($dataArray, $datasetMetadata, 'dimension1');
117 $dimension2 = $this->deriveParameterNames($dataArray, $datasetMetadata, 'dimension2');
118 $value = $this->deriveParameterNames($dataArray, $datasetMetadata, 'value');
119
120 if (!empty($this->errors)) {
121 return $this->requestResponse(false, self::MISSING_PARAM, implode(',', $this->errors));
122 }
123
124 // replace text variables like %now%
125 $dimension1 = $this->replaceTextVariablesSingle($dimension1);
126 $dimension2 = $this->replaceTextVariablesSingle($dimension2);
127
128 $action = $this->StorageService->update($datasetId, $dimension1, $dimension2, $value, null, null, null, false);
129 $insert = $insert + $action['insert'];
130 $update = $update + $action['update'];
131
132 $message = 'Data update successful';
133 }
134 if ($insert > 0 || $update > 0) {
135 $this->ReportService->increaseVersionByDataset($datasetId);
136 $this->DatasetService->provider($datasetId);
137 }
138
139 return $this->requestResponse(true, Http::STATUS_OK, $message);
140 }
141
142 /**
143 * from V3 to V4, the data format for %currentDate% has changed.

Callers 1

dataAddV3Method · 0.95

Calls 9

getDatasetIdFromRouteMethod · 0.95
deriveParameterNamesMethod · 0.95
requestResponseMethod · 0.95
readOwnMethod · 0.45
updateMethod · 0.45
providerMethod · 0.45

Tested by

no test coverage detected