* add data via there real field names * @param int $datasetId * @return DataResponse * @throws \Exception */
(int $datasetId)
| 305 | * @throws \Exception |
| 306 | */ |
| 307 | #[NoAdminRequired] |
| 308 | #[NoCSRFRequired] |
| 309 | #[CORS] |
| 310 | public function addDataV4(int $datasetId) { |
| 311 | $datasetId = $this->getDatasetIdFromRoute($datasetId); |
| 312 | $message = 'No -data- parameter'; |
| 313 | $params = $this->request->getParams(); |
| 314 | $datasetMetadata = $this->DatasetService->readOwn($datasetId); |
| 315 | |
| 316 | $response = $this->deriveMaintenancePossible($datasetMetadata); |
| 317 | if ($response !== true) return $response; |
| 318 | |
| 319 | $insert = $update = 0; |
| 320 | foreach ($params['data'] as $dataArray) { |
| 321 | |
| 322 | $dimension1 = $this->deriveParameterNames($dataArray, $datasetMetadata, 'dimension1'); |
| 323 | $dimension2 = $this->deriveParameterNames($dataArray, $datasetMetadata, 'dimension2'); |
| 324 | $value = $this->deriveParameterNames($dataArray, $datasetMetadata, 'value'); |
| 325 | |
| 326 | if (!empty($this->errors)) { |
| 327 | return $this->requestResponse(false, self::MISSING_PARAM, implode(',', $this->errors)); |
| 328 | } |
| 329 | |
| 330 | $action = $this->StorageService->update($datasetId, $dimension1, $dimension2, $value, null, null, null, false); |
| 331 | $insert = $insert + $action['insert']; |
| 332 | $update = $update + $action['update']; |
| 333 | |
| 334 | $message = 'Data update successful'; |
| 335 | } |
| 336 | if ($insert > 0 || $update > 0) { |
| 337 | $this->ReportService->increaseVersionByDataset($datasetId); |
| 338 | $this->DatasetService->provider($datasetId); |
| 339 | } |
| 340 | |
| 341 | return $this->requestResponse(true, Http::STATUS_OK, $message); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * JSON request bodies can overwrite controller arguments after route matching. |
nothing calls this directly
no test coverage detected