Skip to content

Commit

Permalink
Do not throw an exception in DbTool due to an implementation detail
Browse files Browse the repository at this point in the history
Throwing exceptions due to failing logic which is purely an implementation
detail must not affect the calling code in any way.

refs #7163
  • Loading branch information
Johannes Meyer committed Oct 29, 2014
1 parent 47d9426 commit 33a64eb
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions library/Icinga/Web/Setup/DbTool.php
Expand Up @@ -4,7 +4,6 @@

namespace Icinga\Web\Setup;

use Icinga\Exception\ProgrammingError;
use PDO;
use PDOException;
use LogicException;
Expand Down Expand Up @@ -66,7 +65,6 @@ public function connectToHost()
// Therefore, we specify the maintenance database 'postgres' as database, which
// is most probably present and public.
$this->connect('postgres');

} else {
$this->connect();
}
Expand Down Expand Up @@ -387,13 +385,11 @@ public function listTables()
* Return whether the given database login exists
*
* @param string $username The username to search
* @param string $password The username to login
* @param string $password The password for user $username, required in case it's a MySQL database
*
* @return bool
* @throws PDOException When logging in is not possible due to an Exception not related
* to authentication
*/
public function hasLogin($username, $password)
public function hasLogin($username, $password = null)
{
if ($this->config['db'] === 'mysql') {
// probe login by trial and error since we don't know our host name or it may be globbed
Expand All @@ -404,12 +400,9 @@ public function hasLogin($username, $password)
$probe = new DbTool($probeConf);
$probe->connectToHost();
} catch (PDOException $e) {
$code = $e->getCode();
if ($code === 1045 || $code === 1044) {
return false;
}
throw $e;
return false;
}

return true;
} elseif ($this->config['db'] === 'pgsql') {
$rowCount = $this->exec(
Expand Down

0 comments on commit 33a64eb

Please sign in to comment.