@@ -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(); |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function synchronizeDbModel(AbstractZohoDao $dao, $twoWaysSync, $forceCreateTrigger = false) |
91 | 91 | { |
92 | - $tableName = ZohoDatabaseHelper::getTableName($dao,$this->prefix); |
|
92 | + $tableName = ZohoDatabaseHelper::getTableName($dao, $this->prefix); |
|
93 | 93 | $this->logger->info("Synchronizing DB Model for ".$tableName); |
94 | 94 | |
95 | 95 | $schema = new Schema(); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | private function copyData(AbstractZohoDao $dao, $incrementalSync = true, $twoWaysSync = true) |
207 | 207 | { |
208 | - $tableName = ZohoDatabaseHelper::getTableName($dao,$this->prefix); |
|
208 | + $tableName = ZohoDatabaseHelper::getTableName($dao, $this->prefix); |
|
209 | 209 | |
210 | 210 | if ($incrementalSync) { |
211 | 211 | $this->logger->info("Copying incremental data for '$tableName'"); |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $data = []; |
244 | 244 | $types = []; |
245 | 245 | foreach ($table->getColumns() as $column) { |
246 | - if (in_array($column->getName(),['id','uid'])) { |
|
246 | + if (in_array($column->getName(), ['id', 'uid'])) { |
|
247 | 247 | continue; |
248 | 248 | } |
249 | 249 | else { |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | $sqlStatementUid = 'select uid from '.$this->connection->quoteIdentifier($tableName).' where id = :id'; |
285 | 285 | foreach ($deletedRecordIds as $id) { |
286 | 286 | $uid = $this->connection->fetchColumn($sqlStatementUid, ['id' => $id]); |
287 | - $this->connection->delete($tableName, [ 'id' => $id ]); |
|
287 | + $this->connection->delete($tableName, ['id' => $id]); |
|
288 | 288 | if ($twoWaysSync) { |
289 | 289 | // TODO: we could detect if there are changes to be updated to the server and try to warn with a log message |
290 | 290 | // Also, let's remove the newly created field (because of the trigger) to avoid looping back to Zoho |
291 | - $this->connection->delete('local_delete', [ 'table_name' => $tableName, 'id' => $id ]); |
|
292 | - $this->connection->delete('local_update', [ 'table_name' => $tableName, 'uid' => $uid ]); |
|
291 | + $this->connection->delete('local_delete', ['table_name' => $tableName, 'id' => $id]); |
|
292 | + $this->connection->delete('local_update', ['table_name' => $tableName, 'uid' => $uid]); |
|
293 | 293 | } |
294 | 294 | } |
295 | 295 |
@@ -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); |
@@ -106,9 +106,9 @@ |
||
106 | 106 | foreach ($row as $columnName => $columnValue) { |
107 | 107 | if (!in_array($columnName,['id','uid']) || isset($fieldsMatching[$columnName])) { |
108 | 108 | $value = $this->formatValueToBeans($zohoDao->getModule(), $fieldsMatching, $columnName, $columnValue, null, $row['uid']); |
109 | - if($columnValue){ |
|
110 | - $zohoBean->{$fieldsMatching[$columnName]['setter']}($value); |
|
111 | - } |
|
109 | + if($columnValue){ |
|
110 | + $zohoBean->{$fieldsMatching[$columnName]['setter']}($value); |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | } |
114 | 114 | $zohoBeans[$row['uid']] = $zohoBean; |
@@ -99,7 +99,7 @@ |
||
99 | 99 | /* @var $zohoBean ZohoBeanInterface */ |
100 | 100 | if(isset($zohoBeans[$row['uid']])){ |
101 | 101 | $zohoBean = $zohoBeans[$row['uid']]; |
102 | - }else{ |
|
102 | + } else{ |
|
103 | 103 | $zohoBean = new $beanClassName(); |
104 | 104 | } |
105 | 105 | if(!$update){ |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param AbstractZohoDao $zohoDao |
55 | 55 | * @return array |
56 | 56 | */ |
57 | - private function findMethodValues(AbstractZohoDao $zohoDao){ |
|
57 | + private function findMethodValues(AbstractZohoDao $zohoDao) { |
|
58 | 58 | $fieldsMatching = array(); |
59 | 59 | foreach ($zohoDao->getFields() as $fieldsDescriptor) { |
60 | 60 | foreach (array_values($fieldsDescriptor) as $fieldDescriptor) { |
@@ -73,14 +73,14 @@ discard block |
||
73 | 73 | * @param AbstractZohoDao $zohoDao |
74 | 74 | * @param string $localTable |
75 | 75 | */ |
76 | - public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false){ |
|
76 | + public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false) { |
|
77 | 77 | |
78 | 78 | $fieldsMatching = $this->findMethodValues($zohoDao); |
79 | - $tableName = ZohoDatabaseHelper::getTableName($zohoDao,$this->prefix); |
|
79 | + $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix); |
|
80 | 80 | $rowsDeleted = []; |
81 | 81 | $statement = $this->connection->createQueryBuilder(); |
82 | 82 | $statement->select('zcrm.*'); |
83 | - if($update){ |
|
83 | + if ($update) { |
|
84 | 84 | $statement->addSelect('l.field_name as updated_fieldname'); |
85 | 85 | } |
86 | 86 | $statement->from($localTable, 'l') |
@@ -95,26 +95,26 @@ discard block |
||
95 | 95 | while ($row = $results->fetch()) { |
96 | 96 | $beanClassName = $zohoDao->getBeanClassName(); |
97 | 97 | /* @var $zohoBean ZohoBeanInterface */ |
98 | - if(isset($zohoBeans[$row['uid']])){ |
|
98 | + if (isset($zohoBeans[$row['uid']])) { |
|
99 | 99 | $zohoBean = $zohoBeans[$row['uid']]; |
100 | - }else{ |
|
100 | + } else { |
|
101 | 101 | $zohoBean = new $beanClassName(); |
102 | 102 | } |
103 | - if(!$update){ |
|
103 | + if (!$update) { |
|
104 | 104 | foreach ($row as $columnName => $columnValue) { |
105 | - if (!in_array($columnName,['id','uid']) || isset($fieldsMatching[$columnName])) { |
|
105 | + if (!in_array($columnName, ['id', 'uid']) || isset($fieldsMatching[$columnName])) { |
|
106 | 106 | $value = $this->formatValueToBeans($zohoDao->getModule(), $fieldsMatching, $columnName, $columnValue, null, $row['uid']); |
107 | - if($columnValue){ |
|
107 | + if ($columnValue) { |
|
108 | 108 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($value); |
109 | 109 | } |
110 | 110 | } |
111 | 111 | } |
112 | - $zohoBeans[$row['uid']] = $zohoBean; |
|
112 | + $zohoBeans[$row['uid']] = $zohoBean; |
|
113 | 113 | $rowsDeleted[] = $row['uid']; |
114 | - } else{ |
|
114 | + } else { |
|
115 | 115 | $columnName = $row['updated_fieldname']; |
116 | 116 | $zohoBean->setZohoId($row['id']); |
117 | - if (!in_array($columnName,['id','uid']) || isset($fieldsMatching[$columnName])) { |
|
117 | + if (!in_array($columnName, ['id', 'uid']) || isset($fieldsMatching[$columnName])) { |
|
118 | 118 | $value = $this->formatValueToBeans($zohoDao->getModule(), $fieldsMatching, $columnName, $row[$columnName], $row['id']); |
119 | 119 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($value); |
120 | 120 | $zohoBeans[$row['uid']] = $zohoBean; |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | } |
124 | 124 | } |
125 | 125 | $zohoDao->save($zohoBeans); |
126 | - if(!$update){ |
|
126 | + if (!$update) { |
|
127 | 127 | foreach ($zohoBeans as $uid => $zohoBean) { |
128 | - $this->connection->update($tableName, [ 'id'=>$zohoBean->getZohoId(),'lastActivityTime'=> date("Y-m-d H:i:s") ], ['uid'=>$uid ]); |
|
128 | + $this->connection->update($tableName, ['id'=>$zohoBean->getZohoId(), 'lastActivityTime'=> date("Y-m-d H:i:s")], ['uid'=>$uid]); |
|
129 | 129 | } |
130 | 130 | } |
131 | 131 | $statementDelete = $this->connection->prepare('delete from '.$localTable.' where uid in ( :rowsDeleted)'); |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * @return mixed |
145 | 145 | * @throws ZohoCRMException |
146 | 146 | */ |
147 | - private function formatValueToBeans($moduleName, $fieldsMatching,$columnName,$value,$id=null, $uid = null) |
|
147 | + private function formatValueToBeans($moduleName, $fieldsMatching, $columnName, $value, $id = null, $uid = null) |
|
148 | 148 | { |
149 | - $idrecord = $id?$id.'[ZOHO]':$uid.'[UID]'; |
|
150 | - if(isset($fieldsMatching[$columnName]) && $value){ |
|
149 | + $idrecord = $id ? $id.'[ZOHO]' : $uid.'[UID]'; |
|
150 | + if (isset($fieldsMatching[$columnName]) && $value) { |
|
151 | 151 | switch ($fieldsMatching[$columnName]['type']) { |
152 | 152 | case 'Date': |
153 | 153 | if ($dateObj = \DateTime::createFromFormat('M/d/Y', $value)) { |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @param AbstractZohoDao $zohoDao |
174 | 174 | * @param string $localTable |
175 | 175 | */ |
176 | - public function deleteDataToZoho(AbstractZohoDao $zohoDao, $localTable){ |
|
177 | - $tableName = ZohoDatabaseHelper::getTableName($zohoDao,$this->prefix); |
|
176 | + public function deleteDataToZoho(AbstractZohoDao $zohoDao, $localTable) { |
|
177 | + $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix); |
|
178 | 178 | $statement = $this->connection->createQueryBuilder(); |
179 | 179 | $statement->select('l.id') |
180 | 180 | ->from($localTable, 'l') |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | $results = $statement->execute(); |
186 | 186 | while ($row = $results->fetch()) { |
187 | 187 | $zohoDao->delete($row['id']); |
188 | - $this->connection->delete($localTable, ['table_name' => $tableName,'id' => $row['id']]); |
|
188 | + $this->connection->delete($localTable, ['table_name' => $tableName, 'id' => $row['id']]); |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * Run inserted rows to Zoho : local_insert. |
194 | 194 | * @param AbstractZohoDao $zohoDao |
195 | 195 | */ |
196 | - public function pushInsertedRows(AbstractZohoDao $zohoDao){ |
|
196 | + public function pushInsertedRows(AbstractZohoDao $zohoDao) { |
|
197 | 197 | return $this->pushDataToZoho($zohoDao, 'local_insert'); |
198 | 198 | } |
199 | 199 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * Run updated rows to Zoho : local_update. |
202 | 202 | * @param AbstractZohoDao $zohoDao |
203 | 203 | */ |
204 | - public function pushUpdatedRows(AbstractZohoDao $zohoDao){ |
|
204 | + public function pushUpdatedRows(AbstractZohoDao $zohoDao) { |
|
205 | 205 | $this->pushDataToZoho($zohoDao, 'local_update', true); |
206 | 206 | } |
207 | 207 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | * Run deleted rows to Zoho : local_delete. |
210 | 210 | * @param AbstractZohoDao $zohoDao |
211 | 211 | */ |
212 | - public function pushDeletedRows(AbstractZohoDao $zohoDao){ |
|
212 | + public function pushDeletedRows(AbstractZohoDao $zohoDao) { |
|
213 | 213 | $this->deleteDataToZoho($zohoDao, 'local_delete'); |
214 | 214 | } |
215 | 215 |
@@ -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 | */ |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $this |
66 | 66 | ->setName('zoho:copy-db') |
67 | 67 | ->setDescription('Copies the Zoho database in local DB tables and synchronize Zoho CRM from the Zoho database.') |
68 | - ->addArgument("action", InputArgument::REQUIRED, "Specify 'copy' or 'sync'") |
|
68 | + ->addArgument("action", InputArgument::REQUIRED, "Specify 'copy' or 'sync'") |
|
69 | 69 | ->addOption("reset", "r", InputOption::VALUE_NONE, 'Get a fresh copy of Zoho (rather than doing incremental copy)') |
70 | 70 | ->addOption("trigger", "t", InputOption::VALUE_NONE, 'Create or update the triggers'); |
71 | 71 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param InputInterface $input |
91 | 91 | * @param OutputInterface $output |
92 | 92 | */ |
93 | - private function copyDb(InputInterface $input, OutputInterface $output){ |
|
93 | + private function copyDb(InputInterface $input, OutputInterface $output) { |
|
94 | 94 | try { |
95 | 95 | if ($this->lockCopy) { |
96 | 96 | $this->lockCopy->acquireLock(); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | $forceCreateTrigger = false; |
106 | 106 | |
107 | - if($input->getOption('trigger')){ |
|
107 | + if ($input->getOption('trigger')) { |
|
108 | 108 | $forceCreateTrigger = true; |
109 | 109 | } |
110 | 110 | $twoWaysSync = true; |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * @param InputInterface $input |
130 | 130 | * @param OutputInterface $output |
131 | 131 | */ |
132 | - private function syncDb(OutputInterface $output){ |
|
132 | + private function syncDb(OutputInterface $output) { |
|
133 | 133 | try { |
134 | 134 | if ($this->lockSync) { |
135 | 135 | $this->lockSync->acquireLock(); |