Passed
Push — master ( 993560...e6d07d )
by Patrick
01:57
created
library/Trapdirector/TrapsActions/UIDatabase.php 3 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
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,189 +52,189 @@  discard block
 block discarded – undo
52 52
 class UIDatabase
53 53
 {
54 54
     
55
-    /** @var TrapsController $trapController TrapController 'parent' class */
56
-    private  $trapController;
55
+	/** @var TrapsController $trapController TrapController 'parent' class */
56
+	private  $trapController;
57 57
     
58
-    /** @var Zend_Db_Adapter_Abstract $trapDB Trap Database*/
59
-    private $trapDB;
58
+	/** @var Zend_Db_Adapter_Abstract $trapDB Trap Database*/
59
+	private $trapDB;
60 60
  
61
-    /** @var Zend_Db_Adapter_Abstract $trapDB Icinga IDO database*/
62
-    private $idoDB;
61
+	/** @var Zend_Db_Adapter_Abstract $trapDB Icinga IDO database*/
62
+	private $idoDB;
63 63
     
64
-    /**
65
-     * 
66
-     * @param TrapsController $trapCtrl
67
-     */
68
-    function __construct(TrapsController $trapCtrl)
69
-    {
70
-        $this->trapController=$trapCtrl;
71
-    }
64
+	/**
65
+	 * 
66
+	 * @param TrapsController $trapCtrl
67
+	 */
68
+	function __construct(TrapsController $trapCtrl)
69
+	{
70
+		$this->trapController=$trapCtrl;
71
+	}
72 72
     
73
-    /**
74
-     * Test if database version >= min database version
75
-     * 
76
-     * @param \Zend_Db_Adapter_Abstract $dbConn
77
-     * @param int $min Minimum version
78
-     * @param bool $test Test mode
79
-     * @param string $DBname Name of DB
80
-     * @throws DBException if test = true
81
-     */
82
-    protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
83
-    {
84
-        try
85
-        {
86
-            $query = $dbAdapter->select()
87
-            ->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
88
-            ->where('name=\'db_version\'');
89
-            $version=$dbAdapter->fetchRow($query);
90
-            if ( ($version == null) || ! property_exists($version,'value') )
91
-            {
92
-                if ($test === true) 
93
-                {
94
-                    throw new DBException(array(4,$DBname));
95
-                }
96
-                $this->trapController->redirectNow('trapdirector/settings?dberror=4');
97
-                exit(0);
98
-            }
99
-            if ($version->value < $min)
100
-            {
101
-                if ($test === true) 
102
-                {
103
-                    throw new DBException(array(5,$version->value,$min));
104
-                }
105
-                $this->trapController->redirectNow('trapdirector/settings?dberror=5');
106
-                exit(0);
107
-            }
108
-        }
109
-        catch (Exception $e)
110
-        {
111
-            if ($test === true) 
112
-            {
113
-                throw new DBException(array(3,$DBname,$e->getMessage()));
114
-            }
115
-            $this->trapController->redirectNow('trapdirector/settings?dberror=4');
116
-        }
117
-        return;
118
-    }
73
+	/**
74
+	 * Test if database version >= min database version
75
+	 * 
76
+	 * @param \Zend_Db_Adapter_Abstract $dbConn
77
+	 * @param int $min Minimum version
78
+	 * @param bool $test Test mode
79
+	 * @param string $DBname Name of DB
80
+	 * @throws DBException if test = true
81
+	 */
82
+	protected function testDbVersion($dbAdapter,int $min,bool $test, string $DBname)
83
+	{
84
+		try
85
+		{
86
+			$query = $dbAdapter->select()
87
+			->from($this->trapController->getModuleConfig()->getDbConfigTableName(),'value')
88
+			->where('name=\'db_version\'');
89
+			$version=$dbAdapter->fetchRow($query);
90
+			if ( ($version == null) || ! property_exists($version,'value') )
91
+			{
92
+				if ($test === true) 
93
+				{
94
+					throw new DBException(array(4,$DBname));
95
+				}
96
+				$this->trapController->redirectNow('trapdirector/settings?dberror=4');
97
+				exit(0);
98
+			}
99
+			if ($version->value < $min)
100
+			{
101
+				if ($test === true) 
102
+				{
103
+					throw new DBException(array(5,$version->value,$min));
104
+				}
105
+				$this->trapController->redirectNow('trapdirector/settings?dberror=5');
106
+				exit(0);
107
+			}
108
+		}
109
+		catch (Exception $e)
110
+		{
111
+			if ($test === true) 
112
+			{
113
+				throw new DBException(array(3,$DBname,$e->getMessage()));
114
+			}
115
+			$this->trapController->redirectNow('trapdirector/settings?dberror=4');
116
+		}
117
+		return;
118
+	}
119 119
     
120
-    /**	Get Database connexion
121
-     *	@param $DBname string DB name in resource.ini_ge
122
-     *	@param $test bool if set to true, returns error code and not database
123
-     *	@param $test_version bool if set to flase, does not test database version of trapDB
124
-     *	@return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
125
-     */
126
-    protected function getDbByName($DBname,$test=false,$test_version=true)
127
-    {
128
-        try
129
-        {
130
-            $dbconn = IcingaDbConnection::fromResourceName($DBname);
131
-        }
132
-        catch (Exception $e)
133
-        {
134
-            if ($test) return array(2,$DBname);
135
-            $this->trapController->redirectNow('trapdirector/settings?dberror=2');
136
-            return null;
137
-        }
120
+	/**	Get Database connexion
121
+	 *	@param $DBname string DB name in resource.ini_ge
122
+	 *	@param $test bool if set to true, returns error code and not database
123
+	 *	@param $test_version bool if set to flase, does not test database version of trapDB
124
+	 *	@return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
125
+	 */
126
+	protected function getDbByName($DBname,$test=false,$test_version=true)
127
+	{
128
+		try
129
+		{
130
+			$dbconn = IcingaDbConnection::fromResourceName($DBname);
131
+		}
132
+		catch (Exception $e)
133
+		{
134
+			if ($test) return array(2,$DBname);
135
+			$this->trapController->redirectNow('trapdirector/settings?dberror=2');
136
+			return null;
137
+		}
138 138
 
139
-        try
140
-        {
141
-            $dbAdapter=$dbconn->getDbAdapter();
139
+		try
140
+		{
141
+			$dbAdapter=$dbconn->getDbAdapter();
142 142
             
143
-        }
144
-        catch (Exception $e)
145
-        {
146
-            if ($test) return array(3,$DBname,$e->getMessage());
147
-            $this->trapController->redirectNow('trapdirector/settings?dberror=3');
148
-            return null;
149
-        }
143
+		}
144
+		catch (Exception $e)
145
+		{
146
+			if ($test) return array(3,$DBname,$e->getMessage());
147
+			$this->trapController->redirectNow('trapdirector/settings?dberror=3');
148
+			return null;
149
+		}
150 150
         
151
-        if ($test_version == true) {
152
-            $testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname);
153
-            if ($testRet != null) 
154
-            {
155
-                return $testRet;
156
-            }
157
-        }
158
-        if ($test) return array(0,'');
159
-        return $dbAdapter;
160
-    }
151
+		if ($test_version == true) {
152
+			$testRet=$this->testDbVersion($dbAdapter, $this->trapController->getModuleConfig()->getDbMinVersion(), $test, $DBname);
153
+			if ($testRet != null) 
154
+			{
155
+				return $testRet;
156
+			}
157
+		}
158
+		if ($test) return array(0,'');
159
+		return $dbAdapter;
160
+	}
161 161
 
162
-    /**
163
-     * Get Trap database
164
-     * @param boolean $test
165
-     * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
166
-     */
167
-    public function getDb($test=false)
168
-    {
169
-        if ($this->trapDB != null && $test = false) return $this->trapDB;
162
+	/**
163
+	 * Get Trap database
164
+	 * @param boolean $test
165
+	 * @return Zend_Db_Adapter_Abstract|array|null : if test=false, returns DB connexion, else array(error_num,message) or null on error.
166
+	 */
167
+	public function getDb($test=false)
168
+	{
169
+		if ($this->trapDB != null && $test = false) return $this->trapDB;
170 170
         
171
-        $dbresource=$this->trapController->Config()->get('config', 'database');
171
+		$dbresource=$this->trapController->Config()->get('config', 'database');
172 172
         
173
-        if ( ! $dbresource )
174
-        {
175
-            if ($test) return array(1,'');
176
-            $this->trapController->redirectNow('trapdirector/settings?dberror=1');
177
-            return null;
178
-        }
179
-        $retDB=$this->getDbByName($dbresource,$test,true);
173
+		if ( ! $dbresource )
174
+		{
175
+			if ($test) return array(1,'');
176
+			$this->trapController->redirectNow('trapdirector/settings?dberror=1');
177
+			return null;
178
+		}
179
+		$retDB=$this->getDbByName($dbresource,$test,true);
180 180
         
181
-        if ($test === true) return $retDB;
181
+		if ($test === true) return $retDB;
182 182
         
183
-        $this->trapDB=$retDB;
184
-        return $this->trapDB;
185
-    }
183
+		$this->trapDB=$retDB;
184
+		return $this->trapDB;
185
+	}
186 186
     
187
-    /**
188
-     * Get IDO Database 
189
-     * @param boolean $test
190
-     * @return Zend_Db_Adapter_Abstract|array]|NULL if test=false, returns DB connexion, else array(error_num,message) or null on error.
191
-     */
192
-    public function getIdoDb($test=false)
193
-    {
194
-        if ($this->idoDB != null && $test = false) return $this->idoDB;
195
-        // TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
196
-        $dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
187
+	/**
188
+	 * Get IDO Database 
189
+	 * @param boolean $test
190
+	 * @return Zend_Db_Adapter_Abstract|array]|NULL if test=false, returns DB connexion, else array(error_num,message) or null on error.
191
+	 */
192
+	public function getIdoDb($test=false)
193
+	{
194
+		if ($this->idoDB != null && $test = false) return $this->idoDB;
195
+		// TODO : get ido database directly from icingaweb2 config -> (or not if using only API)
196
+		$dbresource=$this->trapController->Config()->get('config', 'IDOdatabase');;
197 197
         
198
-        if ( ! $dbresource )
199
-        {
200
-            if ($test) return array(1,'No database in config.ini');
201
-            $this->redirectNow('trapdirector/settings?idodberror=1');
202
-            return null;
203
-        }
198
+		if ( ! $dbresource )
199
+		{
200
+			if ($test) return array(1,'No database in config.ini');
201
+			$this->redirectNow('trapdirector/settings?idodberror=1');
202
+			return null;
203
+		}
204 204
         
205
-        try
206
-        {
207
-            $dbconn = IcingaDbConnection::fromResourceName($dbresource);
208
-        }
209
-        catch (Exception $e)
210
-        {
211
-            if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
212
-            $this->redirectNow('trapdirector/settings?idodberror=2');
213
-            return null;
214
-        }
205
+		try
206
+		{
207
+			$dbconn = IcingaDbConnection::fromResourceName($dbresource);
208
+		}
209
+		catch (Exception $e)
210
+		{
211
+			if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2");
212
+			$this->redirectNow('trapdirector/settings?idodberror=2');
213
+			return null;
214
+		}
215 215
         
216
-        if ($test === false)
217
-        {
218
-            $this->idoDB = $dbconn->getDbAdapter();
219
-            return $this->idoDB;
220
-        }
216
+		if ($test === false)
217
+		{
218
+			$this->idoDB = $dbconn->getDbAdapter();
219
+			return $this->idoDB;
220
+		}
221 221
         
222
-        try
223
-        {
224
-            $query = $dbconn->select()
225
-            ->from('icinga_dbversion',array('version'));
226
-            $version=$dbconn->fetchRow($query);
227
-            if ( ($version == null) || ! property_exists($version,'version') )
228
-            {
229
-                return array(4,"$dbresource does not look like an IDO database");
230
-            }
231
-        }
232
-        catch (Exception $e)
233
-        {
234
-            return array(3,"Error connecting to $dbresource : " . $e->getMessage());
235
-        }
222
+		try
223
+		{
224
+			$query = $dbconn->select()
225
+			->from('icinga_dbversion',array('version'));
226
+			$version=$dbconn->fetchRow($query);
227
+			if ( ($version == null) || ! property_exists($version,'version') )
228
+			{
229
+				return array(4,"$dbresource does not look like an IDO database");
230
+			}
231
+		}
232
+		catch (Exception $e)
233
+		{
234
+			return array(3,"Error connecting to $dbresource : " . $e->getMessage());
235
+		}
236 236
         
237
-        return array(0,'');
238
-    }
237
+		return array(0,'');
238
+	}
239 239
     
240 240
 }
241 241
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -24,10 +24,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
Braces   +32 added lines, -19 removed lines patch added patch discarded remove patch
@@ -105,8 +105,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.