* Update data to the storage backend * * @NoAdminRequired * @param int $datasetId * @param $dimension1 * @param $dimension2 * @param $value * @param string|null $user_id * @param $bulkInsert * @param $aggregation * @return array * @throws Exception */
( int $datasetId, $dimension1, $dimension2, $value, ?string $user_id = null, $bulkInsert = null, $aggregation = null, bool $increaseVersion = true )
| 108 | * @throws Exception |
| 109 | */ |
| 110 | public function update( |
| 111 | int $datasetId, |
| 112 | $dimension1, |
| 113 | $dimension2, |
| 114 | $value, |
| 115 | ?string $user_id = null, |
| 116 | $bulkInsert = null, |
| 117 | $aggregation = null, |
| 118 | bool $increaseVersion = true |
| 119 | ) { |
| 120 | TODO: |
| 121 | //dates in both columns |
| 122 | $dimension2 = $this->convertGermanDateFormat($dimension2); |
| 123 | //convert date into timestamp |
| 124 | //$timestamp = $this->convertGermanDateFormat($timestamp); |
| 125 | $value = $this->floatvalue($value); |
| 126 | $validate = ''; |
| 127 | $insert = $update = $error = $action = 0; |
| 128 | |
| 129 | // replace text variables like %now% |
| 130 | $dimension1 = $this->VariableService->replaceTextVariablesSingle($dimension1); |
| 131 | $dimension2 = $this->VariableService->replaceTextVariablesSingle($dimension2); |
| 132 | |
| 133 | // in case a dimension is empty (e.g. manual data input), we properly null it as also null is coming from data loads |
| 134 | $dimension1 = $dimension1 === '' ? null : $dimension1; |
| 135 | $dimension2 = $dimension2 === '' ? null : $dimension2; |
| 136 | |
| 137 | if ($value !== false) { |
| 138 | try { |
| 139 | $action = $this->StorageMapper->create($datasetId, $dimension1, $dimension2, $value, $user_id, null, $bulkInsert, $aggregation); |
| 140 | } catch (\Exception $e) { |
| 141 | $error = 1; |
| 142 | } |
| 143 | if ($action === 'insert') $insert = 1; elseif ($action === 'update') $update = 1; |
| 144 | if ($increaseVersion && ($action === 'insert' || $action === 'update')) { |
| 145 | $this->ReportService->increaseVersionByDataset($datasetId); |
| 146 | } |
| 147 | } else { |
| 148 | $error = 1; |
| 149 | } |
| 150 | |
| 151 | // get all reports for the dataset and evaluate their thresholds for push notifications |
| 152 | if ($error === 0) { |
| 153 | foreach ($this->ReportService->reportsForDataset($datasetId) as $report) { |
| 154 | $validateResult = $this->ThresholdService->validate($report['id'], $dimension1, $dimension2, $value, $insert); |
| 155 | if ($validateResult !== null) $validate = $validateResult; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return [ |
| 160 | 'insert' => $insert, |
| 161 | 'update' => $update, |
| 162 | 'error' => $error, |
| 163 | 'validate' => $validate |
| 164 | ]; |
| 165 | } |
| 166 | |
| 167 | /** |
nothing calls this directly
no test coverage detected