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

Method execute

lib/Service/DataloadService.php:232–387  ·  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

230 * @throws Exception
231 */
232 public function execute(int $dataloadId, ?string $file = null, bool $enforceOwnership = true)
233 {
234 $bulkSize = 500;
235 $insert = $update = $error = $delete = $currentCount = 0;
236 $errorMessages = [];
237 $bulkInsert = null;
238 $aggregation = null;
239
240 // get the data from the data source
241 $result = $this->getDataFromDatasource($dataloadId, $file, $enforceOwnership);
242
243 // dont continue in case of data source error
244 if (!is_array($result) || $result['error'] !== 0) {
245 $response = [
246 'insert' => $insert,
247 'update' => $update,
248 'delete' => $delete,
249 'error' => 1,
250 ];
251 if (is_array($result) && is_string($result['error'] ?? null) && $result['error'] !== '') {
252 $response['message'] = $result['error'];
253 }
254 return $response;
255 }
256
257 // get the meta data
258 $dataloadMetadata = $this->getDataloadMetadata($dataloadId, $enforceOwnership);
259 if (empty($dataloadMetadata)) {
260 return [
261 'insert' => $insert,
262 'update' => $update,
263 'delete' => $delete,
264 'error' => 1,
265 ];
266 }
267 $datasetId = $dataloadMetadata['dataset'];
268
269 if (in_array($dataloadMetadata['datasource'], [0, '0'], true)) {
270 try {
271 $filter = $this->deletionFilter((int)$datasetId, $dataloadMetadata['option']);
272 $records = $this->StorageService->deleteWithFilter($datasetId, $filter);
273 } catch (\InvalidArgumentException|FlexibleStorageException $e) {
274 return ['insert' => 0, 'update' => 0, 'delete' => 0, 'error' => 1, 'message' => $e->getMessage()];
275 }
276
277 return [
278 'insert' => $insert,
279 'update' => $update,
280 'delete' => $records,
281 'error' => $error,
282 ];
283 }
284
285 $option = json_decode($dataloadMetadata['option'], true);
286 $dataset = $this->DatasetService->read((int)$datasetId);
287 if (is_array($dataset) && ($dataset['storageMode'] ?? 'legacy') === 'flexible_shared') {
288 try {
289 $flexibleResult = $this->FlexibleStorageService->executeMappedLoad(

Callers 1

executeByScheduleMethod · 0.95

Calls 15

getDataFromDatasourceMethod · 0.95
getDataloadMetadataMethod · 0.95
deletionFilterMethod · 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