@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | ) |
59 | 59 | ->from('WbmQueryManager\Models\Query', 'query'); |
60 | 60 | |
61 | - if(!empty($id)){ |
|
61 | + if (!empty($id)) { |
|
62 | 62 | $qb->where('query.id = :id') |
63 | 63 | ->setParameter(':id', $id); |
64 | 64 | } else { |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | $params = $this->Request()->getPost(); |
78 | 78 | |
79 | - if($params['hasCronjob'] && empty($params['nextRun'])){ |
|
79 | + if ($params['hasCronjob'] && empty($params['nextRun'])) { |
|
80 | 80 | $params['nextRun'] = new \DateTime(); |
81 | 81 | } |
82 | 82 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $params = $this->Request()->getPost(); |
100 | 100 | $id = (int)$this->Request()->get('id'); |
101 | 101 | |
102 | - if($params['hasCronjob'] && empty($params['nextRun'])){ |
|
102 | + if ($params['hasCronjob'] && empty($params['nextRun'])) { |
|
103 | 103 | $params['nextRun'] = new \DateTime(); |
104 | 104 | } |
105 | 105 | |
@@ -164,18 +164,18 @@ discard block |
||
164 | 164 | do { |
165 | 165 | $data[$i]['rowsetKey'] = $i; |
166 | 166 | |
167 | - if($this->container->get('wbm_query_manager.db')->getColumnCount($query)){ |
|
167 | + if ($this->container->get('wbm_query_manager.db')->getColumnCount($query)) { |
|
168 | 168 | $records = $this->container->get('wbm_query_manager.db')->fetchAll($query); |
169 | 169 | $data[$i]['rowCount'] = $this->container->get('wbm_query_manager.db')->getRowCount($query); |
170 | 170 | |
171 | - if($download && $rowsetKey != $i){ |
|
171 | + if ($download && $rowsetKey != $i) { |
|
172 | 172 | $i++; |
173 | 173 | continue; |
174 | 174 | } |
175 | 175 | |
176 | 176 | $recordFields = array_keys($records[0]); |
177 | 177 | $columns = array(); |
178 | - foreach($recordFields as $recordField){ |
|
178 | + foreach ($recordFields as $recordField) { |
|
179 | 179 | $columns[] = array( |
180 | 180 | 'header' => $recordField, |
181 | 181 | 'dataIndex' => $recordField, |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'columns' => $columns |
190 | 190 | ); |
191 | 191 | |
192 | - if($download){ |
|
192 | + if ($download) { |
|
193 | 193 | $this->container->get('plugins')->Controller()->ViewRenderer()->setNoRender(); |
194 | 194 | $now = new \DateTime(); |
195 | 195 | $file = "query_" . $now->format('Y_m_d_h_i_s') . ".csv"; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | header("Content-Disposition: attachment; filename=\"$file\""); |
198 | 198 | |
199 | 199 | $outputBuffer = fopen("php://output", 'w'); |
200 | - foreach(array_merge(array(0 => $recordFields),$records) as $val) { |
|
200 | + foreach (array_merge(array(0 => $recordFields), $records) as $val) { |
|
201 | 201 | fputcsv($outputBuffer, $val, $this->container->get('config')->getByNamespace('WbmQueryManager', 'csv_field_separator')); |
202 | 202 | } |
203 | 203 | fclose($outputBuffer); |
@@ -58,11 +58,11 @@ discard block |
||
58 | 58 | */ |
59 | 59 | private function getConnection($query) |
60 | 60 | { |
61 | - if(function_exists('mysqli_connect')) { |
|
61 | + if (function_exists('mysqli_connect')) { |
|
62 | 62 | $config = $this->container->getParameter('shopware.db'); |
63 | 63 | $mysqli = new \Zend_Db_Adapter_Mysqli($config); |
64 | 64 | $connection = $mysqli->getConnection(); |
65 | - if($connection->multi_query($query)){ |
|
65 | + if ($connection->multi_query($query)) { |
|
66 | 66 | return $connection; |
67 | 67 | } |
68 | 68 | } |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | public function query($query) |
77 | 77 | { |
78 | 78 | $connection = $this->getConnection($query); |
79 | - if(get_class($connection) == 'mysqli'){ |
|
79 | + if (get_class($connection) == 'mysqli') { |
|
80 | 80 | return $connection; |
81 | 81 | } |
82 | 82 | return $connection->query($query); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | public function getRowCount($query) |
90 | 90 | { |
91 | - if(get_class($query) == 'mysqli'){ |
|
91 | + if (get_class($query) == 'mysqli') { |
|
92 | 92 | return $query->affected_rows; |
93 | 93 | } |
94 | 94 | return $query->rowCount(); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function getColumnCount($query) |
102 | 102 | { |
103 | - if(get_class($query) == 'mysqli'){ |
|
103 | + if (get_class($query) == 'mysqli') { |
|
104 | 104 | return $query->field_count; |
105 | 105 | } |
106 | 106 | return $query->columnCount(); |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | */ |
113 | 113 | public function fetchAll($query) |
114 | 114 | { |
115 | - if(get_class($query) == 'mysqli'){ |
|
115 | + if (get_class($query) == 'mysqli') { |
|
116 | 116 | $results = array(); |
117 | - if($result = $query->store_result()){ |
|
118 | - while($row = $result->fetch_assoc()){ |
|
117 | + if ($result = $query->store_result()) { |
|
118 | + while ($row = $result->fetch_assoc()) { |
|
119 | 119 | $results[] = $row; |
120 | 120 | } |
121 | 121 | } |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function nextResult($query) |
132 | 132 | { |
133 | - if(get_class($query) == 'mysqli'){ |
|
133 | + if (get_class($query) == 'mysqli') { |
|
134 | 134 | return $query->next_result(); |
135 | 135 | } |
136 | 136 | return false; |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | public function close($query) |
144 | 144 | { |
145 | - if(get_class($query) == 'mysqli'){ |
|
145 | + if (get_class($query) == 'mysqli') { |
|
146 | 146 | return $query->close(); |
147 | 147 | } else { |
148 | 148 | $query->closeCursor(); |
@@ -76,13 +76,13 @@ discard block |
||
76 | 76 | $data = array(); |
77 | 77 | $clearCacheAfter = false; |
78 | 78 | |
79 | - foreach($cronJobs as $cronJob){ |
|
79 | + foreach ($cronJobs as $cronJob) { |
|
80 | 80 | $i = 0; |
81 | 81 | $numRows = 0; |
82 | 82 | try { |
83 | 83 | /** @var \mysqli|\Zend_Db_Statement_Pdo $query */ |
84 | 84 | $query = $this->container->get('wbm_query_manager.db')->query($cronJob['sqlString']); |
85 | - if($query instanceof \Zend_Db_Statement_Pdo) { |
|
85 | + if ($query instanceof \Zend_Db_Statement_Pdo) { |
|
86 | 86 | $query->closeCursor(); |
87 | 87 | } |
88 | 88 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $snippets = $this->container->get('snippets')->getNamespace("backend/plugins/wbm/querymanager"); |
91 | 91 | |
92 | 92 | do { |
93 | - if($this->container->get('wbm_query_manager.db')->getColumnCount($query)){ |
|
93 | + if ($this->container->get('wbm_query_manager.db')->getColumnCount($query)) { |
|
94 | 94 | $records = $this->container->get('wbm_query_manager.db')->fetchAll($query); |
95 | 95 | $rowCount = $this->container->get('wbm_query_manager.db')->getRowCount($query); |
96 | 96 | $recordFields = array_keys($records[0]); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $csvPath = $this->container->get('application')->DocPath() . 'var/log/' . $file; |
103 | 103 | |
104 | 104 | $outputBuffer = fopen($csvPath, 'w'); |
105 | - foreach(array_merge(array(0 => $recordFields),$records) as $val) { |
|
105 | + foreach (array_merge(array(0 => $recordFields), $records) as $val) { |
|
106 | 106 | fputcsv($outputBuffer, $val, $this->container->get('config')->getByNamespace('WbmQueryManager', 'csv_field_separator')); |
107 | 107 | } |
108 | 108 | fclose($outputBuffer); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | if ($cronJob['mailRecipient']) { |
112 | 112 | $mailRecipient = $cronJob['mailRecipient']; |
113 | 113 | } |
114 | - if(!empty($mailRecipient)){ |
|
114 | + if (!empty($mailRecipient)) { |
|
115 | 115 | $mail = clone $this->container->get('mail'); |
116 | 116 | $mail->setFrom($this->container->get('config')->get('mail')); |
117 | 117 | $mail->addTo($mailRecipient); |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $mail->send(); |
128 | 128 | } |
129 | 129 | |
130 | - if(!$this->container->get('config')->getByNamespace('WbmQueryManager', 'log_csv')){ |
|
130 | + if (!$this->container->get('config')->getByNamespace('WbmQueryManager', 'log_csv')) { |
|
131 | 131 | unlink($csvPath); |
132 | 132 | } |
133 | 133 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $query = $this->container->get('models')->getRepository('WbmQueryManager\Models\Query')->find($cronJob['id']); |
148 | 148 | $query->setLastLog($result); |
149 | 149 | /** @var \DateTime $lastRun */ |
150 | - $lastRun = $query->getLastRun() ? : new \DateTime(); |
|
150 | + $lastRun = $query->getLastRun() ?: new \DateTime(); |
|
151 | 151 | $query->setLastRun($now); |
152 | 152 | $query->setNextRun($lastRun->add(\DateInterval::createFromDateString($query->getIntervalInt() . ' seconds'))); |
153 | 153 | |
@@ -155,14 +155,14 @@ discard block |
||
155 | 155 | $this->container->get('models')->flush(); |
156 | 156 | $this->container->get('models')->clear(); |
157 | 157 | |
158 | - if($cronJob['clear_cache']){ |
|
158 | + if ($cronJob['clear_cache']) { |
|
159 | 159 | $clearCacheAfter = true; |
160 | 160 | } |
161 | 161 | |
162 | 162 | $data[$cronJob['name']] = $result; |
163 | 163 | } |
164 | 164 | |
165 | - if($clearCacheAfter){ |
|
165 | + if ($clearCacheAfter) { |
|
166 | 166 | $cacheManager = $this->container->get('shopware.cache_manager'); |
167 | 167 | $cacheManager->clearHttpCache(); |
168 | 168 | $cacheManager->clearTemplateCache(); |
@@ -60,14 +60,14 @@ |
||
60 | 60 | */ |
61 | 61 | public function update(UpdateContext $context) |
62 | 62 | { |
63 | - if(version_compare($context->getCurrentVersion(), '2.0.0', '<')) { |
|
63 | + if (version_compare($context->getCurrentVersion(), '2.0.0', '<')) { |
|
64 | 64 | $sql = "ALTER TABLE `wbm_query_manager` CHANGE `interval` `interval_int` INT(11) NULL DEFAULT '0'; |
65 | 65 | ALTER TABLE `wbm_query_manager` CHANGE `sql` `sql_string` LONGTEXT NOT NULL;"; |
66 | 66 | |
67 | 67 | $this->container->get('shopware.db')->query($sql); |
68 | 68 | } |
69 | 69 | |
70 | - if(version_compare($context->getCurrentVersion(), '2.0.3', '<')) { |
|
70 | + if (version_compare($context->getCurrentVersion(), '2.0.3', '<')) { |
|
71 | 71 | $sql = "ALTER TABLE `wbm_query_manager` ADD `mail_recipient` VARCHAR (255) NULL DEFAULT NULL AFTER `last_run`;"; |
72 | 72 | |
73 | 73 | $this->container->get('shopware.db')->query($sql); |