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

Method update

lib/Service/StorageService.php:145–214  ·  view source on GitHub ↗

* 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
	)

Source from the content-addressed store, hash-verified

143 * @throws Exception
144 */
145 public function update(
146 int $datasetId,
147 $dimension1,
148 $dimension2,
149 $value,
150 ?string $user_id = null,
151 $bulkInsert = null,
152 $aggregation = null,
153 bool $increaseVersion = true
154 ) {
155 $this->requireLegacy($datasetId);
156 TODO:
157 //dates in both columns
158 $dimension2 = $this->convertGermanDateFormat($dimension2);
159 //convert date into timestamp
160 //$timestamp = $this->convertGermanDateFormat($timestamp);
161 $value = $this->floatvalue($value);
162 $validate = '';
163 $errorMessage = '';
164 $insert = $update = $error = $action = 0;
165
166 // replace text variables like %now%
167 $dimension1 = $this->VariableService->replaceTextVariablesSingle($dimension1);
168 $dimension2 = $this->VariableService->replaceTextVariablesSingle($dimension2);
169
170 // in case a dimension is empty (e.g. manual data input), we properly null it as also null is coming from data loads
171 $dimension1 = $dimension1 === '' ? null : $dimension1;
172 $dimension2 = $dimension2 === '' ? null : $dimension2;
173
174 if ($value !== false) {
175 try {
176 $action = $this->StorageMapper->create($datasetId, $dimension1, $dimension2, $value, $user_id, null, $bulkInsert, $aggregation);
177 } catch (\Exception $e) {
178 $error = 1;
179 $errorMessage = 'Storage operation failed; see preceding Analytics log entry';
180 $this->logger->error('Analytics data row storage failed for dataset ' . $datasetId . ': ' . $e->getMessage(), [
181 'datasetId' => $datasetId,
182 'exceptionClass' => $e::class,
183 'exceptionCode' => $e->getCode(),
184 'exception' => $e,
185 ]);
186 }
187 if ($action === 'insert') $insert = 1; elseif ($action === 'update') $update = 1;
188 if ($increaseVersion && ($action === 'insert' || $action === 'update')) {
189 $this->ReportService->increaseVersionByDataset($datasetId);
190 }
191 } else {
192 $error = 1;
193 $errorMessage = 'Last field must be a valid number';
194 }
195
196 // get all reports for the dataset and evaluate their thresholds for push notifications
197 if ($error === 0) {
198 foreach ($this->ReportService->reportsForDataset($datasetId) as $report) {
199 $validateResult = $this->ThresholdService->validate($report['id'], $dimension1, $dimension2, $value, $insert);
200 if ($validateResult !== null) $validate = $validateResult;
201 }
202 }

Callers

nothing calls this directly

Calls 9

requireLegacyMethod · 0.95
floatvalueMethod · 0.95
createMethod · 0.45
errorMethod · 0.45
reportsForDatasetMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected