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

Method execute

lib/Service/DataloadService.php:231–388  ·  view source on GitHub ↗

* execute a data load from data source and store into dataset * * @param int $dataloadId * @param string|null $file * @return array * @throws Exception */

(int $dataloadId, ?string $file = null, bool $enforceOwnership = true)

Source from the content-addressed store, hash-verified

229 * @throws Exception
230 */
231 public function execute(int $dataloadId, ?string $file = null, bool $enforceOwnership = true)
232 {
233 $bulkSize = 500;
234 $insert = $update = $error = $delete = $currentCount = 0;
235 $errorMessages = [];
236 $bulkInsert = null;
237 $aggregation = null;
238
239 // get the data from the data source
240 $result = $this->getDataFromDatasource($dataloadId, $file, $enforceOwnership);
241
242 // dont continue in case of data source error
243 if (!is_array($result) || $result['error'] !== 0) {
244 $response = [
245 'insert' => $insert,
246 'update' => $update,
247 'delete' => $delete,
248 'error' => 1,
249 ];
250 if (is_array($result) && is_string($result['error'] ?? null) && $result['error'] !== '') {
251 $response['message'] = $result['error'];
252 }
253 return $response;
254 }
255
256 // get the meta data
257 $dataloadMetadata = $this->getDataloadMetadata($dataloadId, $enforceOwnership);
258 if (empty($dataloadMetadata)) {
259 return [
260 'insert' => $insert,
261 'update' => $update,
262 'delete' => $delete,
263 'error' => 1,
264 ];
265 }
266 $option = json_decode($dataloadMetadata['option'], true);
267 $datasetId = $dataloadMetadata['dataset'];
268
269 // this is a deletion request. Just run the deletion and stop after that with a return.
270 if ($dataloadMetadata['datasource'] === 0) {
271 // deletion jobs are using the same dimension/option/value settings a report filter
272 $filter = array();
273 $filter['filteroptions'] = '{"filter":{"' . $option['filterDimension'] . '":{"option":"' . $option['filterOption'] . '","value":"' . $option['filterValue'] . '"}}}';
274 // Text variables like %xx% could be in use here
275 $filter = $this->VariableService->replaceFilterVariables($filter);
276
277 $records = $this->StorageService->deleteWithFilter($dataloadMetadata['dataset'], json_decode($filter['filteroptions'], true));
278
279 return [
280 'insert' => $insert,
281 'update' => $update,
282 'delete' => $records,
283 'error' => $error,
284 ];
285 }
286
287 $dataset = $this->DatasetService->read((int)$datasetId);
288 if (is_array($dataset) && ($dataset['storageMode'] ?? 'legacy') === 'flexible_shared') {

Callers 1

executeByScheduleMethod · 0.95

Calls 15

getDataFromDatasourceMethod · 0.95
getDataloadMetadataMethod · 0.95
executeMappedLoadMethod · 0.80
toResponseMethod · 0.80
countFunction · 0.50
deleteWithFilterMethod · 0.45
readMethod · 0.45
providerMethod · 0.45
deleteMethod · 0.45
getRecordCountMethod · 0.45
beginTransactionMethod · 0.45

Tested by

no test coverage detected