@@ -52,20 +52,25 @@ discard block |
||
| 52 | 52 | $version=$dbAdapter->fetchRow($query); |
| 53 | 53 | if ( ($version == null) || ! property_exists($version,'value') ) |
| 54 | 54 | { |
| 55 | - if ($test) return array(4,$DBname); |
|
| 55 | + if ($test) { |
|
| 56 | + return array(4,$DBname); |
|
| 57 | + } |
|
| 56 | 58 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 57 | 59 | return null; |
| 58 | 60 | } |
| 59 | 61 | if ($version->value < $min) |
| 60 | 62 | { |
| 61 | - if ($test) return array(5,$version->value,$min); |
|
| 63 | + if ($test) { |
|
| 64 | + return array(5,$version->value,$min); |
|
| 65 | + } |
|
| 62 | 66 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
| 63 | 67 | return null; |
| 64 | 68 | } |
| 65 | - } |
|
| 66 | - catch (Exception $e) |
|
| 69 | + } catch (Exception $e) |
|
| 67 | 70 | { |
| 68 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 71 | + if ($test) { |
|
| 72 | + return array(3,$DBname,$e->getMessage()); |
|
| 73 | + } |
|
| 69 | 74 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
| 70 | 75 | } |
| 71 | 76 | return null; |
@@ -82,10 +87,11 @@ discard block |
||
| 82 | 87 | try |
| 83 | 88 | { |
| 84 | 89 | $dbconn = IcingaDbConnection::fromResourceName($DBname); |
| 85 | - } |
|
| 86 | - catch (Exception $e) |
|
| 90 | + } catch (Exception $e) |
|
| 87 | 91 | { |
| 88 | - if ($test) return array(2,$DBname); |
|
| 92 | + if ($test) { |
|
| 93 | + return array(2,$DBname); |
|
| 94 | + } |
|
| 89 | 95 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
| 90 | 96 | return null; |
| 91 | 97 | } |
@@ -94,10 +100,11 @@ discard block |
||
| 94 | 100 | { |
| 95 | 101 | $dbAdapter=$dbconn->getDbAdapter(); |
| 96 | 102 | |
| 97 | - } |
|
| 98 | - catch (Exception $e) |
|
| 103 | + } catch (Exception $e) |
|
| 99 | 104 | { |
| 100 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 105 | + if ($test) { |
|
| 106 | + return array(3,$DBname,$e->getMessage()); |
|
| 107 | + } |
|
| 101 | 108 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
| 102 | 109 | return null; |
| 103 | 110 | } |
@@ -109,7 +116,9 @@ discard block |
||
| 109 | 116 | return $testRet; |
| 110 | 117 | } |
| 111 | 118 | } |
| 112 | - if ($test) return array(0,''); |
|
| 119 | + if ($test) { |
|
| 120 | + return array(0,''); |
|
| 121 | + } |
|
| 113 | 122 | return $dbAdapter; |
| 114 | 123 | } |
| 115 | 124 | |
@@ -120,19 +129,25 @@ discard block |
||
| 120 | 129 | */ |
| 121 | 130 | public function getDb($test=false) |
| 122 | 131 | { |
| 123 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 132 | + if ($this->trapDB != null && $test = false) { |
|
| 133 | + return $this->trapDB; |
|
| 134 | + } |
|
| 124 | 135 | |
| 125 | 136 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
| 126 | 137 | |
| 127 | 138 | if ( ! $dbresource ) |
| 128 | 139 | { |
| 129 | - if ($test) return array(1,''); |
|
| 140 | + if ($test) { |
|
| 141 | + return array(1,''); |
|
| 142 | + } |
|
| 130 | 143 | $this->redirectNow('trapdirector/settings?dberror=1'); |
| 131 | 144 | return null; |
| 132 | 145 | } |
| 133 | 146 | $retDB=$this->getDbByName($dbresource,$test,true); |
| 134 | 147 | |
| 135 | - if ($test === true) return $retDB; |
|
| 148 | + if ($test === true) { |
|
| 149 | + return $retDB; |
|
| 150 | + } |
|
| 136 | 151 | |
| 137 | 152 | $this->trapDB=$retDB; |
| 138 | 153 | return $this->trapDB; |
@@ -145,13 +160,17 @@ discard block |
||
| 145 | 160 | */ |
| 146 | 161 | public function getIdoDb($test=false) |
| 147 | 162 | { |
| 148 | - if ($this->idoDB != null && $test = false) return $this->idoDB; |
|
| 163 | + if ($this->idoDB != null && $test = false) { |
|
| 164 | + return $this->idoDB; |
|
| 165 | + } |
|
| 149 | 166 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 150 | 167 | $dbresource=$this->Config()->get('config', 'IDOdatabase');; |
| 151 | 168 | |
| 152 | 169 | if ( ! $dbresource ) |
| 153 | 170 | { |
| 154 | - if ($test) return array(1,'No database in config.ini'); |
|
| 171 | + if ($test) { |
|
| 172 | + return array(1,'No database in config.ini'); |
|
| 173 | + } |
|
| 155 | 174 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
| 156 | 175 | return null; |
| 157 | 176 | } |
@@ -159,10 +178,11 @@ discard block |
||
| 159 | 178 | try |
| 160 | 179 | { |
| 161 | 180 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
| 162 | - } |
|
| 163 | - catch (Exception $e) |
|
| 181 | + } catch (Exception $e) |
|
| 164 | 182 | { |
| 165 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 183 | + if ($test) { |
|
| 184 | + return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 185 | + } |
|
| 166 | 186 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
| 167 | 187 | return null; |
| 168 | 188 | } |
@@ -182,8 +202,7 @@ discard block |
||
| 182 | 202 | { |
| 183 | 203 | return array(4,"$dbresource does not look like an IDO database"); |
| 184 | 204 | } |
| 185 | - } |
|
| 186 | - catch (Exception $e) |
|
| 205 | + } catch (Exception $e) |
|
| 187 | 206 | { |
| 188 | 207 | return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
| 189 | 208 | } |