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

Method addDataV2

lib/Controller/ApiDataController.php:105–144  ·  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

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