wizard: Show a warning if the IDO is used for the internal database

resolves #9653
This commit is contained in:
Johannes Meyer 2015-08-28 15:25:21 +02:00
parent 85a4c67705
commit ded6666897
2 changed files with 42 additions and 25 deletions

View File

@ -3,7 +3,7 @@
namespace Icinga\Module\Setup\Forms; namespace Icinga\Module\Setup\Forms;
use PDOException; use Exception;
use Icinga\Web\Form; use Icinga\Web\Form;
use Icinga\Forms\Config\Resource\DbResourceForm; use Icinga\Forms\Config\Resource\DbResourceForm;
use Icinga\Module\Setup\Utils\DbTool; use Icinga\Module\Setup\Utils\DbTool;
@ -112,7 +112,7 @@ class DbResourcePage extends Form
try { try {
$db = new DbTool($this->getValues()); $db = new DbTool($this->getValues());
$db->checkConnectivity(); $db->checkConnectivity();
} catch (PDOException $e) { } catch (Exception $e) {
$this->error(sprintf( $this->error(sprintf(
$this->translate('Failed to successfully validate the configuration: %s'), $this->translate('Failed to successfully validate the configuration: %s'),
$e->getMessage() $e->getMessage()
@ -120,22 +120,36 @@ class DbResourcePage extends Form
return false; return false;
} }
if ($this->getValue('db') === 'pgsql') { $state = true;
if (! $db->isConnected()) { $connectionError = null;
try { try {
$db->connectToDb(); $db->connectToDb();
} catch (PDOException $e) { } catch (Exception $e) {
$connectionError = $e;
}
if ($connectionError === null && array_search('icinga_instances', $db->listTables(), true) !== false) {
$this->warning($this->translate(
'The database you\'ve configured to use for Icinga Web 2 seems to be the one of Icinga. Please be aware'
. ' that this database configuration is supposed to be used for Icinga Web 2\'s configuration and that'
. ' it is highly recommended to not mix different schemas in the same database. If this is intentional,'
. ' you can skip the validation and ignore this warning. If not, please provide a different database.'
));
$state = false;
}
if ($this->getValue('db') === 'pgsql') {
if ($connectionError !== null) {
$this->warning($this->translate(sprintf( $this->warning($this->translate(sprintf(
'Unable to check the server\'s version. This is usually not a critical error as there is' 'Unable to check the server\'s version. This is usually not a critical error as there is'
. ' probably only access to the database permitted which does not exist yet. If you are' . ' probably only access to the database permitted which does not exist yet. If you are'
. ' absolutely sure you are running PostgreSQL in a version equal to or newer than 9.1,' . ' absolutely sure you are running PostgreSQL in a version equal to or newer than 9.1,'
. ' you can skip the validation and safely proceed to the next step. The error was: %s', . ' you can skip the validation and safely proceed to the next step. The error was: %s',
$e->getMessage() $connectionError->getMessage()
))); )));
return false; $state = false;
} } else {
}
$version = $db->getServerVersion(); $version = $db->getServerVersion();
if (version_compare($version, '9.1', '<')) { if (version_compare($version, '9.1', '<')) {
$this->error($this->translate(sprintf( $this->error($this->translate(sprintf(
@ -143,11 +157,12 @@ class DbResourcePage extends Form
$version, $version,
'9.1' '9.1'
))); )));
return false; $state = false;
}
} }
} }
return true; return $state;
} }
/** /**

View File

@ -271,6 +271,8 @@ class DbTool
$this->config['db'] $this->config['db']
); );
} }
$this->zendConn->getConnection(); // Force connection attempt
} }
/** /**