@@ -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) { |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | $table = $this->connection->getSchemaManager()->createSchema()->getTable($tableName); |
| 398 | 398 | $apiModuleName = $dao->getPluralModuleName(); |
| 399 | 399 | |
| 400 | - $this->logger->notice('Starting bulk fetch for module ' . $apiModuleName . '...'); |
|
| 400 | + $this->logger->notice('Starting bulk fetch for module '.$apiModuleName.'...'); |
|
| 401 | 401 | |
| 402 | 402 | $zohoClient = new ZohoClient([ |
| 403 | 403 | 'client_id' => ZOHO_CRM_CLIENT_ID, |
@@ -416,11 +416,11 @@ discard block |
||
| 416 | 416 | $oauthToken = $zohoClient->getZohoOAuthClient()->getAccessToken(ZOHO_CRM_CLIENT_CURRENT_USER_EMAIL); |
| 417 | 417 | |
| 418 | 418 | // Step 1: Create a bulk read job |
| 419 | - $this->logger->info('Creating read job for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
| 420 | - $response = $client->request('POST', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read', [ |
|
| 419 | + $this->logger->info('Creating read job for module '.$apiModuleName.' and page '.$page.'...'); |
|
| 420 | + $response = $client->request('POST', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read', [ |
|
| 421 | 421 | 'http_errors' => false, |
| 422 | 422 | 'headers' => [ |
| 423 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
| 423 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
| 424 | 424 | ], |
| 425 | 425 | 'json' => [ |
| 426 | 426 | 'query' => [ |
@@ -438,23 +438,23 @@ discard block |
||
| 438 | 438 | |
| 439 | 439 | // We don't care about the job status right now, it will be checked later |
| 440 | 440 | } else { |
| 441 | - $this->logger->error('Cannot create bulk read query for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
| 441 | + $this->logger->error('Cannot create bulk read query for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
| 442 | 442 | break; |
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | if ($jobId === null) { |
| 446 | - $this->logger->error('JobID cannot be null. json:' . $resultStr); |
|
| 446 | + $this->logger->error('JobID cannot be null. json:'.$resultStr); |
|
| 447 | 447 | break; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Step 2: Check job status |
| 451 | 451 | $jobDetails = null; |
| 452 | 452 | while (true) { |
| 453 | - $this->logger->info('Checking job ' . $jobId . ' status for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
| 454 | - $response = $client->request('GET', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read/' . $jobId, [ |
|
| 453 | + $this->logger->info('Checking job '.$jobId.' status for module '.$apiModuleName.' and page '.$page.'...'); |
|
| 454 | + $response = $client->request('GET', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read/'.$jobId, [ |
|
| 455 | 455 | 'http_errors' => false, |
| 456 | 456 | 'headers' => [ |
| 457 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
| 457 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
| 458 | 458 | ] |
| 459 | 459 | ]); |
| 460 | 460 | if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { |
@@ -472,15 +472,15 @@ discard block |
||
| 472 | 472 | $jobDetails = $json; |
| 473 | 473 | break; |
| 474 | 474 | } else { |
| 475 | - $this->logger->info('Unsupported job status: ' . $resultStr); |
|
| 475 | + $this->logger->info('Unsupported job status: '.$resultStr); |
|
| 476 | 476 | break; |
| 477 | 477 | } |
| 478 | 478 | } else { |
| 479 | - $this->logger->error('Unsupported response: ' . $resultStr); |
|
| 479 | + $this->logger->error('Unsupported response: '.$resultStr); |
|
| 480 | 480 | break; |
| 481 | 481 | } |
| 482 | 482 | } else { |
| 483 | - $this->logger->error('Cannot get bulk job status query for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
| 483 | + $this->logger->error('Cannot get bulk job status query for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
| 484 | 484 | break; |
| 485 | 485 | } |
| 486 | 486 | sleep(15); |
@@ -488,31 +488,31 @@ discard block |
||
| 488 | 488 | |
| 489 | 489 | // Step 3: Download the result |
| 490 | 490 | if ($jobDetails === null) { |
| 491 | - $this->logger->error('JobDetails cannot be empty. json:' . $resultStr); |
|
| 491 | + $this->logger->error('JobDetails cannot be empty. json:'.$resultStr); |
|
| 492 | 492 | break; |
| 493 | 493 | } |
| 494 | 494 | $this->logger->debug(json_encode($jobDetails)); |
| 495 | - $this->logger->info('Downloading zip file for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
| 496 | - $jobZipFile = '/tmp/job_' . $dao->getZCRMModule()->getAPIName() . '_' . $jobDetails['data'][0]['id'] . '.zip'; |
|
| 495 | + $this->logger->info('Downloading zip file for module '.$apiModuleName.' and page '.$page.'...'); |
|
| 496 | + $jobZipFile = '/tmp/job_'.$dao->getZCRMModule()->getAPIName().'_'.$jobDetails['data'][0]['id'].'.zip'; |
|
| 497 | 497 | $jobCsvPath = '/tmp/job_extract'; |
| 498 | - $jobCsvFile = '/tmp/job_extract/' . $jobDetails['data'][0]['id'] . '.csv'; |
|
| 498 | + $jobCsvFile = '/tmp/job_extract/'.$jobDetails['data'][0]['id'].'.csv'; |
|
| 499 | 499 | $canProcessCsv = false; |
| 500 | 500 | |
| 501 | - $response = $client->request('GET', 'https://' . (ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www') . '.zohoapis.com/crm/bulk/v2/read/' . $jobId . '/result', [ |
|
| 501 | + $response = $client->request('GET', 'https://'.(ZOHO_CRM_SANDBOX === 'true' ? 'sandbox' : 'www').'.zohoapis.com/crm/bulk/v2/read/'.$jobId.'/result', [ |
|
| 502 | 502 | 'http_errors' => false, |
| 503 | 503 | 'headers' => [ |
| 504 | - 'Authorization' => 'Zoho-oauthtoken ' . $oauthToken |
|
| 504 | + 'Authorization' => 'Zoho-oauthtoken '.$oauthToken |
|
| 505 | 505 | ], |
| 506 | 506 | 'sink' => $jobZipFile |
| 507 | 507 | ]); |
| 508 | 508 | if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) { |
| 509 | - $this->logger->info('Extracting ' . $jobZipFile . ' file for module ' . $apiModuleName . ' and page ' . $page . '...'); |
|
| 509 | + $this->logger->info('Extracting '.$jobZipFile.' file for module '.$apiModuleName.' and page '.$page.'...'); |
|
| 510 | 510 | $zip = new ZipArchive(); |
| 511 | 511 | $res = $zip->open($jobZipFile); |
| 512 | 512 | if ($res === TRUE) { |
| 513 | 513 | $zip->extractTo($jobCsvPath); |
| 514 | 514 | $zip->close(); |
| 515 | - $this->logger->info('File extracted in ' . $jobCsvFile); |
|
| 515 | + $this->logger->info('File extracted in '.$jobCsvFile); |
|
| 516 | 516 | $canProcessCsv = true; |
| 517 | 517 | } else { |
| 518 | 518 | switch ($res) { |
@@ -544,11 +544,11 @@ discard block |
||
| 544 | 544 | $zipErrorMessage = "Unknow (Code $res)"; |
| 545 | 545 | break; |
| 546 | 546 | } |
| 547 | - $this->logger->error('Error when extracting zip file: ' . $zipErrorMessage); |
|
| 547 | + $this->logger->error('Error when extracting zip file: '.$zipErrorMessage); |
|
| 548 | 548 | break; |
| 549 | 549 | } |
| 550 | 550 | } else { |
| 551 | - $this->logger->error('Cannot download results for module ' . $apiModuleName . ': status: ' . $response->getStatusCode() . '. Status: ' . $response->getBody()->getContents()); |
|
| 551 | + $this->logger->error('Cannot download results for module '.$apiModuleName.': status: '.$response->getStatusCode().'. Status: '.$response->getBody()->getContents()); |
|
| 552 | 552 | break; |
| 553 | 553 | } |
| 554 | 554 | |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | $this->logger->info('Saving records to db...'); |
| 570 | 570 | $nbRecords = $jobDetails['data'][0]['result']['count']; |
| 571 | 571 | $whenToLog = ceil($nbRecords / 100); |
| 572 | - $this->logger->info($nbRecords . ' records to save'); |
|
| 572 | + $this->logger->info($nbRecords.' records to save'); |
|
| 573 | 573 | $nbSaved = 0; |
| 574 | 574 | $handle = fopen($jobCsvFile, 'r'); |
| 575 | 575 | $fields = []; |
@@ -587,30 +587,30 @@ discard block |
||
| 587 | 587 | $recordDataToInsert[$decodedColumnName] = $value === '' ? null : $value; |
| 588 | 588 | } else { |
| 589 | 589 | if ($columnName === 'Owner' || $columnName === 'Created_By' || $columnName === 'Modified_By') { |
| 590 | - $recordDataToInsert[$decodedColumnName . '_OwnerID'] = $value === '' ? null : $value; |
|
| 591 | - $recordDataToInsert[$decodedColumnName . '_OwnerName'] = $users[$value] ?? null; |
|
| 592 | - } else if ($table->hasColumn($decodedColumnName . '_ID')) { |
|
| 593 | - $recordDataToInsert[$decodedColumnName . '_ID'] = $value === '' ? null : $value; |
|
| 590 | + $recordDataToInsert[$decodedColumnName.'_OwnerID'] = $value === '' ? null : $value; |
|
| 591 | + $recordDataToInsert[$decodedColumnName.'_OwnerName'] = $users[$value] ?? null; |
|
| 592 | + } else if ($table->hasColumn($decodedColumnName.'_ID')) { |
|
| 593 | + $recordDataToInsert[$decodedColumnName.'_ID'] = $value === '' ? null : $value; |
|
| 594 | 594 | } |
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | 597 | $this->connection->insert($tableName, $recordDataToInsert); |
| 598 | 598 | ++$nbSaved; |
| 599 | 599 | if (($nbSaved % $whenToLog) === 0) { |
| 600 | - $this->logger->info($nbSaved . '/' . $nbRecords . ' records processed'); |
|
| 600 | + $this->logger->info($nbSaved.'/'.$nbRecords.' records processed'); |
|
| 601 | 601 | } |
| 602 | 602 | } |
| 603 | - $this->logger->info($nbSaved . ' records saved for module ' . $apiModuleName . ' and page ' . $page); |
|
| 603 | + $this->logger->info($nbSaved.' records saved for module '.$apiModuleName.' and page '.$page); |
|
| 604 | 604 | fclose($handle); |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | // Step 5: Check if there is more results |
| 608 | 608 | $hasMoreRecords = $jobDetails['data'][0]['result']['more_records']; |
| 609 | 609 | if (!$hasMoreRecords) { |
| 610 | - $this->logger->info('No more records for the module ' . $apiModuleName); |
|
| 610 | + $this->logger->info('No more records for the module '.$apiModuleName); |
|
| 611 | 611 | break; |
| 612 | 612 | } |
| 613 | - $this->logger->info('More records to fetch for the module ' . $apiModuleName); |
|
| 613 | + $this->logger->info('More records to fetch for the module '.$apiModuleName); |
|
| 614 | 614 | ++$page; |
| 615 | 615 | } |
| 616 | 616 | } |