@@ -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) { |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | $lastPageInConfig = '1'; |
182 | 182 | } |
183 | 183 | $lastActivityTime = new \DateTime($lastDateInConfig); |
184 | - $recordsPage = (int)$lastPageInConfig; |
|
184 | + $recordsPage = (int) $lastPageInConfig; |
|
185 | 185 | } else { |
186 | 186 | $findDateByModifiedTime = true; |
187 | 187 | } |
@@ -194,10 +194,10 @@ discard block |
||
194 | 194 | $lastActivityTime = new \DateTime($modifiedSince); |
195 | 195 | } else { |
196 | 196 | if ($tableDetail->hasColumn('modifiedTime')) { |
197 | - $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM ' . $tableName); |
|
197 | + $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM '.$tableName); |
|
198 | 198 | } |
199 | 199 | if (!$lastActivityTime && $tableDetail->hasColumn('createdTime')) { |
200 | - $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM ' . $tableName); |
|
200 | + $lastActivityTime = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM '.$tableName); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | if ($lastActivityTime !== null) { |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | if ($zohoSyncConfigTableExists) { |
225 | 225 | $lastDate = $lastActivityTime ? $lastActivityTime->format('Y-m-d H:i:s') : date('Y-m-d H:i:s', 0); |
226 | 226 | $this->upsertZohoConfig('FETCH_RECORDS_MODIFIED_SINCE__DATE', $tableName, $lastDate); |
227 | - $this->upsertZohoConfig('FETCH_RECORDS_MODIFIED_SINCE__PAGE', $tableName, (string)$recordsPage); |
|
227 | + $this->upsertZohoConfig('FETCH_RECORDS_MODIFIED_SINCE__PAGE', $tableName, (string) $recordsPage); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | $recordsPaginationLastTime = $lastActivityTime; |
@@ -234,10 +234,10 @@ discard block |
||
234 | 234 | $latestDateToSave = $currentDateTime->format('Y-m-d H:i:s'); |
235 | 235 | $tableDetail = $this->connection->getSchemaManager()->listTableDetails($tableName); |
236 | 236 | if ($tableDetail->hasColumn('modifiedTime')) { |
237 | - $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM ' . $tableName); |
|
237 | + $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM '.$tableName); |
|
238 | 238 | } |
239 | 239 | if (!$latestDateToSave && $tableDetail->hasColumn('createdTime')) { |
240 | - $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM ' . $tableName); |
|
240 | + $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM '.$tableName); |
|
241 | 241 | } |
242 | 242 | if (!$latestDateToSave) { |
243 | 243 | $latestDateToSave = $currentDateTime->format('Y-m-d H:i:s'); |
@@ -247,26 +247,26 @@ discard block |
||
247 | 247 | } |
248 | 248 | } |
249 | 249 | $totalRecords = count($records); |
250 | - $this->logger->debug($totalRecords . ' records fetched.'); |
|
250 | + $this->logger->debug($totalRecords.' records fetched.'); |
|
251 | 251 | $deletedRecords = []; |
252 | 252 | $totalRecordsDeleted = 0; |
253 | 253 | if (($recordsPage - 1) === 1) { |
254 | 254 | $this->logger->notice(sprintf('Fetching the records to delete for module %s...', $dao->getPluralModuleName())); |
255 | 255 | $deletedRecords = $dao->getDeletedRecordIds($lastActivityTime); |
256 | 256 | $totalRecordsDeleted = count($deletedRecords); |
257 | - $this->logger->debug($totalRecordsDeleted . ' records fetched.'); |
|
257 | + $this->logger->debug($totalRecordsDeleted.' records fetched.'); |
|
258 | 258 | } |
259 | 259 | } else { |
260 | 260 | $this->logger->info(sprintf('Full copy started for module %s', $dao->getPluralModuleName())); |
261 | 261 | $this->logger->notice(sprintf('Fetching the records to insert/update for module ...%s', $dao->getPluralModuleName())); |
262 | 262 | $records = $dao->getRecords(); |
263 | 263 | $totalRecords = count($records); |
264 | - $this->logger->debug($totalRecords . ' records fetched.'); |
|
264 | + $this->logger->debug($totalRecords.' records fetched.'); |
|
265 | 265 | $deletedRecords = []; |
266 | 266 | $stopAndhasMoreResults = false; |
267 | 267 | } |
268 | 268 | } catch (ZCRMException $exception) { |
269 | - $this->logger->error('Error when getting records for module ' . $dao->getPluralModuleName() . ': ' . $exception->getMessage(), [ |
|
269 | + $this->logger->error('Error when getting records for module '.$dao->getPluralModuleName().': '.$exception->getMessage(), [ |
|
270 | 270 | 'exception' => $exception |
271 | 271 | ]); |
272 | 272 | if ($throwErrors) { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | |
279 | 279 | $table = $this->connection->getSchemaManager()->createSchema()->getTable($tableName); |
280 | 280 | |
281 | - $select = $this->connection->prepare('SELECT * FROM ' . $tableName . ' WHERE id = :id'); |
|
281 | + $select = $this->connection->prepare('SELECT * FROM '.$tableName.' WHERE id = :id'); |
|
282 | 282 | |
283 | 283 | $this->connection->beginTransaction(); |
284 | 284 | |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | } |
349 | 349 | |
350 | 350 | $this->logger->info(sprintf('Deleting %d records from table %s...', $totalRecordsDeleted, $tableName)); |
351 | - $sqlStatementUid = 'select uid from ' . $this->connection->quoteIdentifier($tableName) . ' where id = :id'; |
|
351 | + $sqlStatementUid = 'select uid from '.$this->connection->quoteIdentifier($tableName).' where id = :id'; |
|
352 | 352 | $processedRecords = 0; |
353 | 353 | $logOffset = $totalRecordsDeleted >= 500 ? 100 : 50; |
354 | 354 | foreach ($deletedRecords as $deletedRecord) { |
@@ -381,10 +381,10 @@ discard block |
||
381 | 381 | $latestDateToSave = $currentDateTime->format('Y-m-d H:i:s'); |
382 | 382 | $tableDetail = $this->connection->getSchemaManager()->listTableDetails($tableName); |
383 | 383 | if ($tableDetail->hasColumn('modifiedTime')) { |
384 | - $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM ' . $tableName); |
|
384 | + $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(modifiedTime) FROM '.$tableName); |
|
385 | 385 | } |
386 | 386 | if (!$latestDateToSave && $tableDetail->hasColumn('createdTime')) { |
387 | - $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM ' . $tableName); |
|
387 | + $latestDateToSave = $this->connection->fetchColumn('SELECT MAX(createdTime) FROM '.$tableName); |
|
388 | 388 | } |
389 | 389 | if (!$latestDateToSave) { |
390 | 390 | $latestDateToSave = $currentDateTime->format('Y-m-d H:i:s'); |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | $table = $this->connection->getSchemaManager()->createSchema()->getTable($tableName); |
409 | 409 | $apiModuleName = $dao->getPluralModuleName(); |
410 | 410 | |
411 | - $this->logger->notice('Starting bulk fetch for module ' . $apiModuleName . '...'); |
|
411 | + $this->logger->notice('Starting bulk fetch for module '.$apiModuleName.'...'); |
|
412 | 412 | |
413 | 413 | $zohoClient = new ZohoClient([ |
414 | 414 | 'client_id' => ZOHO_CRM_CLIENT_ID, |
@@ -427,11 +427,11 @@ discard block |
||
427 | 427 | $oauthToken = $zohoClient->getZohoOAuthClient()->getAccessToken(ZOHO_CRM_CLIENT_CURRENT_USER_EMAIL); |
428 | 428 | |
429 | 429 | // Step 1: Create a bulk read job |
430 | - $this->logger->info('Creating read job for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
431 | - $response = $client->request('POST', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read', [ |
|
430 | + $this->logger->info('Creating read job for module '.$apiModuleName.' and page '.$page.'...'); |
|
431 | + $response = $client->request('POST', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read', [ |
|
432 | 432 | 'http_errors' => false, |
433 | 433 | 'headers' => [ |
434 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
434 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
435 | 435 | ], |
436 | 436 | 'json' => [ |
437 | 437 | 'query' => [ |
@@ -449,23 +449,23 @@ discard block |
||
449 | 449 | |
450 | 450 | // We don't care about the job status right now, it will be checked later |
451 | 451 | } else { |
452 | - $this->logger->error('Cannot create bulk read query for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
452 | + $this->logger->error('Cannot create bulk read query for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
453 | 453 | break; |
454 | 454 | } |
455 | 455 | |
456 | 456 | if ($jobId === null) { |
457 | - $this->logger->error('JobID cannot be null. json:' . $resultStr); |
|
457 | + $this->logger->error('JobID cannot be null. json:'.$resultStr); |
|
458 | 458 | break; |
459 | 459 | } |
460 | 460 | |
461 | 461 | // Step 2: Check job status |
462 | 462 | $jobDetails = null; |
463 | 463 | while (true) { |
464 | - $this->logger->info('Checking job ' . $jobId . ' status for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
465 | - $response = $client->request('GET', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read/' . $jobId, [ |
|
464 | + $this->logger->info('Checking job '.$jobId.' status for module '.$apiModuleName.' and page '.$page.'...'); |
|
465 | + $response = $client->request('GET', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read/'.$jobId, [ |
|
466 | 466 | 'http_errors' => false, |
467 | 467 | 'headers' => [ |
468 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
468 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
469 | 469 | ] |
470 | 470 | ]); |
471 | 471 | if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { |
@@ -483,15 +483,15 @@ discard block |
||
483 | 483 | $jobDetails = $json; |
484 | 484 | break; |
485 | 485 | } else { |
486 | - $this->logger->info('Unsupported job status: ' . $resultStr); |
|
486 | + $this->logger->info('Unsupported job status: '.$resultStr); |
|
487 | 487 | break; |
488 | 488 | } |
489 | 489 | } else { |
490 | - $this->logger->error('Unsupported response: ' . $resultStr); |
|
490 | + $this->logger->error('Unsupported response: '.$resultStr); |
|
491 | 491 | break; |
492 | 492 | } |
493 | 493 | } else { |
494 | - $this->logger->error('Cannot get bulk job status query for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
494 | + $this->logger->error('Cannot get bulk job status query for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
495 | 495 | break; |
496 | 496 | } |
497 | 497 | sleep(15); |
@@ -499,31 +499,31 @@ discard block |
||
499 | 499 | |
500 | 500 | // Step 3: Download the result |
501 | 501 | if ($jobDetails === null) { |
502 | - $this->logger->error('JobDetails cannot be empty. json:' . $resultStr); |
|
502 | + $this->logger->error('JobDetails cannot be empty. json:'.$resultStr); |
|
503 | 503 | break; |
504 | 504 | } |
505 | 505 | $this->logger->debug(json_encode($jobDetails)); |
506 | - $this->logger->info('Downloading zip file for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
507 | - $jobZipFile = '/tmp/job_' . $dao->getZCRMModule()->getAPIName() . '_' . $jobDetails['data'][0]['id'] . '.zip'; |
|
506 | + $this->logger->info('Downloading zip file for module '.$apiModuleName.' and page '.$page.'...'); |
|
507 | + $jobZipFile = '/tmp/job_'.$dao->getZCRMModule()->getAPIName().'_'.$jobDetails['data'][0]['id'].'.zip'; |
|
508 | 508 | $jobCsvPath = '/tmp/job_extract'; |
509 | - $jobCsvFile = '/tmp/job_extract/' . $jobDetails['data'][0]['id'] . '.csv'; |
|
509 | + $jobCsvFile = '/tmp/job_extract/'.$jobDetails['data'][0]['id'].'.csv'; |
|
510 | 510 | $canProcessCsv = false; |
511 | 511 | |
512 | - $response = $client->request('GET', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read/' . $jobId . '/result', [ |
|
512 | + $response = $client->request('GET', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read/'.$jobId.'/result', [ |
|
513 | 513 | 'http_errors' => false, |
514 | 514 | 'headers' => [ |
515 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
515 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
516 | 516 | ], |
517 | 517 | 'sink' => $jobZipFile |
518 | 518 | ]); |
519 | 519 | if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { |
520 | - $this->logger->info('Extracting ' . $jobZipFile . ' file for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
520 | + $this->logger->info('Extracting '.$jobZipFile.' file for module '.$apiModuleName.' and page '.$page.'...'); |
|
521 | 521 | $zip = new ZipArchive(); |
522 | 522 | $res = $zip->open($jobZipFile); |
523 | 523 | if ($res === TRUE) { |
524 | 524 | $zip->extractTo($jobCsvPath); |
525 | 525 | $zip->close(); |
526 | - $this->logger->info('File extracted in ' . $jobCsvFile); |
|
526 | + $this->logger->info('File extracted in '.$jobCsvFile); |
|
527 | 527 | $canProcessCsv = true; |
528 | 528 | } else { |
529 | 529 | switch ($res) { |
@@ -555,11 +555,11 @@ discard block |
||
555 | 555 | $zipErrorMessage = "Unknow (Code $res)"; |
556 | 556 | break; |
557 | 557 | } |
558 | - $this->logger->error('Error when extracting zip file: ' . $zipErrorMessage); |
|
558 | + $this->logger->error('Error when extracting zip file: '.$zipErrorMessage); |
|
559 | 559 | break; |
560 | 560 | } |
561 | 561 | } else { |
562 | - $this->logger->error('Cannot download results for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
562 | + $this->logger->error('Cannot download results for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
563 | 563 | break; |
564 | 564 | } |
565 | 565 | |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | $this->logger->info('Saving records to db...'); |
581 | 581 | $nbRecords = $jobDetails['data'][0]['result']['count']; |
582 | 582 | $whenToLog = ceil($nbRecords / 100); |
583 | - $this->logger->info($nbRecords . ' records to save'); |
|
583 | + $this->logger->info($nbRecords.' records to save'); |
|
584 | 584 | $nbSaved = 0; |
585 | 585 | $handle = fopen($jobCsvFile, 'r'); |
586 | 586 | $fields = []; |
@@ -598,30 +598,30 @@ discard block |
||
598 | 598 | $recordDataToInsert[$decodedColumnName] = $value === '' ? null : $value; |
599 | 599 | } else { |
600 | 600 | if ($columnName === 'Owner' || $columnName === 'Created_By' || $columnName === 'Modified_By') { |
601 | - $recordDataToInsert[$decodedColumnName . '_OwnerID'] = $value === '' ? null : $value; |
|
602 | - $recordDataToInsert[$decodedColumnName . '_OwnerName'] = $users[$value] ?? null; |
|
603 | - } else if ($table->hasColumn($decodedColumnName . '_ID')) { |
|
604 | - $recordDataToInsert[$decodedColumnName . '_ID'] = $value === '' ? null : $value; |
|
601 | + $recordDataToInsert[$decodedColumnName.'_OwnerID'] = $value === '' ? null : $value; |
|
602 | + $recordDataToInsert[$decodedColumnName.'_OwnerName'] = $users[$value] ?? null; |
|
603 | + } else if ($table->hasColumn($decodedColumnName.'_ID')) { |
|
604 | + $recordDataToInsert[$decodedColumnName.'_ID'] = $value === '' ? null : $value; |
|
605 | 605 | } |
606 | 606 | } |
607 | 607 | } |
608 | 608 | $this->connection->insert($tableName, $recordDataToInsert); |
609 | 609 | ++$nbSaved; |
610 | 610 | if (($nbSaved % $whenToLog) === 0) { |
611 | - $this->logger->info($nbSaved . '/' . $nbRecords . ' records processed'); |
|
611 | + $this->logger->info($nbSaved.'/'.$nbRecords.' records processed'); |
|
612 | 612 | } |
613 | 613 | } |
614 | - $this->logger->info($nbSaved . ' records saved for module ' . $apiModuleName . ' and page ' . $page); |
|
614 | + $this->logger->info($nbSaved.' records saved for module '.$apiModuleName.' and page '.$page); |
|
615 | 615 | fclose($handle); |
616 | 616 | } |
617 | 617 | |
618 | 618 | // Step 5: Check if there is more results |
619 | 619 | $hasMoreRecords = $jobDetails['data'][0]['result']['more_records']; |
620 | 620 | if (!$hasMoreRecords) { |
621 | - $this->logger->info('No more records for the module ' . $apiModuleName); |
|
621 | + $this->logger->info('No more records for the module '.$apiModuleName); |
|
622 | 622 | break; |
623 | 623 | } |
624 | - $this->logger->info('More records to fetch for the module ' . $apiModuleName); |
|
624 | + $this->logger->info('More records to fetch for the module '.$apiModuleName); |
|
625 | 625 | ++$page; |
626 | 626 | } |
627 | 627 | } |