@@ -3,7 +3,6 @@ |
||
3 | 3 | |
4 | 4 | use Doctrine\DBAL\Connection; |
5 | 5 | use Doctrine\DBAL\Logging\SQLLogger; |
6 | -use Doctrine\DBAL\SQLParserUtils; |
|
7 | 6 | use function PHPSTORM_META\type; |
8 | 7 | use Psr\Log\LoggerInterface; |
9 | 8 |
@@ -57,7 +57,7 @@ |
||
57 | 57 | $query = null; |
58 | 58 | if ($params && $this->authorizedSQLWithParams) { |
59 | 59 | $this->logger->debug($sql.' -- Params : {params} - Types : {types}', ['params' => json_encode($params), 'types' => json_encode($types)]); |
60 | - } elseif($this->authorizedSQLWithoutParams) { |
|
60 | + } elseif ($this->authorizedSQLWithoutParams) { |
|
61 | 61 | $this->logger->debug($sql); |
62 | 62 | } |
63 | 63 | } |
@@ -8,7 +8,6 @@ |
||
8 | 8 | use Wabel\Zoho\CRM\AbstractZohoDao; |
9 | 9 | use Wabel\Zoho\CRM\Service\EntitiesGeneratorService; |
10 | 10 | use Wabel\Zoho\CRM\ZohoBeanInterface; |
11 | -use zcrmsdk\crm\api\response\EntityResponse; |
|
12 | 11 | |
13 | 12 | /** |
14 | 13 | * Description of ZohoDatabasePusher. |
@@ -288,6 +288,9 @@ discard block |
||
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | + /** |
|
292 | + * @param string $needle |
|
293 | + */ |
|
291 | 294 | private function endsWith($haystack, $needle) { |
292 | 295 | return substr_compare($haystack, $needle, -strlen($needle)) === 0; |
293 | 296 | } |
@@ -322,7 +325,6 @@ discard block |
||
322 | 325 | * Insert data to bean in order to update zoho records. |
323 | 326 | * |
324 | 327 | * @param ZohoBeanInterface $zohoBean |
325 | - * @param array $fieldsMatching |
|
326 | 328 | * @param type $columnName |
327 | 329 | * @param type $valueDb |
328 | 330 | */ |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | { |
68 | 68 | $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix); |
69 | 69 | if ($update) { |
70 | - return (int)$this->connection->executeQuery('SELECT COUNT(DISTINCT uid) AS nb FROM `local_update` WHERE table_name LIKE :tableName AND error IS NULL', ['tableName' => $tableName])->fetchColumn(); |
|
70 | + return (int) $this->connection->executeQuery('SELECT COUNT(DISTINCT uid) AS nb FROM `local_update` WHERE table_name LIKE :tableName AND error IS NULL', ['tableName' => $tableName])->fetchColumn(); |
|
71 | 71 | } |
72 | - return (int)$this->connection->executeQuery('SELECT COUNT(uid) AS nb FROM `local_insert` WHERE table_name LIKE :tableName AND error IS NULL', ['tableName' => $tableName])->fetchColumn(); |
|
72 | + return (int) $this->connection->executeQuery('SELECT COUNT(uid) AS nb FROM `local_insert` WHERE table_name LIKE :tableName AND error IS NULL', ['tableName' => $tableName])->fetchColumn(); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $localTable = $update ? 'local_update' : 'local_insert'; |
83 | 83 | $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix); |
84 | 84 | $countToPush = $this->countElementInTable($zohoDao, $update); |
85 | - $this->logger->notice($countToPush . ' records to ' . ($update ? 'update' : 'insert') . ' into Zoho for module ' . $zohoDao->getPluralModuleName()); |
|
85 | + $this->logger->notice($countToPush.' records to '.($update ? 'update' : 'insert').' into Zoho for module '.$zohoDao->getPluralModuleName()); |
|
86 | 86 | if ($countToPush) { |
87 | 87 | do { |
88 | 88 | $rowsDeleted = []; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | ] |
256 | 256 | ); |
257 | 257 | } else { |
258 | - $countResult = (int)$this->connection->fetchColumn('select count(id) from ' . $tableName . ' where id = :id', ['id' => $zohoBean->getZohoId()]); |
|
258 | + $countResult = (int) $this->connection->fetchColumn('select count(id) from '.$tableName.' where id = :id', ['id' => $zohoBean->getZohoId()]); |
|
259 | 259 | //If the sent data were duplicates Zoho can merged so we need to check if the Zoho ID already exist. |
260 | 260 | if ($countResult === 0) { |
261 | 261 | // ID not exist we can update the new row with the Zoho ID |
@@ -361,13 +361,13 @@ discard block |
||
361 | 361 | $value = \DateTime::createFromFormat('Y-m-d H:i:s', $value) ?: null; |
362 | 362 | break; |
363 | 363 | case 'boolean' : |
364 | - $value = (bool)$value; |
|
364 | + $value = (bool) $value; |
|
365 | 365 | break; |
366 | 366 | case 'percent' : |
367 | - $value = (int)$value; |
|
367 | + $value = (int) $value; |
|
368 | 368 | break; |
369 | 369 | case 'double' : |
370 | - $value = (float)$value; |
|
370 | + $value = (float) $value; |
|
371 | 371 | break; |
372 | 372 | case 'multiselectlookup': |
373 | 373 | case 'multiuserlookup': |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | public function createUuidInsertTrigger(Table $table) |
96 | 96 | { |
97 | 97 | $triggerName = sprintf('TRG_%s_SETUUIDBEFOREINSERT', $table->getName()); |
98 | - $this->logger->info('Creating ' . $triggerName . ' trigger for table ' . $table->getName() . '...'); |
|
98 | + $this->logger->info('Creating '.$triggerName.' trigger for table '.$table->getName().'...'); |
|
99 | 99 | |
100 | 100 | //Fix - temporary MySQL 5.7 strict mode |
101 | 101 | $sql = sprintf( |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | public function createInsertTrigger(Table $table) |
125 | 125 | { |
126 | 126 | $triggerName = sprintf('TRG_%s_ONINSERT', $table->getName()); |
127 | - $this->logger->info('Creating ' . $triggerName . ' trigger for table ' . $table->getName() . '...'); |
|
127 | + $this->logger->info('Creating '.$triggerName.' trigger for table '.$table->getName().'...'); |
|
128 | 128 | |
129 | 129 | $tableNameQuoted = $this->connection->quote($table->getName()); |
130 | 130 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public function createDeleteTrigger(Table $table) |
152 | 152 | { |
153 | 153 | $triggerName = sprintf('TRG_%s_ONDELETE', $table->getName()); |
154 | - $this->logger->info('Creating ' . $triggerName . ' trigger for table ' . $table->getName() . '...'); |
|
154 | + $this->logger->info('Creating '.$triggerName.' trigger for table '.$table->getName().'...'); |
|
155 | 155 | |
156 | 156 | $tableNameQuoted = $this->connection->quote($table->getName()); |
157 | 157 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | public function createUpdateTrigger(Table $table) |
179 | 179 | { |
180 | 180 | $triggerName = sprintf('TRG_%s_ONUPDATE', $table->getName()); |
181 | - $this->logger->info('Creating ' . $triggerName . ' trigger for table ' . $table->getName() . '...'); |
|
181 | + $this->logger->info('Creating '.$triggerName.' trigger for table '.$table->getName().'...'); |
|
182 | 182 | |
183 | 183 | $innerCode = ''; |
184 | 184 |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | } |
87 | 87 | |
88 | 88 | $tableName = ZohoDatabaseHelper::getTableName($dao, $this->prefix); |
89 | - $this->logger->notice('Synchronizing DB Model for ' . $tableName . '...'); |
|
89 | + $this->logger->notice('Synchronizing DB Model for '.$tableName.'...'); |
|
90 | 90 | |
91 | 91 | $schema = new Schema(); |
92 | 92 | $table = $schema->createTable($tableName); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | continue 2; |
178 | 178 | break; |
179 | 179 | default: |
180 | - throw new \RuntimeException('Unknown type "' . $field->getType() . '"'); |
|
180 | + throw new \RuntimeException('Unknown type "'.$field->getType().'"'); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // For MySQL, the maximum row size is 65535 bytes. |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | if ($input->getOption('log-path') && $input->getOption('clear-logs')) { |
142 | 142 | $this->logger->notice('Clearing logs...'); |
143 | 143 | $path = $input->getOption('log-path'); |
144 | - $logFile = $path . '/ZCRMClientLibrary.log'; |
|
144 | + $logFile = $path.'/ZCRMClientLibrary.log'; |
|
145 | 145 | if (file_exists($logFile)) { |
146 | 146 | if (is_writable($logFile)) { |
147 | 147 | if (file_put_contents($logFile, '') === false) { |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | if ($input->getOption('log-path') && $input->getOption('dump-logs')) { |
186 | 186 | $this->logger->info('Dumping logs...'); |
187 | 187 | $path = $input->getOption('log-path'); |
188 | - $logFile = $path . '/ZCRMClientLibrary.log'; |
|
188 | + $logFile = $path.'/ZCRMClientLibrary.log'; |
|
189 | 189 | if (file_exists($logFile)) { |
190 | 190 | if (is_readable($logFile)) { |
191 | 191 | $this->logger->info(file_get_contents($logFile)); |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | { |
73 | 73 | $users = $this->zohoUserService->getUsers(); |
74 | 74 | $tableName = 'users'; |
75 | - $this->logger->info('Fetched ' . count($users) . ' records for table ' . $tableName); |
|
75 | + $this->logger->info('Fetched '.count($users).' records for table '.$tableName); |
|
76 | 76 | |
77 | 77 | $table = $this->connection->getSchemaManager()->createSchema()->getTable($tableName); |
78 | 78 | |
79 | - $select = $this->connection->prepare('SELECT * FROM ' . $tableName . ' WHERE id = :id'); |
|
79 | + $select = $this->connection->prepare('SELECT * FROM '.$tableName.' WHERE id = :id'); |
|
80 | 80 | |
81 | 81 | $this->connection->beginTransaction(); |
82 | 82 | foreach ($users as $user) { |
@@ -162,10 +162,10 @@ discard block |
||
162 | 162 | $lastActivityTime = new \DateTime($modifiedSince); |
163 | 163 | } else { |
164 | 164 | if ($tableDetail->hasColumn('modifiedTime')) { |
165 | - $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM ' . $tableName); |
|
165 | + $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM '.$tableName); |
|
166 | 166 | } |
167 | 167 | if (!$lastActivityTime && $tableDetail->hasColumn('createdTime')) { |
168 | - $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM ' . $tableName); |
|
168 | + $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM '.$tableName); |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | if ($lastActivityTime !== null) { |
@@ -191,26 +191,26 @@ discard block |
||
191 | 191 | $recordsPage++; |
192 | 192 | } |
193 | 193 | $totalRecords = count($records); |
194 | - $this->logger->debug($totalRecords . ' records fetched.'); |
|
194 | + $this->logger->debug($totalRecords.' records fetched.'); |
|
195 | 195 | $deletedRecords = []; |
196 | 196 | $totalRecordsDeleted = 0; |
197 | 197 | if (($recordsPage - 1) === 1) { |
198 | 198 | $this->logger->notice(sprintf('Fetching the records to delete for module %s...', $dao->getPluralModuleName())); |
199 | 199 | $deletedRecords = $dao->getDeletedRecordIds($lastActivityTime); |
200 | 200 | $totalRecordsDeleted = count($deletedRecords); |
201 | - $this->logger->debug($totalRecordsDeleted . ' records fetched.'); |
|
201 | + $this->logger->debug($totalRecordsDeleted.' records fetched.'); |
|
202 | 202 | } |
203 | 203 | } else { |
204 | 204 | $this->logger->info(sprintf('Full copy started for module %s', $dao->getPluralModuleName())); |
205 | 205 | $this->logger->notice(sprintf('Fetching the records to insert/update for module ...%s', $dao->getPluralModuleName())); |
206 | 206 | $records = $dao->getRecords(); |
207 | 207 | $totalRecords = count($records); |
208 | - $this->logger->debug($totalRecords . ' records fetched.'); |
|
208 | + $this->logger->debug($totalRecords.' records fetched.'); |
|
209 | 209 | $deletedRecords = []; |
210 | 210 | $stopAndhasMoreResults = false; |
211 | 211 | } |
212 | 212 | } catch (ZCRMException $exception) { |
213 | - $this->logger->error('Error when getting records for module ' . $dao->getPluralModuleName() . ': ' . $exception->getMessage(), [ |
|
213 | + $this->logger->error('Error when getting records for module '.$dao->getPluralModuleName().': '.$exception->getMessage(), [ |
|
214 | 214 | 'exception' => $exception |
215 | 215 | ]); |
216 | 216 | if ($throwErrors) { |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | |
223 | 223 | $table = $this->connection->getSchemaManager()->createSchema()->getTable($tableName); |
224 | 224 | |
225 | - $select = $this->connection->prepare('SELECT * FROM ' . $tableName . ' WHERE id = :id'); |
|
225 | + $select = $this->connection->prepare('SELECT * FROM '.$tableName.' WHERE id = :id'); |
|
226 | 226 | |
227 | 227 | $this->connection->beginTransaction(); |
228 | 228 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | } |
293 | 293 | |
294 | 294 | $this->logger->info(sprintf('Deleting %d records from table %s...', $totalRecordsDeleted, $tableName)); |
295 | - $sqlStatementUid = 'select uid from ' . $this->connection->quoteIdentifier($tableName) . ' where id = :id'; |
|
295 | + $sqlStatementUid = 'select uid from '.$this->connection->quoteIdentifier($tableName).' where id = :id'; |
|
296 | 296 | $processedRecords = 0; |
297 | 297 | $logOffset = $totalRecordsDeleted >= 500 ? 100 : 50; |
298 | 298 | foreach ($deletedRecords as $deletedRecord) { |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $table = $this->connection->getSchemaManager()->createSchema()->getTable($tableName); |
334 | 334 | $apiModuleName = $dao->getPluralModuleName(); |
335 | 335 | |
336 | - $this->logger->notice('Starting bulk fetch for module ' . $apiModuleName . '...'); |
|
336 | + $this->logger->notice('Starting bulk fetch for module '.$apiModuleName.'...'); |
|
337 | 337 | |
338 | 338 | $zohoClient = new ZohoClient([ |
339 | 339 | 'client_id' => ZOHO_CRM_CLIENT_ID, |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | $oauthToken = $zohoClient->getZohoOAuthClient()->getAccessToken(ZOHO_CRM_CLIENT_CURRENT_USER_EMAIL); |
353 | 353 | |
354 | 354 | // Step 1: Create a bulk read job |
355 | - $this->logger->info('Creating read job for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
356 | - $response = $client->request('POST', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read', [ |
|
355 | + $this->logger->info('Creating read job for module '.$apiModuleName.' and page '.$page.'...'); |
|
356 | + $response = $client->request('POST', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read', [ |
|
357 | 357 | 'http_errors' => false, |
358 | 358 | 'headers' => [ |
359 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
359 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
360 | 360 | ], |
361 | 361 | 'json' => [ |
362 | 362 | 'query' => [ |
@@ -374,23 +374,23 @@ discard block |
||
374 | 374 | |
375 | 375 | // We don't care about the job status right now, it will be checked later |
376 | 376 | } else { |
377 | - $this->logger->error('Cannot create bulk read query for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
377 | + $this->logger->error('Cannot create bulk read query for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
378 | 378 | break; |
379 | 379 | } |
380 | 380 | |
381 | 381 | if ($jobId === null) { |
382 | - $this->logger->error('JobID cannot be null. json:' . $resultStr); |
|
382 | + $this->logger->error('JobID cannot be null. json:'.$resultStr); |
|
383 | 383 | break; |
384 | 384 | } |
385 | 385 | |
386 | 386 | // Step 2: Check job status |
387 | 387 | $jobDetails = null; |
388 | 388 | while (true) { |
389 | - $this->logger->info('Checking job ' . $jobId . ' status for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
390 | - $response = $client->request('GET', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read/' . $jobId, [ |
|
389 | + $this->logger->info('Checking job '.$jobId.' status for module '.$apiModuleName.' and page '.$page.'...'); |
|
390 | + $response = $client->request('GET', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read/'.$jobId, [ |
|
391 | 391 | 'http_errors' => false, |
392 | 392 | 'headers' => [ |
393 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
393 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
394 | 394 | ] |
395 | 395 | ]); |
396 | 396 | if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { |
@@ -408,15 +408,15 @@ discard block |
||
408 | 408 | $jobDetails = $json; |
409 | 409 | break; |
410 | 410 | } else { |
411 | - $this->logger->info('Unsupported job status: ' . $resultStr); |
|
411 | + $this->logger->info('Unsupported job status: '.$resultStr); |
|
412 | 412 | break; |
413 | 413 | } |
414 | 414 | } else { |
415 | - $this->logger->error('Unsupported response: ' . $resultStr); |
|
415 | + $this->logger->error('Unsupported response: '.$resultStr); |
|
416 | 416 | break; |
417 | 417 | } |
418 | 418 | } else { |
419 | - $this->logger->error('Cannot get bulk job status query for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
419 | + $this->logger->error('Cannot get bulk job status query for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
420 | 420 | break; |
421 | 421 | } |
422 | 422 | sleep(15); |
@@ -424,31 +424,31 @@ discard block |
||
424 | 424 | |
425 | 425 | // Step 3: Download the result |
426 | 426 | if ($jobDetails === null) { |
427 | - $this->logger->error('JobDetails cannot be empty. json:' . $resultStr); |
|
427 | + $this->logger->error('JobDetails cannot be empty. json:'.$resultStr); |
|
428 | 428 | break; |
429 | 429 | } |
430 | 430 | $this->logger->debug(json_encode($jobDetails)); |
431 | - $this->logger->info('Downloading zip file for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
432 | - $jobZipFile = '/tmp/job_' . $dao->getZCRMModule()->getAPIName() . '_' . $jobDetails['data'][0]['id'] . '.zip'; |
|
431 | + $this->logger->info('Downloading zip file for module '.$apiModuleName.' and page '.$page.'...'); |
|
432 | + $jobZipFile = '/tmp/job_'.$dao->getZCRMModule()->getAPIName().'_'.$jobDetails['data'][0]['id'].'.zip'; |
|
433 | 433 | $jobCsvPath = '/tmp/job_extract'; |
434 | - $jobCsvFile = '/tmp/job_extract/' . $jobDetails['data'][0]['id'] . '.csv'; |
|
434 | + $jobCsvFile = '/tmp/job_extract/'.$jobDetails['data'][0]['id'].'.csv'; |
|
435 | 435 | $canProcessCsv = false; |
436 | 436 | |
437 | - $response = $client->request('GET', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read/' . $jobId . '/result', [ |
|
437 | + $response = $client->request('GET', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read/'.$jobId.'/result', [ |
|
438 | 438 | 'http_errors' => false, |
439 | 439 | 'headers' => [ |
440 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
440 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
441 | 441 | ], |
442 | 442 | 'sink' => $jobZipFile |
443 | 443 | ]); |
444 | 444 | if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { |
445 | - $this->logger->info('Extracting ' . $jobZipFile . ' file for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
445 | + $this->logger->info('Extracting '.$jobZipFile.' file for module '.$apiModuleName.' and page '.$page.'...'); |
|
446 | 446 | $zip = new ZipArchive(); |
447 | 447 | $res = $zip->open($jobZipFile); |
448 | 448 | if ($res === TRUE) { |
449 | 449 | $zip->extractTo($jobCsvPath); |
450 | 450 | $zip->close(); |
451 | - $this->logger->info('File extracted in ' . $jobCsvFile); |
|
451 | + $this->logger->info('File extracted in '.$jobCsvFile); |
|
452 | 452 | $canProcessCsv = true; |
453 | 453 | } else { |
454 | 454 | switch ($res) { |
@@ -480,11 +480,11 @@ discard block |
||
480 | 480 | $zipErrorMessage = "Unknow (Code $res)"; |
481 | 481 | break; |
482 | 482 | } |
483 | - $this->logger->error('Error when extracting zip file: ' . $zipErrorMessage); |
|
483 | + $this->logger->error('Error when extracting zip file: '.$zipErrorMessage); |
|
484 | 484 | break; |
485 | 485 | } |
486 | 486 | } else { |
487 | - $this->logger->error('Cannot download results for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
487 | + $this->logger->error('Cannot download results for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
488 | 488 | break; |
489 | 489 | } |
490 | 490 | |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | $this->logger->info('Saving records to db...'); |
506 | 506 | $nbRecords = $jobDetails['data'][0]['result']['count']; |
507 | 507 | $whenToLog = ceil($nbRecords / 100); |
508 | - $this->logger->info($nbRecords . ' records to save'); |
|
508 | + $this->logger->info($nbRecords.' records to save'); |
|
509 | 509 | $nbSaved = 0; |
510 | 510 | $handle = fopen($jobCsvFile, 'r'); |
511 | 511 | $fields = []; |
@@ -523,30 +523,30 @@ discard block |
||
523 | 523 | $recordDataToInsert[$decodedColumnName] = $value === '' ? null : $value; |
524 | 524 | } else { |
525 | 525 | if ($columnName === 'Owner' || $columnName === 'Created_By' || $columnName === 'Modified_By') { |
526 | - $recordDataToInsert[$decodedColumnName . '_OwnerID'] = $value === '' ? null : $value; |
|
527 | - $recordDataToInsert[$decodedColumnName . '_OwnerName'] = $users[$value] ?? null; |
|
528 | - } else if ($table->hasColumn($decodedColumnName . '_ID')) { |
|
529 | - $recordDataToInsert[$decodedColumnName . '_ID'] = $value === '' ? null : $value; |
|
526 | + $recordDataToInsert[$decodedColumnName.'_OwnerID'] = $value === '' ? null : $value; |
|
527 | + $recordDataToInsert[$decodedColumnName.'_OwnerName'] = $users[$value] ?? null; |
|
528 | + } else if ($table->hasColumn($decodedColumnName.'_ID')) { |
|
529 | + $recordDataToInsert[$decodedColumnName.'_ID'] = $value === '' ? null : $value; |
|
530 | 530 | } |
531 | 531 | } |
532 | 532 | } |
533 | 533 | $this->connection->insert($tableName, $recordDataToInsert); |
534 | 534 | ++$nbSaved; |
535 | 535 | if (($nbSaved % $whenToLog) === 0) { |
536 | - $this->logger->info($nbSaved . '/' . $nbRecords . ' records processed'); |
|
536 | + $this->logger->info($nbSaved.'/'.$nbRecords.' records processed'); |
|
537 | 537 | } |
538 | 538 | } |
539 | - $this->logger->info($nbSaved . ' records saved for module ' . $apiModuleName . ' and page ' . $page); |
|
539 | + $this->logger->info($nbSaved.' records saved for module '.$apiModuleName.' and page '.$page); |
|
540 | 540 | fclose($handle); |
541 | 541 | } |
542 | 542 | |
543 | 543 | // Step 5: Check if there is more results |
544 | 544 | $hasMoreRecords = $jobDetails['data'][0]['result']['more_records']; |
545 | 545 | if (!$hasMoreRecords) { |
546 | - $this->logger->info('No more records for the module ' . $apiModuleName); |
|
546 | + $this->logger->info('No more records for the module '.$apiModuleName); |
|
547 | 547 | break; |
548 | 548 | } |
549 | - $this->logger->info('More records to fetch for the module ' . $apiModuleName); |
|
549 | + $this->logger->info('More records to fetch for the module '.$apiModuleName); |
|
550 | 550 | ++$page; |
551 | 551 | } |
552 | 552 | } |