@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | else $limit = ''; |
115 | 115 | |
116 | 116 | $query = $this->selectBuilder->createSql($fields, $mode); |
117 | - $query['sql'] = array_filter($query['sql']); |
|
117 | + $query['sql'] = array_filter($query['sql']); |
|
118 | 118 | $this->adapter->query($this->crudBuilder->delete($this->table, $query['sql'], $query['args'], $limit)); |
119 | 119 | $this->addIndex(array_keys($query['args'])); |
120 | 120 | |
@@ -123,23 +123,23 @@ discard block |
||
123 | 123 | $this->resultCache = []; |
124 | 124 | } |
125 | 125 | |
126 | - private function getIfNew($data) { |
|
127 | - $new = false; |
|
128 | - foreach ($this->primaryKey as $k) { |
|
129 | - if (empty($data->$k)) { |
|
130 | - $data->$k = null; |
|
131 | - $new = true; |
|
132 | - } |
|
133 | - } |
|
134 | - return $new; |
|
135 | - } |
|
126 | + private function getIfNew($data) { |
|
127 | + $new = false; |
|
128 | + foreach ($this->primaryKey as $k) { |
|
129 | + if (empty($data->$k)) { |
|
130 | + $data->$k = null; |
|
131 | + $new = true; |
|
132 | + } |
|
133 | + } |
|
134 | + return $new; |
|
135 | + } |
|
136 | 136 | |
137 | 137 | public function save($data, $tryagain = true) { |
138 | 138 | $tryagain = $tryagain && self::EDIT_STRUCTURE & $this->alterDb; |
139 | - $new = $this->getIfNew($data); |
|
139 | + $new = $this->getIfNew($data); |
|
140 | 140 | |
141 | 141 | try { |
142 | - $result = $this->insert($this->table, $this->primaryKey, $data); |
|
142 | + $result = $this->insert($this->table, $this->primaryKey, $data); |
|
143 | 143 | |
144 | 144 | //If there was an error but PDO is silent, trigger the catch block anyway |
145 | 145 | if ($result->errorCode() !== '00000') throw new \Exception('Could not insert into ' . $this->table); |
@@ -157,22 +157,22 @@ discard block |
||
157 | 157 | $this->updateCache($data); |
158 | 158 | } |
159 | 159 | |
160 | - private function updatePK($data, $new) { |
|
161 | - if ($new && count($this->primaryKey) == 1) $data->{$this->primaryKey[0]} = $this->adapter->lastInsertId(); |
|
162 | - } |
|
160 | + private function updatePK($data, $new) { |
|
161 | + if ($new && count($this->primaryKey) == 1) $data->{$this->primaryKey[0]} = $this->adapter->lastInsertId(); |
|
162 | + } |
|
163 | 163 | |
164 | - private function checkIfUpdateWorked($data) { |
|
165 | - $updateWhere = $this->crudBuilder->update($this->table, $this->primaryKey, $data); |
|
166 | - $matched = $this->findByField($updateWhere->getArgs()); |
|
164 | + private function checkIfUpdateWorked($data) { |
|
165 | + $updateWhere = $this->crudBuilder->update($this->table, $this->primaryKey, $data); |
|
166 | + $matched = $this->findByField($updateWhere->getArgs()); |
|
167 | 167 | |
168 | - if (count($matched) == 0) throw new \InvalidArgumentException('Record inserted into table ' . $this->table . ' fails table constraints'); |
|
169 | - } |
|
168 | + if (count($matched) == 0) throw new \InvalidArgumentException('Record inserted into table ' . $this->table . ' fails table constraints'); |
|
169 | + } |
|
170 | 170 | |
171 | - private function updateCache($data) { |
|
172 | - $pkValue = $data->{$this->primaryKey[0]}; |
|
171 | + private function updateCache($data) { |
|
172 | + $pkValue = $data->{$this->primaryKey[0]}; |
|
173 | 173 | if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
174 | 174 | else $this->cache[$pkValue] = $data; |
175 | - } |
|
175 | + } |
|
176 | 176 | |
177 | 177 | private function insert($table, array $primaryKey, $data) { |
178 | 178 | $error = 0; |
@@ -184,16 +184,16 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | if ($error || $result->errorCode() !== '00000') { |
187 | - $result = $this->tryUpdate($table, $primaryKey, $data); |
|
188 | - } |
|
187 | + $result = $this->tryUpdate($table, $primaryKey, $data); |
|
188 | + } |
|
189 | 189 | |
190 | 190 | return $result; |
191 | 191 | } |
192 | 192 | |
193 | - private function tryUpdate($table, array $primaryKey, $data) { |
|
194 | - $result = $this->adapter->query($this->crudBuilder->update($table, $primaryKey, $data)); |
|
195 | - if ($result->rowCount() === 0) $this->checkIfUpdateWorked($data); |
|
193 | + private function tryUpdate($table, array $primaryKey, $data) { |
|
194 | + $result = $this->adapter->query($this->crudBuilder->update($table, $primaryKey, $data)); |
|
195 | + if ($result->rowCount() === 0) $this->checkIfUpdateWorked($data); |
|
196 | 196 | |
197 | - return $result; |
|
198 | - } |
|
197 | + return $result; |
|
198 | + } |
|
199 | 199 | } |