@@ -13,11 +13,15 @@ |
||
13 | 13 | } |
14 | 14 | |
15 | 15 | public function addIndex($args) { |
16 | - if (Database::EDIT_INDEX & $this->alterDb) $this->adapter->addIndex($this->table, $args); |
|
16 | + if (Database::EDIT_INDEX & $this->alterDb) { |
|
17 | + $this->adapter->addIndex($this->table, $args); |
|
18 | + } |
|
17 | 19 | } |
18 | 20 | |
19 | 21 | public function optimizeColumns() { |
20 | - if (Database::EDIT_OPTIMISE & $this->alterDb && rand(0,500) == 1) $this->adapter->optimiseColumns($this->table); |
|
22 | + if (Database::EDIT_OPTIMISE & $this->alterDb && rand(0,500) == 1) { |
|
23 | + $this->adapter->optimiseColumns($this->table); |
|
24 | + } |
|
21 | 25 | } |
22 | 26 | |
23 | 27 | public function getTryInsertAgain($tryagain) { |
@@ -24,13 +24,15 @@ discard block |
||
24 | 24 | if (!isset($this->idCache[$id])) { |
25 | 25 | try { |
26 | 26 | $result = $this->selectQuery($this->selectBuilder->select($this->table, $pk . ' = :id', [':id' => $id], ['limit' => 1])); |
27 | - } |
|
28 | - catch (\Exception $e) { |
|
27 | + } catch (\Exception $e) { |
|
29 | 28 | // Don't issue an error if it cannot be found since we return null |
30 | 29 | } |
31 | 30 | |
32 | - if (isset($result[0])) $this->idCache[$id] = $result[0]; |
|
33 | - else return null; |
|
31 | + if (isset($result[0])) { |
|
32 | + $this->idCache[$id] = $result[0]; |
|
33 | + } else { |
|
34 | + return null; |
|
35 | + } |
|
34 | 36 | } |
35 | 37 | return $this->idCache[$id]; |
36 | 38 | } |
@@ -40,14 +42,15 @@ discard block |
||
40 | 42 | if (!isset($this->resultCache[$cacheId])) { |
41 | 43 | $query = $this->whereBuilder->createSql($fields); |
42 | 44 | |
43 | - if (!isset($options['order'])) $options['order'] = $this->defaultSort; |
|
45 | + if (!isset($options['order'])) { |
|
46 | + $options['order'] = $this->defaultSort; |
|
47 | + } |
|
44 | 48 | |
45 | 49 | try { |
46 | 50 | $this->resultCache[$cacheId] = $this->selectQuery($this->selectBuilder->select($this->table, $query['sql'], $query['args'], $options)); |
47 | 51 | $this->databaseModify->addIndex(array_keys($query['args'])); |
48 | 52 | $this->databaseModify->addIndex(explode(',', $options['order'])); |
49 | - } |
|
50 | - catch (\Exception $e) { |
|
53 | + } catch (\Exception $e) { |
|
51 | 54 | $this->errors[] = $e; |
52 | 55 | $this->resultCache[$cacheId] = []; |
53 | 56 | } |
@@ -57,7 +60,9 @@ discard block |
||
57 | 60 | |
58 | 61 | public function findAggregate($function, $field, $group = null, array $criteria = [], array $options = []) { |
59 | 62 | //Cannot count/sum/max multiple fields, pick the first one. This should only come into play when trying to count() a mapper with multiple primary keys |
60 | - if (is_array($field)) $field = $field[0]; |
|
63 | + if (is_array($field)) { |
|
64 | + $field = $field[0]; |
|
65 | + } |
|
61 | 66 | $query = $this->whereBuilder->createSql($criteria); |
62 | 67 | |
63 | 68 | try { |
@@ -66,8 +71,7 @@ discard block |
||
66 | 71 | $result = $this->selectQuery($this->selectBuilder->aggregate($this->table, $function, $field, $query['sql'], $query['args'], $group)); |
67 | 72 | |
68 | 73 | return $this->determineAggregateResult($result, $group, $field); |
69 | - } |
|
70 | - catch (\Exception $e) { |
|
74 | + } catch (\Exception $e) { |
|
71 | 75 | return $group ? [] : 0; |
72 | 76 | } |
73 | 77 | } |
@@ -75,11 +79,15 @@ discard block |
||
75 | 79 | private function determineAggregateResult($result, $group, $field) { |
76 | 80 | if ($group != null) { |
77 | 81 | $ret = []; |
78 | - foreach ($result as $res) $ret[$res->$field] = $res->val; |
|
82 | + foreach ($result as $res) { |
|
83 | + $ret[$res->$field] = $res->val; |
|
84 | + } |
|
79 | 85 | return $ret; |
86 | + } else if (isset($result[0])) { |
|
87 | + return $result[0]->val; |
|
88 | + } else { |
|
89 | + return 0; |
|
80 | 90 | } |
81 | - else if (isset($result[0])) return $result[0]->val; |
|
82 | - else return 0; |
|
83 | 91 | } |
84 | 92 | |
85 | 93 | private function selectQuery(\Maphper\Lib\Query $query) { |
@@ -95,8 +103,11 @@ discard block |
||
95 | 103 | } |
96 | 104 | |
97 | 105 | public function updateCache($data, $pkValue) { |
98 | - if (isset($this->cache[$pkValue])) $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
|
99 | - else $this->cache[$pkValue] = $data; |
|
106 | + if (isset($this->cache[$pkValue])) { |
|
107 | + $this->cache[$pkValue] = (object) array_merge((array)$this->cache[$pkValue], (array)$data); |
|
108 | + } else { |
|
109 | + $this->cache[$pkValue] = $data; |
|
110 | + } |
|
100 | 111 | } |
101 | 112 | |
102 | 113 | public function deleteIDFromCache($id) { |