Completed
Pull Request — 1.1 (#3)
by Raphaël
02:37
created
src/ZohoCopyDatabaseCommand.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,6 @@
 block discarded – undo
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
     {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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();
Please login to merge, or discard this patch.
src/ZohoDatabaseCopier.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -246,8 +246,7 @@
 block discarded – undo
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();
Please login to merge, or discard this patch.
src/LocalChangesTracker.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,9 +50,9 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
src/ZohoDatabaseSyncZoho.php 4 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,6 @@
 block discarded – undo
8 8
 use Wabel\Zoho\CRM\AbstractZohoDao;
9 9
 use Wabel\Zoho\CRM\ZohoBeanInterface;
10 10
 use Wabel\Zoho\CRM\Exception\ZohoCRMException;
11
-use Wabel\Zoho\CRM\Exception\ZohoCRMResponseException;
12 11
 use function Stringy\create as s;
13 12
 
14 13
 /**
Please login to merge, or discard this patch.
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -106,9 +106,9 @@
 block discarded – undo
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;
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
      * @param AbstractZohoDao $zohoDao
57 57
      * @return array
58 58
      */
59
-    private function findMethodValues(AbstractZohoDao $zohoDao){
59
+    private function findMethodValues(AbstractZohoDao $zohoDao) {
60 60
         $fieldsMatching = array();
61 61
         foreach ($zohoDao->getFields() as $fieldsDescriptor) {
62 62
             foreach (array_values($fieldsDescriptor) as $fieldDescriptor) {
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
      * @param AbstractZohoDao $zohoDao
76 76
      * @param string $localTable
77 77
      */
78
-    public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false){
78
+    public function pushDataToZoho(AbstractZohoDao $zohoDao, $localTable, $update = false) {
79 79
 
80 80
             $fieldsMatching = $this->findMethodValues($zohoDao);
81 81
             $tableName = $this->getTableName($zohoDao);
82 82
             $rowsDeleted = [];
83 83
             $statement = $this->connection->createQueryBuilder();
84 84
             $statement->select('zcrm.*');
85
-            if($update){
85
+            if ($update) {
86 86
                 $statement->addSelect('l.field_name as updated_fieldname');
87 87
             }
88 88
             $statement->from($localTable, 'l')
@@ -97,26 +97,26 @@  discard block
 block discarded – undo
97 97
             while ($row = $results->fetch()) {
98 98
                 $beanClassName = $zohoDao->getBeanClassName();
99 99
                 /* @var $zohoBean ZohoBeanInterface */
100
-                if(isset($zohoBeans[$row['uid']])){
100
+                if (isset($zohoBeans[$row['uid']])) {
101 101
                     $zohoBean = $zohoBeans[$row['uid']];
102
-                }else{
102
+                } else {
103 103
                     $zohoBean = new $beanClassName();
104 104
                 }
105
-                if(!$update){
105
+                if (!$update) {
106 106
                     foreach ($row as $columnName => $columnValue) {
107
-                        if (!in_array($columnName,['id','uid']) || isset($fieldsMatching[$columnName])) {
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){
109
+                           if ($columnValue) {
110 110
                                $zohoBean->{$fieldsMatching[$columnName]['setter']}($value);
111 111
                            }
112 112
                         }
113 113
                     }
114
-                    $zohoBeans[$row['uid']] =  $zohoBean;
114
+                    $zohoBeans[$row['uid']] = $zohoBean;
115 115
                     $rowsDeleted[] = $row['uid'];
116
-                } else{
116
+                } else {
117 117
                     $columnName = $row['updated_fieldname'];
118 118
                     $zohoBean->setZohoId($row['id']);
119
-                    if (!in_array($columnName,['id','uid']) || isset($fieldsMatching[$columnName])) {
119
+                    if (!in_array($columnName, ['id', 'uid']) || isset($fieldsMatching[$columnName])) {
120 120
                         $value = $this->formatValueToBeans($zohoDao->getModule(), $fieldsMatching, $columnName, $row[$columnName], $row['id']);
121 121
                         $zohoBean->{$fieldsMatching[$columnName]['setter']}($value);
122 122
                         $zohoBeans[$row['uid']] = $zohoBean;
@@ -125,9 +125,9 @@  discard block
 block discarded – undo
125 125
                 }
126 126
             }
127 127
             $zohoDao->save($zohoBeans);
128
-            if(!$update){
128
+            if (!$update) {
129 129
                 foreach ($zohoBeans as $uid => $zohoBean) {
130
-                    $this->connection->update($tableName, [ 'id'=>$zohoBean->getZohoId(),'lastActivityTime'=> date("Y-m-d H:i:s") ], ['uid'=>$uid ]);
130
+                    $this->connection->update($tableName, ['id'=>$zohoBean->getZohoId(), 'lastActivityTime'=> date("Y-m-d H:i:s")], ['uid'=>$uid]);
131 131
                 }
132 132
             }
133 133
             $statementDelete = $this->connection->prepare('delete from '.$localTable.' where uid in ( :rowsDeleted)');
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
      * @return mixed
147 147
      * @throws ZohoCRMException
148 148
      */
149
-    private function formatValueToBeans($moduleName, $fieldsMatching,$columnName,$value,$id=null, $uid = null)
149
+    private function formatValueToBeans($moduleName, $fieldsMatching, $columnName, $value, $id = null, $uid = null)
150 150
     {
151
-        $idrecord = $id?$id.'[ZOHO]':$uid.'[UID]';
152
-        if(isset($fieldsMatching[$columnName]) && $value){
151
+        $idrecord = $id ? $id.'[ZOHO]' : $uid.'[UID]';
152
+        if (isset($fieldsMatching[$columnName]) && $value) {
153 153
             switch ($fieldsMatching[$columnName]['type']) {
154 154
                 case 'Date':
155 155
                     if ($dateObj = \DateTime::createFromFormat('M/d/Y', $value)) {
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      * @param AbstractZohoDao $zohoDao
176 176
      * @param string $localTable
177 177
      */
178
-    public function deleteDataToZoho(AbstractZohoDao $zohoDao, $localTable){
178
+    public function deleteDataToZoho(AbstractZohoDao $zohoDao, $localTable) {
179 179
         $tableName = $this->getTableName($zohoDao);
180 180
         $statement = $this->connection->createQueryBuilder();
181 181
         $statement->select('l.id')
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
         $results = $statement->execute();
188 188
         while ($row = $results->fetch()) {
189 189
             $zohoDao->delete($row['id']);
190
-            $this->connection->delete($localTable, ['table_name' => $tableName,'id' => $row['id']]);
190
+            $this->connection->delete($localTable, ['table_name' => $tableName, 'id' => $row['id']]);
191 191
         }
192 192
 }
193 193
     
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
      * Run inserted rows to Zoho : local_insert.
196 196
      * @param AbstractZohoDao $zohoDao
197 197
      */
198
-    public function pushInsertedRows(AbstractZohoDao $zohoDao){
198
+    public function pushInsertedRows(AbstractZohoDao $zohoDao) {
199 199
         return $this->pushDataToZoho($zohoDao, 'local_insert');
200 200
     }
201 201
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      * Run updated rows to Zoho : local_update.
204 204
      * @param AbstractZohoDao $zohoDao
205 205
      */
206
-    public function pushUpdatedRows(AbstractZohoDao $zohoDao){
206
+    public function pushUpdatedRows(AbstractZohoDao $zohoDao) {
207 207
         $this->pushDataToZoho($zohoDao, 'local_update', true);
208 208
     }
209 209
 
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
      * Run deleted rows to Zoho : local_delete.
212 212
      * @param AbstractZohoDao $zohoDao
213 213
      */
214
-    public function pushDeletedRows(AbstractZohoDao $zohoDao){
214
+    public function pushDeletedRows(AbstractZohoDao $zohoDao) {
215 215
         $this->deleteDataToZoho($zohoDao, 'local_delete');
216 216
     }
217 217
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@
 block discarded – undo
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){
Please login to merge, or discard this patch.