@@ -45,7 +45,6 @@ |
||
45 | 45 | /** |
46 | 46 | * @param ZohoDatabaseCopier $zohoDatabaseCopier |
47 | 47 | * @param \Wabel\Zoho\CRM\AbstractZohoDao[] $zohoDaos The list of Zoho DAOs to copy |
48 | - * @param Lock $lock A lock that can be used to avoid running the same command twice at the same time |
|
49 | 48 | */ |
50 | 49 | public function __construct(ZohoDatabaseCopier $zohoDatabaseCopier, ZohoDatabaseSyncZoho $zohoDatabaseSync, array $zohoDaos, Lock $lockCopy = null, Lock $lockSync = null) |
51 | 50 | { |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $this |
63 | 63 | ->setName('zoho:copy-db') |
64 | 64 | ->setDescription('Copies the Zoho database in local DB tables and synchronize Zoho CRM from the Zoho database.') |
65 | - ->addArgument("action", InputArgument::REQUIRED, "Specify 'copy' or 'sync'") |
|
65 | + ->addArgument("action", InputArgument::REQUIRED, "Specify 'copy' or 'sync'") |
|
66 | 66 | ->addOption("reset", "r", InputOption::VALUE_NONE, 'Get a fresh copy of Zoho (rather than doing incremental copy)') |
67 | 67 | ->addOption("trigger", "t", InputOption::VALUE_NONE, 'Create or update the triggers'); |
68 | 68 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @param InputInterface $input |
89 | 89 | * @param OutputInterface $output |
90 | 90 | */ |
91 | - private function copyDb(InputInterface $input, OutputInterface $output){ |
|
91 | + private function copyDb(InputInterface $input, OutputInterface $output) { |
|
92 | 92 | try { |
93 | 93 | if ($this->lockCopy) { |
94 | 94 | $this->lockCopy->acquireLock(); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | $forceCreateTrigger = false; |
104 | 104 | |
105 | - if($input->getOption('trigger')){ |
|
105 | + if ($input->getOption('trigger')) { |
|
106 | 106 | $forceCreateTrigger = true; |
107 | 107 | } |
108 | 108 | $twoWaysSync = true; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param InputInterface $input |
128 | 128 | * @param OutputInterface $output |
129 | 129 | */ |
130 | - private function syncDb(InputInterface $input, OutputInterface $output){ |
|
130 | + private function syncDb(InputInterface $input, OutputInterface $output) { |
|
131 | 131 | try { |
132 | 132 | if ($this->lockSync) { |
133 | 133 | $this->lockSync->acquireLock(); |
@@ -30,7 +30,6 @@ |
||
30 | 30 | private $logger; |
31 | 31 | |
32 | 32 | /** |
33 | - * @param \Wabel\Zoho\CRM\AbstractZohoDao[] $zohoDaos The list of Zoho DAOs to copy |
|
34 | 33 | * @param Connection $connection |
35 | 34 | * |
36 | 35 | */ |
@@ -7,8 +7,6 @@ |
||
7 | 7 | use Psr\Log\NullLogger; |
8 | 8 | use Wabel\Zoho\CRM\AbstractZohoDao; |
9 | 9 | use Wabel\Zoho\CRM\ZohoBeanInterface; |
10 | -use Wabel\Zoho\CRM\Exception\ZohoCRMException; |
|
11 | -use Wabel\Zoho\CRM\Exception\ZohoCRMResponseException; |
|
12 | 10 | use function Stringy\create as s; |
13 | 11 | |
14 | 12 | /** |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * |
|
50 | - * @param AbstractZohoDao $zohoDao |
|
51 | - * @return array |
|
52 | - */ |
|
49 | + * |
|
50 | + * @param AbstractZohoDao $zohoDao |
|
51 | + * @return array |
|
52 | + */ |
|
53 | 53 | private function findMethodValues(AbstractZohoDao $zohoDao){ |
54 | 54 | $fieldsMatching = array(); |
55 | 55 | foreach ($zohoDao->getFields() as $fieldsDescriptor) { |
@@ -96,9 +96,9 @@ discard block |
||
96 | 96 | if (in_array($columnName,['id','uid'])) { |
97 | 97 | continue; |
98 | 98 | }else{ |
99 | - if($columnValue){ |
|
100 | - $zohoBean->{$fieldsMatching[$columnName]['setter']}($columnValue); |
|
101 | - } |
|
99 | + if($columnValue){ |
|
100 | + $zohoBean->{$fieldsMatching[$columnName]['setter']}($columnValue); |
|
101 | + } |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param AbstractZohoDao $zohoDao |
51 | 51 | * @return array |
52 | 52 | */ |
53 | - private function findMethodValues(AbstractZohoDao $zohoDao){ |
|
53 | + private function findMethodValues(AbstractZohoDao $zohoDao) { |
|
54 | 54 | $fieldsMatching = array(); |
55 | 55 | foreach ($zohoDao->getFields() as $fieldsDescriptor) { |
56 | 56 | foreach (array_values($fieldsDescriptor) as $fieldDescriptor) { |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | * @param AbstractZohoDao $zohoDao |
69 | 69 | * @param string $localTable |
70 | 70 | */ |
71 | - public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false){ |
|
71 | + public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false) { |
|
72 | 72 | |
73 | 73 | $fieldsMatching = $this->findMethodValues($zohoDao); |
74 | 74 | $tableName = $this->getTableName($zohoDao); |
75 | 75 | $rowsDeleted = []; |
76 | 76 | $statement = $this->connection->createQueryBuilder(); |
77 | 77 | $statement->select('zcrm.*'); |
78 | - if($update){ |
|
78 | + if ($update) { |
|
79 | 79 | $statement->addSelect('l.field_name as updated_fieldname'); |
80 | 80 | } |
81 | 81 | $statement->from($localTable, 'l') |
@@ -91,25 +91,25 @@ discard block |
||
91 | 91 | $beanClassName = $zohoDao->getBeanClassName(); |
92 | 92 | /* @var $zohoBean ZohoBeanInterface */ |
93 | 93 | $zohoBean = new $beanClassName(); |
94 | - if(!$update){ |
|
94 | + if (!$update) { |
|
95 | 95 | foreach ($row as $columnName => $columnValue) { |
96 | - if (in_array($columnName,['id','uid'])) { |
|
96 | + if (in_array($columnName, ['id', 'uid'])) { |
|
97 | 97 | continue; |
98 | - }else{ |
|
99 | - if($columnValue){ |
|
98 | + } else { |
|
99 | + if ($columnValue) { |
|
100 | 100 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($columnValue); |
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
104 | 104 | } |
105 | - $zohoBeans[$row['uid']] = $zohoBean; |
|
105 | + $zohoBeans[$row['uid']] = $zohoBean; |
|
106 | 106 | $rowsDeleted[] = $row['uid']; |
107 | - } else{ |
|
107 | + } else { |
|
108 | 108 | $columnName = $row['updated_fieldname']; |
109 | 109 | $zohoBean->setZohoId($row['id']); |
110 | - if (in_array($columnName,['uid'])) { |
|
110 | + if (in_array($columnName, ['uid'])) { |
|
111 | 111 | continue; |
112 | - }else{ |
|
112 | + } else { |
|
113 | 113 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($row[$columnName]); |
114 | 114 | $zohoBeans[] = $zohoBean; |
115 | 115 | $rowsDeleted[] = $row['uid']; |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | } |
118 | 118 | } |
119 | 119 | $zohoDao->save($zohoBeans); |
120 | - if(!$update){ |
|
120 | + if (!$update) { |
|
121 | 121 | foreach ($zohoBeans as $uid => $zohoBean) { |
122 | - $this->connection->update($tableName, [ 'id'=>$zohoBean->getZohoId(),'lastActivityTime'=> date("Y-m-d H:i:s") ], ['uid'=>$uid ]); |
|
122 | + $this->connection->update($tableName, ['id'=>$zohoBean->getZohoId(), 'lastActivityTime'=> date("Y-m-d H:i:s")], ['uid'=>$uid]); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | $statementDelete = $this->connection->prepare('delete from '.$localTable.' where uid in ( :rowsDeleted)'); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @param AbstractZohoDao $zohoDao |
134 | 134 | * @param string $localTable |
135 | 135 | */ |
136 | - public function deleteDataToZoho(AbstractZohoDao $zohoDao, $localTable){ |
|
136 | + public function deleteDataToZoho(AbstractZohoDao $zohoDao, $localTable) { |
|
137 | 137 | $tableName = $this->getTableName($zohoDao); |
138 | 138 | $statement = $this->connection->createQueryBuilder(); |
139 | 139 | $statement->select('l.id') |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | $results = $statement->execute(); |
146 | 146 | while ($row = $results->fetch()) { |
147 | 147 | $zohoDao->delete($row['id']); |
148 | - $this->connection->delete($localTable, ['table_name' => $tableName,'id' => $row['id']]); |
|
148 | + $this->connection->delete($localTable, ['table_name' => $tableName, 'id' => $row['id']]); |
|
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * Run inserted rows to Zoho : local_insert. |
154 | 154 | * @param AbstractZohoDao $zohoDao |
155 | 155 | */ |
156 | - public function pushInsertedRows(AbstractZohoDao $zohoDao){ |
|
156 | + public function pushInsertedRows(AbstractZohoDao $zohoDao) { |
|
157 | 157 | return $this->pushDataToZoho($zohoDao, 'local_insert'); |
158 | 158 | } |
159 | 159 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * Run updated rows to Zoho : local_update. |
162 | 162 | * @param AbstractZohoDao $zohoDao |
163 | 163 | */ |
164 | - public function pushUpdatedRows(AbstractZohoDao $zohoDao){ |
|
164 | + public function pushUpdatedRows(AbstractZohoDao $zohoDao) { |
|
165 | 165 | $this->pushDataToZoho($zohoDao, 'local_update', true); |
166 | 166 | } |
167 | 167 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * Run deleted rows to Zoho : local_delete. |
170 | 170 | * @param AbstractZohoDao $zohoDao |
171 | 171 | */ |
172 | - public function pushDeletedRows(AbstractZohoDao $zohoDao){ |
|
172 | + public function pushDeletedRows(AbstractZohoDao $zohoDao) { |
|
173 | 173 | $this->deleteDataToZoho($zohoDao, 'local_delete'); |
174 | 174 | } |
175 | 175 |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | foreach ($row as $columnName => $columnValue) { |
96 | 96 | if (in_array($columnName,['id','uid'])) { |
97 | 97 | continue; |
98 | - }else{ |
|
98 | + } else{ |
|
99 | 99 | if($columnValue){ |
100 | 100 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($columnValue); |
101 | 101 | } |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | $zohoBean->setZohoId($row['id']); |
110 | 110 | if (in_array($columnName,['uid'])) { |
111 | 111 | continue; |
112 | - }else{ |
|
112 | + } else{ |
|
113 | 113 | $zohoBean->{$fieldsMatching[$columnName]['setter']}($row[$columnName]); |
114 | 114 | $zohoBeans[] = $zohoBean; |
115 | 115 | $rowsDeleted[] = $row['uid']; |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | $data = []; |
245 | 245 | $types = []; |
246 | 246 | foreach ($table->getColumns() as $column) { |
247 | - if (in_array($column->getName(),['id','uid'])) { |
|
247 | + if (in_array($column->getName(), ['id', 'uid'])) { |
|
248 | 248 | continue; |
249 | 249 | } |
250 | 250 | else { |
@@ -285,12 +285,12 @@ discard block |
||
285 | 285 | $sqlStatementUid = 'select uid from '.$this->connection->quoteIdentifier($tableName).' where id = :id'; |
286 | 286 | foreach ($deletedRecordIds as $id) { |
287 | 287 | $uid = $this->connection->fetchColumn($sqlStatementUid, ['id' => $id]); |
288 | - $this->connection->delete($tableName, [ 'id' => $id ]); |
|
288 | + $this->connection->delete($tableName, ['id' => $id]); |
|
289 | 289 | if ($twoWaysSync) { |
290 | 290 | // TODO: we could detect if there are changes to be updated to the server and try to warn with a log message |
291 | 291 | // Also, let's remove the newly created field (because of the trigger) to avoid looping back to Zoho |
292 | - $this->connection->delete('local_delete', [ 'table_name' => $tableName, 'id' => $id ]); |
|
293 | - $this->connection->delete('local_update', [ 'table_name' => $tableName, 'uid' => $uid ]); |
|
292 | + $this->connection->delete('local_delete', ['table_name' => $tableName, 'id' => $id]); |
|
293 | + $this->connection->delete('local_update', ['table_name' => $tableName, 'uid' => $uid]); |
|
294 | 294 | } |
295 | 295 | } |
296 | 296 |
@@ -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(); |
@@ -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); |