@@ -105,8 +105,7 @@ discard block |
||
| 105 | 105 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
| 106 | 106 | exit(0); |
| 107 | 107 | } |
| 108 | - } |
|
| 109 | - catch (Exception $e) |
|
| 108 | + } catch (Exception $e) |
|
| 110 | 109 | { |
| 111 | 110 | if ($test === true) |
| 112 | 111 | { |
@@ -128,10 +127,11 @@ discard block |
||
| 128 | 127 | try |
| 129 | 128 | { |
| 130 | 129 | $dbconn = IcingaDbConnection::fromResourceName($DBname); |
| 131 | - } |
|
| 132 | - catch (Exception $e) |
|
| 130 | + } catch (Exception $e) |
|
| 133 | 131 | { |
| 134 | - if ($test) return array(2,$DBname); |
|
| 132 | + if ($test) { |
|
| 133 | + return array(2,$DBname); |
|
| 134 | + } |
|
| 135 | 135 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
| 136 | 136 | return null; |
| 137 | 137 | } |
@@ -140,10 +140,11 @@ discard block |
||
| 140 | 140 | { |
| 141 | 141 | $dbAdapter=$dbconn->getDbAdapter(); |
| 142 | 142 | |
| 143 | - } |
|
| 144 | - catch (Exception $e) |
|
| 143 | + } catch (Exception $e) |
|
| 145 | 144 | { |
| 146 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 145 | + if ($test) { |
|
| 146 | + return array(3,$DBname,$e->getMessage()); |
|
| 147 | + } |
|
| 147 | 148 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
| 148 | 149 | return null; |
| 149 | 150 | } |
@@ -155,7 +156,9 @@ discard block |
||
| 155 | 156 | return $testRet; |
| 156 | 157 | } |
| 157 | 158 | } |
| 158 | - if ($test) return array(0,''); |
|
| 159 | + if ($test) { |
|
| 160 | + return array(0,''); |
|
| 161 | + } |
|
| 159 | 162 | return $dbAdapter; |
| 160 | 163 | } |
| 161 | 164 | |
@@ -166,19 +169,25 @@ discard block |
||
| 166 | 169 | */ |
| 167 | 170 | public function getDb($test=false) |
| 168 | 171 | { |
| 169 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 172 | + if ($this->trapDB != null && $test = false) { |
|
| 173 | + return $this->trapDB; |
|
| 174 | + } |
|
| 170 | 175 | |
| 171 | 176 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 172 | 177 | |
| 173 | 178 | if ( ! $dbresource ) |
| 174 | 179 | { |
| 175 | - if ($test) return array(1,''); |
|
| 180 | + if ($test) { |
|
| 181 | + return array(1,''); |
|
| 182 | + } |
|
| 176 | 183 | $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
| 177 | 184 | return null; |
| 178 | 185 | } |
| 179 | 186 | $retDB=$this->getDbByName($dbresource,$test,true); |
| 180 | 187 | |
| 181 | - if ($test === true) return $retDB; |
|
| 188 | + if ($test === true) { |
|
| 189 | + return $retDB; |
|
| 190 | + } |
|
| 182 | 191 | |
| 183 | 192 | $this->trapDB=$retDB; |
| 184 | 193 | return $this->trapDB; |
@@ -191,13 +200,17 @@ discard block |
||
| 191 | 200 | */ |
| 192 | 201 | public function getIdoDb($test=false) |
| 193 | 202 | { |
| 194 | - if ($this->idoDB != null && $test = false) return $this->idoDB; |
|
| 203 | + if ($this->idoDB != null && $test = false) { |
|
| 204 | + return $this->idoDB; |
|
| 205 | + } |
|
| 195 | 206 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 196 | 207 | $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
| 197 | 208 | |
| 198 | 209 | if ( ! $dbresource ) |
| 199 | 210 | { |
| 200 | - if ($test) return array(1,'No database in config.ini'); |
|
| 211 | + if ($test) { |
|
| 212 | + return array(1,'No database in config.ini'); |
|
| 213 | + } |
|
| 201 | 214 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
| 202 | 215 | return null; |
| 203 | 216 | } |
@@ -205,10 +218,11 @@ discard block |
||
| 205 | 218 | try |
| 206 | 219 | { |
| 207 | 220 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
| 208 | - } |
|
| 209 | - catch (Exception $e) |
|
| 221 | + } catch (Exception $e) |
|
| 210 | 222 | { |
| 211 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 223 | + if ($test) { |
|
| 224 | + return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 225 | + } |
|
| 212 | 226 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
| 213 | 227 | return null; |
| 214 | 228 | } |
@@ -228,8 +242,7 @@ discard block |
||
| 228 | 242 | { |
| 229 | 243 | return array(4,"$dbresource does not look like an IDO database"); |
| 230 | 244 | } |
| 231 | - } |
|
| 232 | - catch (Exception $e) |
|
| 245 | + } catch (Exception $e) |
|
| 233 | 246 | { |
| 234 | 247 | return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
| 235 | 248 | } |