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

Method execute

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

176 * @throws Exception
177 */
178 public function execute(int $dataloadId, ?string $file = null, bool $enforceOwnership = true)
179 {
180 $bulkSize = 500;
181 $insert = $update = $error = $delete = $currentCount = 0;
182 $bulkInsert = null;
183 $aggregation = null;
184
185 // get the data from the data source
186 $result = $this->getDataFromDatasource($dataloadId, $file, $enforceOwnership);
187
188 // dont continue in case of data source error
189 if (!is_array($result) || $result['error'] !== 0) {
190 return [
191 'insert' => $insert,
192 'update' => $update,
193 'delete' => $delete,
194 'error' => 1,
195 ];
196 }
197
198 // get the meta data
199 $dataloadMetadata = $this->getDataloadMetadata($dataloadId, $enforceOwnership);
200 if (empty($dataloadMetadata)) {
201 return [
202 'insert' => $insert,
203 'update' => $update,
204 'delete' => $delete,
205 'error' => 1,
206 ];
207 }
208 $option = json_decode($dataloadMetadata['option'], true);
209 $datasetId = $dataloadMetadata['dataset'];
210
211 // this is a deletion request. Just run the deletion and stop after that with a return.
212 if ($dataloadMetadata['datasource'] === 0) {
213 // deletion jobs are using the same dimension/option/value settings a report filter
214 $filter = array();
215 $filter['filteroptions'] = '{"filter":{"' . $option['filterDimension'] . '":{"option":"' . $option['filterOption'] . '","value":"' . $option['filterValue'] . '"}}}';
216 // Text variables like %xx% could be in use here
217 $filter = $this->VariableService->replaceFilterVariables($filter);
218
219 $records = $this->StorageService->deleteWithFilter($dataloadMetadata['dataset'], json_decode($filter['filteroptions'], true));
220
221 return [
222 'insert' => $insert,
223 'update' => $update,
224 'delete' => $records,
225 'error' => $error,
226 ];
227 }
228
229 // "delete all date before loading" is true in the data source options
230 // in this case, bulkInsert is additionally set to true. Then no further checks for existing records are needed
231 // to reduce db selects
232 if (isset($option['delete']) and $option['delete'] === 'true') {
233 $this->StorageService->delete($datasetId, '*', '*', $dataloadMetadata['user_id']);
234 $bulkInsert = true;
235 }

Callers 1

executeByScheduleMethod · 0.95

Calls 12

getDataFromDatasourceMethod · 0.95
getDataloadMetadataMethod · 0.95
beginTransactionMethod · 0.80
commitMethod · 0.80
deleteWithFilterMethod · 0.45
deleteMethod · 0.45
getRecordCountMethod · 0.45
infoMethod · 0.45
updateMethod · 0.45
providerMethod · 0.45

Tested by

no test coverage detected