@@ -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); |
@@ -60,7 +60,7 @@ |
||
| 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 | |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | private function getConnection($query) |
| 53 | 53 | { |
| 54 | - if(function_exists('mysqli_connect') && class_exists('Zend_Db_Adapter_Mysqli')) { |
|
| 54 | + if (function_exists('mysqli_connect') && class_exists('Zend_Db_Adapter_Mysqli')) { |
|
| 55 | 55 | $config = $this->container->getParameter('shopware.db'); |
| 56 | 56 | $mysqli = new \Zend_Db_Adapter_Mysqli($config); |
| 57 | 57 | $connection = $mysqli->getConnection(); |
| 58 | - if($connection->multi_query($query)){ |
|
| 58 | + if ($connection->multi_query($query)) { |
|
| 59 | 59 | return $connection; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | public function query($query) |
| 70 | 70 | { |
| 71 | 71 | $connection = $this->getConnection($query); |
| 72 | - if(get_class($connection) == 'mysqli'){ |
|
| 72 | + if (get_class($connection) == 'mysqli') { |
|
| 73 | 73 | return $connection; |
| 74 | 74 | } |
| 75 | 75 | return $connection->query($query); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function getRowCount($query) |
| 83 | 83 | { |
| 84 | - if(get_class($query) == 'mysqli'){ |
|
| 84 | + if (get_class($query) == 'mysqli') { |
|
| 85 | 85 | return $query->affected_rows; |
| 86 | 86 | } |
| 87 | 87 | return $query->rowCount(); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function getColumnCount($query) |
| 95 | 95 | { |
| 96 | - if(get_class($query) == 'mysqli'){ |
|
| 96 | + if (get_class($query) == 'mysqli') { |
|
| 97 | 97 | return $query->field_count; |
| 98 | 98 | } |
| 99 | 99 | return $query->columnCount(); |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | public function fetchAll($query) |
| 107 | 107 | { |
| 108 | - if(get_class($query) == 'mysqli'){ |
|
| 108 | + if (get_class($query) == 'mysqli') { |
|
| 109 | 109 | $results = array(); |
| 110 | - if($result = $query->store_result()){ |
|
| 111 | - while($row = $result->fetch_assoc()){ |
|
| 110 | + if ($result = $query->store_result()) { |
|
| 111 | + while ($row = $result->fetch_assoc()) { |
|
| 112 | 112 | $results[] = $row; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public function nextResult($query) |
| 125 | 125 | { |
| 126 | - if(get_class($query) == 'mysqli'){ |
|
| 126 | + if (get_class($query) == 'mysqli') { |
|
| 127 | 127 | return $query->next_result(); |
| 128 | 128 | } |
| 129 | 129 | return false; |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | */ |
| 136 | 136 | public function close($query) |
| 137 | 137 | { |
| 138 | - if(get_class($query) == 'mysqli'){ |
|
| 138 | + if (get_class($query) == 'mysqli') { |
|
| 139 | 139 | return $query->close(); |
| 140 | 140 | } else { |
| 141 | 141 | $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,13 +102,13 @@ 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); |
| 109 | 109 | |
| 110 | 110 | $mailRecipient = $this->container->get('config')->getByNamespace('WbmQueryManager', 'mail_address_receiver'); |
| 111 | - if(!empty($mailRecipient)){ |
|
| 111 | + if (!empty($mailRecipient)) { |
|
| 112 | 112 | $mail = clone $this->container->get('mail'); |
| 113 | 113 | $mail->setFrom($this->container->get('config')->get('mail')); |
| 114 | 114 | $mail->addTo($mailRecipient); |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | $mail->send(); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - if(!$this->container->get('config')->getByNamespace('WbmQueryManager', 'log_csv')){ |
|
| 127 | + if (!$this->container->get('config')->getByNamespace('WbmQueryManager', 'log_csv')) { |
|
| 128 | 128 | unlink($csvPath); |
| 129 | 129 | } |
| 130 | 130 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | $query = $this->container->get('models')->getRepository('WbmQueryManager\Models\Query')->find($cronJob['id']); |
| 145 | 145 | $query->setLastLog($result); |
| 146 | 146 | /** @var \DateTime $lastRun */ |
| 147 | - $lastRun = $query->getLastRun() ? : new \DateTime(); |
|
| 147 | + $lastRun = $query->getLastRun() ?: new \DateTime(); |
|
| 148 | 148 | $query->setLastRun($now); |
| 149 | 149 | $query->setNextRun($lastRun->add(\DateInterval::createFromDateString($query->getIntervalInt() . ' seconds'))); |
| 150 | 150 | |
@@ -152,14 +152,14 @@ discard block |
||
| 152 | 152 | $this->container->get('models')->flush(); |
| 153 | 153 | $this->container->get('models')->clear(); |
| 154 | 154 | |
| 155 | - if($cronJob['clear_cache']){ |
|
| 155 | + if ($cronJob['clear_cache']) { |
|
| 156 | 156 | $clearCacheAfter = true; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $data[$cronJob['name']] = $result; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - if($clearCacheAfter){ |
|
| 162 | + if ($clearCacheAfter) { |
|
| 163 | 163 | $cacheManager = $this->container->get('shopware.cache_manager'); |
| 164 | 164 | $cacheManager->clearHttpCache(); |
| 165 | 165 | $cacheManager->clearTemplateCache(); |