@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | * @param int $code |
| 25 | 25 | * @param Exception $previous |
| 26 | 26 | */ |
| 27 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
| 27 | + public function __construct(array $retarray, string $message=null, int $code=0, Exception $previous=null) |
|
| 28 | 28 | { |
| 29 | - parent::__construct($message,$code,$previous); |
|
| 30 | - $this->returnArray = $retarray; |
|
| 29 | + parent::__construct($message, $code, $previous); |
|
| 30 | + $this->returnArray=$retarray; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -79,19 +79,19 @@ discard block |
||
| 79 | 79 | * @param string $DBname Name of DB |
| 80 | 80 | * @throws DBException if test = true |
| 81 | 81 | */ |
| 82 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
| 82 | + protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname) |
|
| 83 | 83 | { |
| 84 | 84 | try |
| 85 | 85 | { |
| 86 | - $query = $dbAdapter->select() |
|
| 87 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
| 86 | + $query=$dbAdapter->select() |
|
| 87 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value') |
|
| 88 | 88 | ->where('name=\'db_version\''); |
| 89 | 89 | $version=$dbAdapter->fetchRow($query); |
| 90 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
| 90 | + if (($version == null) || !property_exists($version, 'value')) |
|
| 91 | 91 | { |
| 92 | 92 | if ($test === true) |
| 93 | 93 | { |
| 94 | - throw new DBException(array(4,$DBname)); |
|
| 94 | + throw new DBException(array(4, $DBname)); |
|
| 95 | 95 | } |
| 96 | 96 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 97 | 97 | exit(0); |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | if ($test === true) |
| 102 | 102 | { |
| 103 | - throw new DBException(array(5,$version->value,$min)); |
|
| 103 | + throw new DBException(array(5, $version->value, $min)); |
|
| 104 | 104 | } |
| 105 | 105 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
| 106 | 106 | exit(0); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | { |
| 111 | 111 | if ($test === true) |
| 112 | 112 | { |
| 113 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
| 113 | + throw new DBException(array(3, $DBname, $e->getMessage())); |
|
| 114 | 114 | } |
| 115 | 115 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 116 | 116 | } |
@@ -123,15 +123,15 @@ discard block |
||
| 123 | 123 | * @param $test_version bool if set to flase, does not test database version of trapDB |
| 124 | 124 | * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
| 125 | 125 | */ |
| 126 | - protected function getDbByName($DBname,$test=false,$test_version=true) |
|
| 126 | + protected function getDbByName($DBname, $test=false, $test_version=true) |
|
| 127 | 127 | { |
| 128 | 128 | try |
| 129 | 129 | { |
| 130 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
| 130 | + $dbconn=IcingaDbConnection::fromResourceName($DBname); |
|
| 131 | 131 | } |
| 132 | 132 | catch (Exception $e) |
| 133 | 133 | { |
| 134 | - if ($test) return array(2,$DBname); |
|
| 134 | + if ($test) return array(2, $DBname); |
|
| 135 | 135 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
| 136 | 136 | return null; |
| 137 | 137 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | } |
| 144 | 144 | catch (Exception $e) |
| 145 | 145 | { |
| 146 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 146 | + if ($test) return array(3, $DBname, $e->getMessage()); |
|
| 147 | 147 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
| 148 | 148 | return null; |
| 149 | 149 | } |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | return $testRet; |
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | - if ($test) return array(0,''); |
|
| 158 | + if ($test) return array(0, ''); |
|
| 159 | 159 | return $dbAdapter; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -166,17 +166,17 @@ discard block |
||
| 166 | 166 | */ |
| 167 | 167 | public function getDb($test=false) |
| 168 | 168 | { |
| 169 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 169 | + if ($this->trapDB != null && $test=false) return $this->trapDB; |
|
| 170 | 170 | |
| 171 | 171 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 172 | 172 | |
| 173 | - if ( ! $dbresource ) |
|
| 173 | + if (!$dbresource) |
|
| 174 | 174 | { |
| 175 | - if ($test) return array(1,''); |
|
| 175 | + if ($test) return array(1, ''); |
|
| 176 | 176 | $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
| 177 | 177 | return null; |
| 178 | 178 | } |
| 179 | - $retDB=$this->getDbByName($dbresource,$test,true); |
|
| 179 | + $retDB=$this->getDbByName($dbresource, $test, true); |
|
| 180 | 180 | |
| 181 | 181 | if ($test === true) return $retDB; |
| 182 | 182 | |
@@ -191,50 +191,50 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function getIdoDb($test=false) |
| 193 | 193 | { |
| 194 | - if ($this->idoDB != null && $test = false) return $this->idoDB; |
|
| 194 | + if ($this->idoDB != null && $test=false) return $this->idoDB; |
|
| 195 | 195 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 196 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
| 196 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
| 197 | 197 | |
| 198 | - if ( ! $dbresource ) |
|
| 198 | + if (!$dbresource) |
|
| 199 | 199 | { |
| 200 | - if ($test) return array(1,'No database in config.ini'); |
|
| 200 | + if ($test) return array(1, 'No database in config.ini'); |
|
| 201 | 201 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
| 202 | 202 | return null; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | try |
| 206 | 206 | { |
| 207 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
| 207 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
| 208 | 208 | } |
| 209 | 209 | catch (Exception $e) |
| 210 | 210 | { |
| 211 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 211 | + if ($test) return array(2, "Database $dbresource does not exists in IcingaWeb2"); |
|
| 212 | 212 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
| 213 | 213 | return null; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | if ($test === false) |
| 217 | 217 | { |
| 218 | - $this->idoDB = $dbconn->getDbAdapter(); |
|
| 218 | + $this->idoDB=$dbconn->getDbAdapter(); |
|
| 219 | 219 | return $this->idoDB; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | try |
| 223 | 223 | { |
| 224 | - $query = $dbconn->select() |
|
| 225 | - ->from('icinga_dbversion',array('version')); |
|
| 224 | + $query=$dbconn->select() |
|
| 225 | + ->from('icinga_dbversion', array('version')); |
|
| 226 | 226 | $version=$dbconn->fetchRow($query); |
| 227 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
| 227 | + if (($version == null) || !property_exists($version, 'version')) |
|
| 228 | 228 | { |
| 229 | - return array(4,"$dbresource does not look like an IDO database"); |
|
| 229 | + return array(4, "$dbresource does not look like an IDO database"); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | catch (Exception $e) |
| 233 | 233 | { |
| 234 | - return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
|
| 234 | + return array(3, "Error connecting to $dbresource : ".$e->getMessage()); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - return array(0,''); |
|
| 237 | + return array(0, ''); |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | } |
| 241 | 241 | \ No newline at end of file |