@@ -14,30 +14,30 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class DBException extends Exception |
16 | 16 | { |
17 | - /** @var array $returnArray */ |
|
18 | - private $returnArray; |
|
17 | + /** @var array $returnArray */ |
|
18 | + private $returnArray; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Buil DBException |
|
22 | - * @param array $retarray |
|
23 | - * @param string $message |
|
24 | - * @param int $code |
|
25 | - * @param Exception $previous |
|
26 | - */ |
|
27 | - public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
28 | - { |
|
29 | - parent::__construct($message,$code,$previous); |
|
30 | - $this->returnArray = $retarray; |
|
31 | - } |
|
20 | + /** |
|
21 | + * Buil DBException |
|
22 | + * @param array $retarray |
|
23 | + * @param string $message |
|
24 | + * @param int $code |
|
25 | + * @param Exception $previous |
|
26 | + */ |
|
27 | + public function __construct(array $retarray, string $message = null, int $code = 0, Exception $previous = null) |
|
28 | + { |
|
29 | + parent::__construct($message,$code,$previous); |
|
30 | + $this->returnArray = $retarray; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Get exception array |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public function getArray() |
|
38 | - { |
|
39 | - return $this->returnArray; |
|
40 | - } |
|
33 | + /** |
|
34 | + * Get exception array |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public function getArray() |
|
38 | + { |
|
39 | + return $this->returnArray; |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -52,244 +52,244 @@ discard block |
||
52 | 52 | class UIDatabase |
53 | 53 | { |
54 | 54 | |
55 | - /** @var TrapsController $trapController TrapController 'parent' class */ |
|
56 | - protected $trapController; |
|
55 | + /** @var TrapsController $trapController TrapController 'parent' class */ |
|
56 | + protected $trapController; |
|
57 | 57 | |
58 | - /** @var Zend_Db_Adapter_Abstract $trapDB Trap Database*/ |
|
59 | - protected $trapDB; |
|
58 | + /** @var Zend_Db_Adapter_Abstract $trapDB Trap Database*/ |
|
59 | + protected $trapDB; |
|
60 | 60 | |
61 | - /** @var Zend_Db_Adapter_Abstract $trapDB Icinga IDO database*/ |
|
62 | - protected $idoDB; |
|
61 | + /** @var Zend_Db_Adapter_Abstract $trapDB Icinga IDO database*/ |
|
62 | + protected $idoDB; |
|
63 | 63 | |
64 | - /** @var array $testResult */ |
|
65 | - protected $testResult; |
|
64 | + /** @var array $testResult */ |
|
65 | + protected $testResult; |
|
66 | 66 | |
67 | - /** |
|
68 | - * |
|
69 | - * @param TrapsController $trapCtrl |
|
70 | - */ |
|
71 | - function __construct(TrapsController $trapCtrl) |
|
72 | - { |
|
73 | - $this->trapController=$trapCtrl; |
|
74 | - } |
|
67 | + /** |
|
68 | + * |
|
69 | + * @param TrapsController $trapCtrl |
|
70 | + */ |
|
71 | + function __construct(TrapsController $trapCtrl) |
|
72 | + { |
|
73 | + $this->trapController=$trapCtrl; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Test if database version >= min database version |
|
78 | - * |
|
79 | - * @param \Zend_Db_Adapter_Abstract $dbConn |
|
80 | - * @param int $min Minimum version |
|
81 | - * @param bool $test Test mode |
|
82 | - * @param string $DBname Name of DB |
|
83 | - * @return bool true if OK, false if version < min version |
|
84 | - * @throws Exception if error and test = true |
|
85 | - */ |
|
86 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
87 | - { |
|
88 | - try |
|
89 | - { |
|
90 | - $query = $dbAdapter->select() |
|
91 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
92 | - ->where('name=\'db_version\''); |
|
93 | - $version=$dbAdapter->fetchRow($query); |
|
94 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
95 | - { |
|
96 | - if ($test === true) |
|
97 | - { |
|
98 | - $this->testResult = array(4,$DBname); |
|
99 | - return false; |
|
100 | - } |
|
101 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
102 | - return false; |
|
103 | - } |
|
104 | - if ($version->value < $min) |
|
105 | - { |
|
106 | - if ($test === true) |
|
107 | - { |
|
108 | - $this->testResult = array(5,$version->value,$min); |
|
109 | - return false; |
|
110 | - } |
|
111 | - $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
112 | - return false; |
|
113 | - } |
|
114 | - } |
|
115 | - catch (Exception $e) |
|
116 | - { |
|
117 | - if ($test === true) |
|
118 | - { |
|
119 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
120 | - return false; |
|
121 | - } |
|
122 | - $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
123 | - return false; |
|
124 | - } |
|
125 | - return true; |
|
126 | - } |
|
76 | + /** |
|
77 | + * Test if database version >= min database version |
|
78 | + * |
|
79 | + * @param \Zend_Db_Adapter_Abstract $dbConn |
|
80 | + * @param int $min Minimum version |
|
81 | + * @param bool $test Test mode |
|
82 | + * @param string $DBname Name of DB |
|
83 | + * @return bool true if OK, false if version < min version |
|
84 | + * @throws Exception if error and test = true |
|
85 | + */ |
|
86 | + protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
87 | + { |
|
88 | + try |
|
89 | + { |
|
90 | + $query = $dbAdapter->select() |
|
91 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
92 | + ->where('name=\'db_version\''); |
|
93 | + $version=$dbAdapter->fetchRow($query); |
|
94 | + if ( ($version == null) || ! property_exists($version,'value') ) |
|
95 | + { |
|
96 | + if ($test === true) |
|
97 | + { |
|
98 | + $this->testResult = array(4,$DBname); |
|
99 | + return false; |
|
100 | + } |
|
101 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
102 | + return false; |
|
103 | + } |
|
104 | + if ($version->value < $min) |
|
105 | + { |
|
106 | + if ($test === true) |
|
107 | + { |
|
108 | + $this->testResult = array(5,$version->value,$min); |
|
109 | + return false; |
|
110 | + } |
|
111 | + $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
|
112 | + return false; |
|
113 | + } |
|
114 | + } |
|
115 | + catch (Exception $e) |
|
116 | + { |
|
117 | + if ($test === true) |
|
118 | + { |
|
119 | + $this->testResult = array(3,$DBname,$e->getMessage()); |
|
120 | + return false; |
|
121 | + } |
|
122 | + $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
|
123 | + return false; |
|
124 | + } |
|
125 | + return true; |
|
126 | + } |
|
127 | 127 | |
128 | - /** Get Database connexion |
|
129 | - * @param $DBname string DB name in resource.ini_ge |
|
130 | - * @param $test bool if set to true, returns error code and not database |
|
131 | - * @param $test_version bool if set to flase, does not test database version of trapDB |
|
132 | - * @throws DBException if test = true and error |
|
133 | - * @return Zend_Db_Adapter_Abstract|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
134 | - */ |
|
135 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
136 | - { |
|
137 | - try |
|
138 | - { |
|
139 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
140 | - } |
|
141 | - catch (Exception $e) |
|
142 | - { |
|
143 | - if ($test === true) |
|
144 | - { |
|
145 | - throw new DBException(array(2,$DBname)); |
|
146 | - } |
|
147 | - $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
148 | - return null; |
|
149 | - } |
|
128 | + /** Get Database connexion |
|
129 | + * @param $DBname string DB name in resource.ini_ge |
|
130 | + * @param $test bool if set to true, returns error code and not database |
|
131 | + * @param $test_version bool if set to flase, does not test database version of trapDB |
|
132 | + * @throws DBException if test = true and error |
|
133 | + * @return Zend_Db_Adapter_Abstract|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
134 | + */ |
|
135 | + protected function getDbByName($DBname , $test = false , $test_version = true) |
|
136 | + { |
|
137 | + try |
|
138 | + { |
|
139 | + $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
140 | + } |
|
141 | + catch (Exception $e) |
|
142 | + { |
|
143 | + if ($test === true) |
|
144 | + { |
|
145 | + throw new DBException(array(2,$DBname)); |
|
146 | + } |
|
147 | + $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
|
148 | + return null; |
|
149 | + } |
|
150 | 150 | |
151 | - try |
|
152 | - { |
|
153 | - $dbAdapter=$dbconn->getDbAdapter(); |
|
151 | + try |
|
152 | + { |
|
153 | + $dbAdapter=$dbconn->getDbAdapter(); |
|
154 | 154 | |
155 | - } |
|
156 | - catch (Exception $e) |
|
157 | - { |
|
158 | - if ($test === true) |
|
159 | - { |
|
160 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
161 | - } |
|
162 | - $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
163 | - return null; |
|
164 | - } |
|
155 | + } |
|
156 | + catch (Exception $e) |
|
157 | + { |
|
158 | + if ($test === true) |
|
159 | + { |
|
160 | + throw new DBException(array(3,$DBname,$e->getMessage())); |
|
161 | + } |
|
162 | + $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
|
163 | + return null; |
|
164 | + } |
|
165 | 165 | |
166 | - if ($test_version == true) { |
|
167 | - $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
168 | - if ($testRet !== true) |
|
169 | - { |
|
170 | - throw new DBException($this->testResult); |
|
171 | - } |
|
172 | - } |
|
166 | + if ($test_version == true) { |
|
167 | + $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname); |
|
168 | + if ($testRet !== true) |
|
169 | + { |
|
170 | + throw new DBException($this->testResult); |
|
171 | + } |
|
172 | + } |
|
173 | 173 | |
174 | - return $dbAdapter; |
|
175 | - } |
|
174 | + return $dbAdapter; |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * Get Trap database |
|
179 | - * @param boolean $test |
|
180 | - * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
181 | - */ |
|
182 | - public function getDb() |
|
183 | - { |
|
184 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
177 | + /** |
|
178 | + * Get Trap database |
|
179 | + * @param boolean $test |
|
180 | + * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
181 | + */ |
|
182 | + public function getDb() |
|
183 | + { |
|
184 | + if ( $this->trapDB != null ) return $this->trapDB; |
|
185 | 185 | |
186 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
186 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
187 | 187 | |
188 | - if ( ! $dbresource ) |
|
189 | - { |
|
190 | - $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
191 | - return null; |
|
192 | - } |
|
188 | + if ( ! $dbresource ) |
|
189 | + { |
|
190 | + $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
|
191 | + return null; |
|
192 | + } |
|
193 | 193 | |
194 | - try { |
|
195 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
196 | - } catch (DBException $e) { |
|
197 | - return null; // Should not happen as test = false |
|
198 | - } |
|
194 | + try { |
|
195 | + $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
196 | + } catch (DBException $e) { |
|
197 | + return null; // Should not happen as test = false |
|
198 | + } |
|
199 | 199 | |
200 | - return $this->trapDB; |
|
201 | - } |
|
200 | + return $this->trapDB; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Test Trap database |
|
205 | - * @param boolean $test |
|
206 | - * @throws DBException on error. |
|
207 | - * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
208 | - */ |
|
209 | - public function testGetDb() |
|
210 | - { |
|
211 | - $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
203 | + /** |
|
204 | + * Test Trap database |
|
205 | + * @param boolean $test |
|
206 | + * @throws DBException on error. |
|
207 | + * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
|
208 | + */ |
|
209 | + public function testGetDb() |
|
210 | + { |
|
211 | + $dbresource=$this->trapController->Config()->get('config', 'database'); |
|
212 | 212 | |
213 | - if ( ! $dbresource ) |
|
214 | - { |
|
215 | - throw new DBException(array(1,'')); |
|
216 | - } |
|
213 | + if ( ! $dbresource ) |
|
214 | + { |
|
215 | + throw new DBException(array(1,'')); |
|
216 | + } |
|
217 | 217 | |
218 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
219 | - return; |
|
220 | - } |
|
218 | + $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
219 | + return; |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * Get IDO Database |
|
224 | - * @param boolean $test |
|
225 | - * @return Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
226 | - */ |
|
227 | - public function getIdoDb($test=false) |
|
228 | - { |
|
229 | - if ($this->idoDB != null && $test === false) return $this->idoDB; |
|
230 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
231 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
222 | + /** |
|
223 | + * Get IDO Database |
|
224 | + * @param boolean $test |
|
225 | + * @return Zend_Db_Adapter_Abstract|NULL returns DB connexion or null on error. |
|
226 | + */ |
|
227 | + public function getIdoDb($test=false) |
|
228 | + { |
|
229 | + if ($this->idoDB != null && $test === false) return $this->idoDB; |
|
230 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
231 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
232 | 232 | |
233 | - if ( ! $dbresource ) |
|
234 | - { |
|
235 | - $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
236 | - return null; |
|
237 | - } |
|
233 | + if ( ! $dbresource ) |
|
234 | + { |
|
235 | + $this->redirectNow('trapdirector/settings?idodberror=1'); |
|
236 | + return null; |
|
237 | + } |
|
238 | 238 | |
239 | - try |
|
240 | - { |
|
241 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
242 | - } |
|
243 | - catch (Exception $e) |
|
244 | - { |
|
245 | - $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
246 | - return null; |
|
247 | - } |
|
239 | + try |
|
240 | + { |
|
241 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
242 | + } |
|
243 | + catch (Exception $e) |
|
244 | + { |
|
245 | + $this->redirectNow('trapdirector/settings?idodberror=2'); |
|
246 | + return null; |
|
247 | + } |
|
248 | 248 | |
249 | - $this->idoDB = $dbconn->getDbAdapter(); |
|
250 | - return $this->idoDB; |
|
251 | - } |
|
249 | + $this->idoDB = $dbconn->getDbAdapter(); |
|
250 | + return $this->idoDB; |
|
251 | + } |
|
252 | 252 | |
253 | - /** |
|
254 | - * Get IDO Database |
|
255 | - * @param boolean $test |
|
256 | - * @throws DBException on error |
|
257 | - */ |
|
258 | - public function testGetIdoDb() |
|
259 | - { |
|
260 | - // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
261 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
253 | + /** |
|
254 | + * Get IDO Database |
|
255 | + * @param boolean $test |
|
256 | + * @throws DBException on error |
|
257 | + */ |
|
258 | + public function testGetIdoDb() |
|
259 | + { |
|
260 | + // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
|
261 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
262 | 262 | |
263 | - if ( ! $dbresource ) |
|
264 | - { |
|
265 | - throw new DBException(array(1,'No database in config.ini')); |
|
266 | - } |
|
263 | + if ( ! $dbresource ) |
|
264 | + { |
|
265 | + throw new DBException(array(1,'No database in config.ini')); |
|
266 | + } |
|
267 | 267 | |
268 | - try |
|
269 | - { |
|
270 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
271 | - } |
|
272 | - catch (Exception $e) |
|
273 | - { |
|
274 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
275 | - } |
|
268 | + try |
|
269 | + { |
|
270 | + $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
271 | + } |
|
272 | + catch (Exception $e) |
|
273 | + { |
|
274 | + throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
275 | + } |
|
276 | 276 | |
277 | - try |
|
278 | - { |
|
279 | - $query = $dbconn->select() |
|
280 | - ->from('icinga_dbversion',array('version')); |
|
281 | - $version=$dbconn->fetchRow($query); |
|
282 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
283 | - { |
|
284 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
285 | - } |
|
286 | - } |
|
287 | - catch (Exception $e) |
|
288 | - { |
|
289 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
290 | - } |
|
277 | + try |
|
278 | + { |
|
279 | + $query = $dbconn->select() |
|
280 | + ->from('icinga_dbversion',array('version')); |
|
281 | + $version=$dbconn->fetchRow($query); |
|
282 | + if ( ($version == null) || ! property_exists($version,'version') ) |
|
283 | + { |
|
284 | + throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
285 | + } |
|
286 | + } |
|
287 | + catch (Exception $e) |
|
288 | + { |
|
289 | + throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
290 | + } |
|
291 | 291 | |
292 | - return; |
|
293 | - } |
|
292 | + return; |
|
293 | + } |
|
294 | 294 | |
295 | 295 | } |
296 | 296 | \ No newline at end of file |
@@ -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 | /** |
@@ -83,19 +83,19 @@ discard block |
||
83 | 83 | * @return bool true if OK, false if version < min version |
84 | 84 | * @throws Exception if error and test = true |
85 | 85 | */ |
86 | - protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname) |
|
86 | + protected function testDbVersion($dbAdapter, int $min, bool $test, string $DBname) |
|
87 | 87 | { |
88 | 88 | try |
89 | 89 | { |
90 | - $query = $dbAdapter->select() |
|
91 | - ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value') |
|
90 | + $query=$dbAdapter->select() |
|
91 | + ->from($this->trapController->getModuleConfig()->getDbConfigTableName(), 'value') |
|
92 | 92 | ->where('name=\'db_version\''); |
93 | 93 | $version=$dbAdapter->fetchRow($query); |
94 | - if ( ($version == null) || ! property_exists($version,'value') ) |
|
94 | + if (($version == null) || !property_exists($version, 'value')) |
|
95 | 95 | { |
96 | 96 | if ($test === true) |
97 | 97 | { |
98 | - $this->testResult = array(4,$DBname); |
|
98 | + $this->testResult=array(4, $DBname); |
|
99 | 99 | return false; |
100 | 100 | } |
101 | 101 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | { |
106 | 106 | if ($test === true) |
107 | 107 | { |
108 | - $this->testResult = array(5,$version->value,$min); |
|
108 | + $this->testResult=array(5, $version->value, $min); |
|
109 | 109 | return false; |
110 | 110 | } |
111 | 111 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | { |
117 | 117 | if ($test === true) |
118 | 118 | { |
119 | - $this->testResult = array(3,$DBname,$e->getMessage()); |
|
119 | + $this->testResult=array(3, $DBname, $e->getMessage()); |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | $this->trapController->redirectNow('trapdirector/settings?dberror=4'); |
@@ -132,17 +132,17 @@ discard block |
||
132 | 132 | * @throws DBException if test = true and error |
133 | 133 | * @return Zend_Db_Adapter_Abstract|null : if test=false, returns DB connexion, else array(error_num,message) or null on error. |
134 | 134 | */ |
135 | - protected function getDbByName($DBname , $test = false , $test_version = true) |
|
135 | + protected function getDbByName($DBname, $test=false, $test_version=true) |
|
136 | 136 | { |
137 | 137 | try |
138 | 138 | { |
139 | - $dbconn = IcingaDbConnection::fromResourceName($DBname); |
|
139 | + $dbconn=IcingaDbConnection::fromResourceName($DBname); |
|
140 | 140 | } |
141 | 141 | catch (Exception $e) |
142 | 142 | { |
143 | 143 | if ($test === true) |
144 | 144 | { |
145 | - throw new DBException(array(2,$DBname)); |
|
145 | + throw new DBException(array(2, $DBname)); |
|
146 | 146 | } |
147 | 147 | $this->trapController->redirectNow('trapdirector/settings?dberror=2'); |
148 | 148 | return null; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | { |
158 | 158 | if ($test === true) |
159 | 159 | { |
160 | - throw new DBException(array(3,$DBname,$e->getMessage())); |
|
160 | + throw new DBException(array(3, $DBname, $e->getMessage())); |
|
161 | 161 | } |
162 | 162 | $this->trapController->redirectNow('trapdirector/settings?dberror=3'); |
163 | 163 | return null; |
@@ -181,18 +181,18 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getDb() |
183 | 183 | { |
184 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
184 | + if ($this->trapDB != null) return $this->trapDB; |
|
185 | 185 | |
186 | 186 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
187 | 187 | |
188 | - if ( ! $dbresource ) |
|
188 | + if (!$dbresource) |
|
189 | 189 | { |
190 | 190 | $this->trapController->redirectNow('trapdirector/settings?dberror=1'); |
191 | 191 | return null; |
192 | 192 | } |
193 | 193 | |
194 | 194 | try { |
195 | - $this->trapDB = $this->getDbByName($dbresource,false,true); |
|
195 | + $this->trapDB=$this->getDbByName($dbresource, false, true); |
|
196 | 196 | } catch (DBException $e) { |
197 | 197 | return null; // Should not happen as test = false |
198 | 198 | } |
@@ -210,12 +210,12 @@ discard block |
||
210 | 210 | { |
211 | 211 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
212 | 212 | |
213 | - if ( ! $dbresource ) |
|
213 | + if (!$dbresource) |
|
214 | 214 | { |
215 | - throw new DBException(array(1,'')); |
|
215 | + throw new DBException(array(1, '')); |
|
216 | 216 | } |
217 | 217 | |
218 | - $this->trapDB = $this->getDbByName($dbresource,true,true); |
|
218 | + $this->trapDB=$this->getDbByName($dbresource, true, true); |
|
219 | 219 | return; |
220 | 220 | } |
221 | 221 | |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | { |
229 | 229 | if ($this->idoDB != null && $test === false) return $this->idoDB; |
230 | 230 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
231 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
231 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
232 | 232 | |
233 | - if ( ! $dbresource ) |
|
233 | + if (!$dbresource) |
|
234 | 234 | { |
235 | 235 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
236 | 236 | return null; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | |
239 | 239 | try |
240 | 240 | { |
241 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
241 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
242 | 242 | } |
243 | 243 | catch (Exception $e) |
244 | 244 | { |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | return null; |
247 | 247 | } |
248 | 248 | |
249 | - $this->idoDB = $dbconn->getDbAdapter(); |
|
249 | + $this->idoDB=$dbconn->getDbAdapter(); |
|
250 | 250 | return $this->idoDB; |
251 | 251 | } |
252 | 252 | |
@@ -258,35 +258,35 @@ discard block |
||
258 | 258 | public function testGetIdoDb() |
259 | 259 | { |
260 | 260 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
261 | - $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
|
261 | + $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase'); ; |
|
262 | 262 | |
263 | - if ( ! $dbresource ) |
|
263 | + if (!$dbresource) |
|
264 | 264 | { |
265 | - throw new DBException(array(1,'No database in config.ini')); |
|
265 | + throw new DBException(array(1, 'No database in config.ini')); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | try |
269 | 269 | { |
270 | - $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
|
270 | + $dbconn=IcingaDbConnection::fromResourceName($dbresource); |
|
271 | 271 | } |
272 | 272 | catch (Exception $e) |
273 | 273 | { |
274 | - throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
|
274 | + throw new DBException(array(2, "Database $dbresource does not exists in IcingaWeb2")); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | try |
278 | 278 | { |
279 | - $query = $dbconn->select() |
|
280 | - ->from('icinga_dbversion',array('version')); |
|
279 | + $query=$dbconn->select() |
|
280 | + ->from('icinga_dbversion', array('version')); |
|
281 | 281 | $version=$dbconn->fetchRow($query); |
282 | - if ( ($version == null) || ! property_exists($version,'version') ) |
|
282 | + if (($version == null) || !property_exists($version, 'version')) |
|
283 | 283 | { |
284 | - throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
|
284 | + throw new DBException(array(4, "$dbresource does not look like an IDO database")); |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 | catch (Exception $e) |
288 | 288 | { |
289 | - throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
|
289 | + throw new DBException(array(3, "Error connecting to $dbresource : ".$e->getMessage())); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | return; |
@@ -111,8 +111,7 @@ discard block |
||
111 | 111 | $this->trapController->redirectNow('trapdirector/settings?dberror=5'); |
112 | 112 | return false; |
113 | 113 | } |
114 | - } |
|
115 | - catch (Exception $e) |
|
114 | + } catch (Exception $e) |
|
116 | 115 | { |
117 | 116 | if ($test === true) |
118 | 117 | { |
@@ -137,8 +136,7 @@ discard block |
||
137 | 136 | try |
138 | 137 | { |
139 | 138 | $dbconn = IcingaDbConnection::fromResourceName($DBname); |
140 | - } |
|
141 | - catch (Exception $e) |
|
139 | + } catch (Exception $e) |
|
142 | 140 | { |
143 | 141 | if ($test === true) |
144 | 142 | { |
@@ -152,8 +150,7 @@ discard block |
||
152 | 150 | { |
153 | 151 | $dbAdapter=$dbconn->getDbAdapter(); |
154 | 152 | |
155 | - } |
|
156 | - catch (Exception $e) |
|
153 | + } catch (Exception $e) |
|
157 | 154 | { |
158 | 155 | if ($test === true) |
159 | 156 | { |
@@ -181,7 +178,9 @@ discard block |
||
181 | 178 | */ |
182 | 179 | public function getDb() |
183 | 180 | { |
184 | - if ( $this->trapDB != null ) return $this->trapDB; |
|
181 | + if ( $this->trapDB != null ) { |
|
182 | + return $this->trapDB; |
|
183 | + } |
|
185 | 184 | |
186 | 185 | $dbresource=$this->trapController->Config()->get('config', 'database'); |
187 | 186 | |
@@ -226,7 +225,9 @@ discard block |
||
226 | 225 | */ |
227 | 226 | public function getIdoDb($test=false) |
228 | 227 | { |
229 | - if ($this->idoDB != null && $test === false) return $this->idoDB; |
|
228 | + if ($this->idoDB != null && $test === false) { |
|
229 | + return $this->idoDB; |
|
230 | + } |
|
230 | 231 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
231 | 232 | $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');; |
232 | 233 | |
@@ -239,8 +240,7 @@ discard block |
||
239 | 240 | try |
240 | 241 | { |
241 | 242 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
242 | - } |
|
243 | - catch (Exception $e) |
|
243 | + } catch (Exception $e) |
|
244 | 244 | { |
245 | 245 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
246 | 246 | return null; |
@@ -268,8 +268,7 @@ discard block |
||
268 | 268 | try |
269 | 269 | { |
270 | 270 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
271 | - } |
|
272 | - catch (Exception $e) |
|
271 | + } catch (Exception $e) |
|
273 | 272 | { |
274 | 273 | throw new DBException( array(2,"Database $dbresource does not exists in IcingaWeb2") ); |
275 | 274 | } |
@@ -283,8 +282,7 @@ discard block |
||
283 | 282 | { |
284 | 283 | throw new DBException( array(4,"$dbresource does not look like an IDO database")); |
285 | 284 | } |
286 | - } |
|
287 | - catch (Exception $e) |
|
285 | + } catch (Exception $e) |
|
288 | 286 | { |
289 | 287 | throw new DBException( array(3,"Error connecting to $dbresource : " . $e->getMessage())); |
290 | 288 | } |