From 33a64eb55af9943d10c9a3a072fd2363e68e96ec Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 29 Oct 2014 15:45:26 +0100 Subject: [PATCH] Do not throw an exception in DbTool due to an implementation detail Throwing exceptions due to failing logic which is purely an implementation detail must not affect the calling code in any way. refs #7163 --- library/Icinga/Web/Setup/DbTool.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/library/Icinga/Web/Setup/DbTool.php b/library/Icinga/Web/Setup/DbTool.php index 650cd7bda..6155f7740 100644 --- a/library/Icinga/Web/Setup/DbTool.php +++ b/library/Icinga/Web/Setup/DbTool.php @@ -4,7 +4,6 @@ namespace Icinga\Web\Setup; -use Icinga\Exception\ProgrammingError; use PDO; use PDOException; use LogicException; @@ -66,7 +65,6 @@ class DbTool // Therefore, we specify the maintenance database 'postgres' as database, which // is most probably present and public. $this->connect('postgres'); - } else { $this->connect(); } @@ -387,13 +385,11 @@ class DbTool * 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 @@ -404,12 +400,9 @@ class DbTool $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(