Completed
Push — 2.0 ( bde703...da6ae8 )
by Raphaël
04:43 queued 01:54
created
src/ZohoDatabasePusher.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             $this->logger = $logger;
47 47
         }
48 48
         $this->apiLimitInsertUpdateDelete = $apiLimitInsertUpdateDelete;
49
-        if($apiLimitInsertUpdateDelete === null){
49
+        if ($apiLimitInsertUpdateDelete === null) {
50 50
             $this->apiLimitInsertUpdateDelete = 100;
51 51
         }
52 52
     }
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
         $rowsDeleted = [];
90 90
         //@see https://www.zoho.com/crm/help/api/api-limits.html
91 91
         //To optimize your API usage, get maximum 200 records with each request and insert, update or delete maximum 100 records with each request.
92
-        do{
92
+        do {
93 93
             $statementLimiter = $this->connection->createQueryBuilder();
94 94
             $statementLimiter->select('DISTINCT table_name,uid')
95 95
                 ->from($localTable)->setMaxResults($this->apiLimitInsertUpdateDelete);
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
                 $statement->addSelect('l.field_name as updated_fieldname');
100 100
             }
101 101
             $statement->from($localTable, 'l')
102
-                ->join('l','('.$statementLimiter->getSQL().')','ll','ll.table_name = l.table_name and  ll.uid = l.uid')
102
+                ->join('l', '('.$statementLimiter->getSQL().')', 'll', 'll.table_name = l.table_name and  ll.uid = l.uid')
103 103
                 ->join('l', $tableName, 'zcrm', 'zcrm.uid = l.uid')
104 104
                 ->where('l.table_name=:table_name')
105 105
                 ->setParameters([
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
                     $rowsDeleted[] = $row['uid'];
132 132
                 }
133 133
             }
134
-            $this->sendDataToZohoCleanLocal($zohoDao,$zohoBeans,$rowsDeleted,$update);
134
+            $this->sendDataToZohoCleanLocal($zohoDao, $zohoBeans, $rowsDeleted, $update);
135 135
             $statementElement = $this->connection->createQueryBuilder();
136
-            $countElementToPush =  $statementElement->select('*')->from($localTable)->execute()->rowCount();
137
-        } while($countElementToPush > 0);
136
+            $countElementToPush = $statementElement->select('*')->from($localTable)->execute()->rowCount();
137
+        } while ($countElementToPush > 0);
138 138
     }
139 139
 
140 140
     /**
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
      * @param string[] $rowsDeleted
144 144
      * @param bool $update
145 145
      */
146
-    private function sendDataToZohoCleanLocal(AbstractZohoDao $zohoDao, array $zohoBeans,$rowsDeleted, $update = false)
146
+    private function sendDataToZohoCleanLocal(AbstractZohoDao $zohoDao, array $zohoBeans, $rowsDeleted, $update = false)
147 147
     {
148 148
         $tableName = ZohoDatabaseHelper::getTableName($zohoDao, $this->prefix);
149 149
         $zohoDao->save($zohoBeans);
@@ -155,13 +155,13 @@  discard block
 block discarded – undo
155 155
                     // ID not exist we can update the new row with the Zoho ID
156 156
                     $this->connection->beginTransaction();
157 157
                     $this->connection->update($tableName, ['id' => $zohoBean->getZohoId()], ['uid' => $uid]);
158
-                    $this->connection->delete('local_insert', ['table_name'=>$tableName, 'uid' => $uid ]);
158
+                    $this->connection->delete('local_insert', ['table_name'=>$tableName, 'uid' => $uid]);
159 159
                     $this->connection->commit();
160 160
                 } else {
161 161
                     //ID already exist we need to delete the duplicate row.
162 162
                     $this->connection->beginTransaction();
163
-                    $this->connection->delete($tableName, ['uid' => $uid ]);
164
-                    $this->connection->delete('local_insert', ['table_name'=>$tableName, 'uid' => $uid ]);
163
+                    $this->connection->delete($tableName, ['uid' => $uid]);
164
+                    $this->connection->delete('local_insert', ['table_name'=>$tableName, 'uid' => $uid]);
165 165
                     $this->connection->commit();
166 166
                 }
167 167
             }
Please login to merge, or discard this patch.