@@ -246,8 +246,7 @@ |
||
| 246 | 246 | foreach ($table->getColumns() as $column) { |
| 247 | 247 | if (in_array($column->getName(),['id','uid'])) { |
| 248 | 248 | continue; |
| 249 | - } |
|
| 250 | - else { |
|
| 249 | + } else { |
|
| 251 | 250 | $field = $fieldsByName[$column->getName()]; |
| 252 | 251 | $getterName = $field['getter']; |
| 253 | 252 | $data[$column->getName()] = $record->$getterName(); |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | */ |
| 76 | 76 | public function fetchFromZoho(AbstractZohoDao $dao, $incrementalSync = true, $twoWaysSync = true) |
| 77 | 77 | { |
| 78 | - $tableName = ZohoDatabaseHelper::getTableName($dao,$this->prefix); |
|
| 78 | + $tableName = ZohoDatabaseHelper::getTableName($dao, $this->prefix); |
|
| 79 | 79 | |
| 80 | 80 | if ($incrementalSync) { |
| 81 | 81 | $this->logger->info("Copying incremental data for '$tableName'"); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $data = []; |
| 114 | 114 | $types = []; |
| 115 | 115 | foreach ($table->getColumns() as $column) { |
| 116 | - if (in_array($column->getName(),['id','uid'])) { |
|
| 116 | + if (in_array($column->getName(), ['id', 'uid'])) { |
|
| 117 | 117 | continue; |
| 118 | 118 | } |
| 119 | 119 | else { |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | $sqlStatementUid = 'select uid from '.$this->connection->quoteIdentifier($tableName).' where id = :id'; |
| 155 | 155 | foreach ($deletedRecordIds as $id) { |
| 156 | 156 | $uid = $this->connection->fetchColumn($sqlStatementUid, ['id' => $id]); |
| 157 | - $this->connection->delete($tableName, [ 'id' => $id ]); |
|
| 157 | + $this->connection->delete($tableName, ['id' => $id]); |
|
| 158 | 158 | if ($twoWaysSync) { |
| 159 | 159 | // TODO: we could detect if there are changes to be updated to the server and try to warn with a log message |
| 160 | 160 | // Also, let's remove the newly created field (because of the trigger) to avoid looping back to Zoho |
| 161 | - $this->connection->delete('local_delete', [ 'table_name' => $tableName, 'id' => $id ]); |
|
| 162 | - $this->connection->delete('local_update', [ 'table_name' => $tableName, 'uid' => $uid ]); |
|
| 161 | + $this->connection->delete('local_delete', ['table_name' => $tableName, 'id' => $id]); |
|
| 162 | + $this->connection->delete('local_update', ['table_name' => $tableName, 'uid' => $uid]); |
|
| 163 | 163 | } |
| 164 | 164 | } |
| 165 | 165 | |
@@ -50,9 +50,9 @@ |
||
| 50 | 50 | $localDelete = $schema->createTable("local_delete"); |
| 51 | 51 | $localDelete->addColumn("table_name", 'string', ['length' => 100]); |
| 52 | 52 | $localDelete->addColumn("uid", 'integer'); |
| 53 | - $localDelete->addColumn("id", 'string', ['length' => 100]); |
|
| 53 | + $localDelete->addColumn("id", 'string', ['length' => 100]); |
|
| 54 | 54 | $localDelete->setPrimaryKey(array("table_name", "uid")); |
| 55 | - $localDelete->addUniqueIndex(['id','table_name']); |
|
| 55 | + $localDelete->addUniqueIndex(['id', 'table_name']); |
|
| 56 | 56 | |
| 57 | 57 | $dbalTableDiffService = new DbalTableDiffService($this->connection, $this->logger); |
| 58 | 58 | $dbalTableDiffService->createOrUpdateTable($localUpdate); |
@@ -16,6 +16,7 @@ |
||
| 16 | 16 | * Computes the name of the table based on the DAO plural module name. |
| 17 | 17 | * |
| 18 | 18 | * @param AbstractZohoDao $dao |
| 19 | + * @param string $prefix |
|
| 19 | 20 | * |
| 20 | 21 | * @return string |
| 21 | 22 | */ |
@@ -106,11 +106,11 @@ |
||
| 106 | 106 | $rowsDeleted[] = $row['uid']; |
| 107 | 107 | } |
| 108 | 108 | if($update && isset($row['updated_fieldname'])){ |
| 109 | - $columnName = $row['updated_fieldname']; |
|
| 110 | - $zohoBean->getZohoId()?:$zohoBean->setZohoId($row['id']); |
|
| 111 | - $this->updateDataZohoBean($zohoBean, $fieldsMatching, $columnName, $row[$columnName]); |
|
| 112 | - $zohoBeans[$row['uid']] = $zohoBean; |
|
| 113 | - $rowsDeleted[] = $row['uid']; |
|
| 109 | + $columnName = $row['updated_fieldname']; |
|
| 110 | + $zohoBean->getZohoId()?:$zohoBean->setZohoId($row['id']); |
|
| 111 | + $this->updateDataZohoBean($zohoBean, $fieldsMatching, $columnName, $row[$columnName]); |
|
| 112 | + $zohoBeans[$row['uid']] = $zohoBean; |
|
| 113 | + $rowsDeleted[] = $row['uid']; |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | $zohoDao->save($zohoBeans); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param AbstractZohoDao $zohoDao |
| 54 | 54 | * @return array |
| 55 | 55 | */ |
| 56 | - private function findMethodValues(AbstractZohoDao $zohoDao){ |
|
| 56 | + private function findMethodValues(AbstractZohoDao $zohoDao) { |
|
| 57 | 57 | $fieldsMatching = array(); |
| 58 | 58 | foreach ($zohoDao->getFields() as $fieldsDescriptor) { |
| 59 | 59 | foreach (array_values($fieldsDescriptor) as $fieldDescriptor) { |
@@ -72,14 +72,14 @@ discard block |
||
| 72 | 72 | * @param AbstractZohoDao $zohoDao |
| 73 | 73 | * @param string $localTable |
| 74 | 74 | */ |
| 75 | - public function pushDataToZoho(AbstractZohoDao $zohoDao, $update = false){ |
|
| 75 | + public function pushDataToZoho(AbstractZohoDao $zohoDao, $update = false) { |
|
| 76 | 76 | $localTable = $update ? 'local_update' : 'local_insert'; |
| 77 | 77 | $fieldsMatching = $this->findMethodValues($zohoDao); |
| 78 | - $tableName = ZohoDatabaseHelper::getTableName($zohoDao,$this->prefix); |
|
| 78 | + $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix); |
|
| 79 | 79 | $rowsDeleted = []; |
| 80 | 80 | $statement = $this->connection->createQueryBuilder(); |
| 81 | 81 | $statement->select('zcrm.*'); |
| 82 | - if($update){ |
|
| 82 | + if ($update) { |
|
| 83 | 83 | $statement->addSelect('l.field_name as updated_fieldname'); |
| 84 | 84 | } |
| 85 | 85 | $statement->from($localTable, 'l') |
@@ -94,29 +94,29 @@ discard block |
||
| 94 | 94 | while ($row = $results->fetch()) { |
| 95 | 95 | $beanClassName = $zohoDao->getBeanClassName(); |
| 96 | 96 | /* @var $zohoBean ZohoBeanInterface */ |
| 97 | - if(isset($zohoBeans[$row['uid']])){ |
|
| 97 | + if (isset($zohoBeans[$row['uid']])) { |
|
| 98 | 98 | $zohoBean = $zohoBeans[$row['uid']]; |
| 99 | - }else{ |
|
| 99 | + } else { |
|
| 100 | 100 | $zohoBean = new $beanClassName(); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - if(!$update){ |
|
| 103 | + if (!$update) { |
|
| 104 | 104 | $this->insertDataZohoBean($zohoBean, $fieldsMatching, $row); |
| 105 | - $zohoBeans[$row['uid']] = $zohoBean; |
|
| 105 | + $zohoBeans[$row['uid']] = $zohoBean; |
|
| 106 | 106 | $rowsDeleted[] = $row['uid']; |
| 107 | 107 | } |
| 108 | - if($update && isset($row['updated_fieldname'])){ |
|
| 108 | + if ($update && isset($row['updated_fieldname'])) { |
|
| 109 | 109 | $columnName = $row['updated_fieldname']; |
| 110 | - $zohoBean->getZohoId()?:$zohoBean->setZohoId($row['id']); |
|
| 110 | + $zohoBean->getZohoId() ?: $zohoBean->setZohoId($row['id']); |
|
| 111 | 111 | $this->updateDataZohoBean($zohoBean, $fieldsMatching, $columnName, $row[$columnName]); |
| 112 | 112 | $zohoBeans[$row['uid']] = $zohoBean; |
| 113 | 113 | $rowsDeleted[] = $row['uid']; |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | $zohoDao->save($zohoBeans); |
| 117 | - if(!$update){ |
|
| 117 | + if (!$update) { |
|
| 118 | 118 | foreach ($zohoBeans as $uid => $zohoBean) { |
| 119 | - $this->connection->update($tableName, [ 'id'=>$zohoBean->getZohoId() ], ['uid'=>$uid ]); |
|
| 119 | + $this->connection->update($tableName, ['id'=>$zohoBean->getZohoId()], ['uid'=>$uid]); |
|
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | $this->connection->executeUpdate('delete from '.$localTable.' where uid in ( :rowsDeleted)', |
@@ -153,10 +153,10 @@ discard block |
||
| 153 | 153 | * @param type $columnName |
| 154 | 154 | * @param type $valueDb |
| 155 | 155 | */ |
| 156 | - private function updateDataZohoBean(ZohoBeanInterface $zohoBean, array $fieldsMatching, $columnName, $valueDb){ |
|
| 157 | - if (!in_array($columnName,['id','uid']) || (isset($fieldsMatching[$columnName]))) { |
|
| 156 | + private function updateDataZohoBean(ZohoBeanInterface $zohoBean, array $fieldsMatching, $columnName, $valueDb) { |
|
| 157 | + if (!in_array($columnName, ['id', 'uid']) || (isset($fieldsMatching[$columnName]))) { |
|
| 158 | 158 | $type = $fieldsMatching[$columnName]['type']; |
| 159 | - $value = is_null($valueDb)?$valueDb:$this->formatValueToBeans($type, $valueDb); |
|
| 159 | + $value = is_null($valueDb) ? $valueDb : $this->formatValueToBeans($type, $valueDb); |
|
| 160 | 160 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($value); |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @param mixed $value |
| 168 | 168 | * @return mixed |
| 169 | 169 | */ |
| 170 | - private function formatValueToBeans($type ,$value) |
|
| 170 | + private function formatValueToBeans($type, $value) |
|
| 171 | 171 | { |
| 172 | 172 | switch ($type) { |
| 173 | 173 | case 'Date': |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | * Run deleted rows to Zoho : local_delete. |
| 185 | 185 | * @param AbstractZohoDao $zohoDao |
| 186 | 186 | */ |
| 187 | - public function pushDeletedRows(AbstractZohoDao $zohoDao){ |
|
| 187 | + public function pushDeletedRows(AbstractZohoDao $zohoDao) { |
|
| 188 | 188 | $localTable = 'local_delete'; |
| 189 | - $tableName = ZohoDatabaseHelper::getTableName($zohoDao,$this->prefix); |
|
| 189 | + $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix); |
|
| 190 | 190 | $statement = $this->connection->createQueryBuilder(); |
| 191 | 191 | $statement->select('l.id') |
| 192 | 192 | ->from($localTable, 'l') |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | $results = $statement->execute(); |
| 198 | 198 | while ($row = $results->fetch()) { |
| 199 | 199 | $zohoDao->delete($row['id']); |
| 200 | - $this->connection->delete($localTable, ['table_name' => $tableName,'id' => $row['id']]); |
|
| 200 | + $this->connection->delete($localTable, ['table_name' => $tableName, 'id' => $row['id']]); |
|
| 201 | 201 | } |
| 202 | 202 | } |
| 203 | 203 | |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | * Run inserted rows to Zoho : local_insert. |
| 206 | 206 | * @param AbstractZohoDao $zohoDao |
| 207 | 207 | */ |
| 208 | - public function pushInsertedRows(AbstractZohoDao $zohoDao){ |
|
| 208 | + public function pushInsertedRows(AbstractZohoDao $zohoDao) { |
|
| 209 | 209 | return $this->pushDataToZoho($zohoDao); |
| 210 | 210 | } |
| 211 | 211 | |
@@ -213,8 +213,8 @@ discard block |
||
| 213 | 213 | * Run updated rows to Zoho : local_update. |
| 214 | 214 | * @param AbstractZohoDao $zohoDao |
| 215 | 215 | */ |
| 216 | - public function pushUpdatedRows(AbstractZohoDao $zohoDao){ |
|
| 217 | - $this->pushDataToZoho($zohoDao,true); |
|
| 216 | + public function pushUpdatedRows(AbstractZohoDao $zohoDao) { |
|
| 217 | + $this->pushDataToZoho($zohoDao, true); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | /* @var $zohoBean ZohoBeanInterface */ |
| 97 | 97 | if(isset($zohoBeans[$row['uid']])){ |
| 98 | 98 | $zohoBean = $zohoBeans[$row['uid']]; |
| 99 | - }else{ |
|
| 99 | + } else{ |
|
| 100 | 100 | $zohoBean = new $beanClassName(); |
| 101 | 101 | } |
| 102 | 102 | |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | $this->localChangesTracker->createTrackingTables(); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $tableName = ZohoDatabaseHelper::getTableName($dao,$this->prefix); |
|
| 75 | + $tableName = ZohoDatabaseHelper::getTableName($dao, $this->prefix); |
|
| 76 | 76 | $this->logger->info("Synchronizing DB Model for ".$tableName); |
| 77 | 77 | |
| 78 | 78 | $schema = new Schema(); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * Sychronizes the model of the database with Zoho records. |
| 103 | 103 | * @param OutputInterface $output |
| 104 | 104 | */ |
| 105 | - private function syncModel(InputInterface $input, OutputInterface $output){ |
|
| 105 | + private function syncModel(InputInterface $input, OutputInterface $output) { |
|
| 106 | 106 | $this->zohoDatabaseModelSync->setLogger(new ConsoleLogger($output)); |
| 107 | 107 | |
| 108 | 108 | $twoWaysSync = !$input->getOption('fetch-only'); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | * @param InputInterface $input |
| 121 | 121 | * @param OutputInterface $output |
| 122 | 122 | */ |
| 123 | - private function fetchDb(InputInterface $input, OutputInterface $output){ |
|
| 123 | + private function fetchDb(InputInterface $input, OutputInterface $output) { |
|
| 124 | 124 | |
| 125 | 125 | if ($input->getOption('reset')) { |
| 126 | 126 | $incremental = false; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * Run the push Db command. |
| 144 | 144 | * @param OutputInterface $output |
| 145 | 145 | */ |
| 146 | - private function pushDb(OutputInterface $output){ |
|
| 146 | + private function pushDb(OutputInterface $output) { |
|
| 147 | 147 | $this->zohoDatabaseSync->setLogger(new ConsoleLogger($output)); |
| 148 | 148 | |
| 149 | 149 | $output->writeln('Starting synchronize Zoho data into Zoho CRM.'); |