Improve the db-summary text and db-creation/-resource step handling

refs #7163
This commit is contained in:
Johannes Meyer 2014-10-08 15:36:26 +02:00
parent 8fa8642917
commit 7c202dd8fa

View File

@ -8,8 +8,6 @@ use Exception;
use Zend_Config; use Zend_Config;
use PDOException; use PDOException;
use Icinga\Web\Setup\DbTool; use Icinga\Web\Setup\DbTool;
use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Web\Setup\Installer; use Icinga\Web\Setup\Installer;
use Icinga\Data\ResourceFactory; use Icinga\Data\ResourceFactory;
use Icinga\Config\PreservingIniWriter; use Icinga\Config\PreservingIniWriter;
@ -52,7 +50,12 @@ class WebInstaller implements Installer
{ {
$success = true; $success = true;
if (isset($this->pageData['setup_db_resource']) && ! $this->pageData['setup_db_resource']['skip_validation']) { if (isset($this->pageData['setup_db_resource'])
&& ! $this->pageData['setup_db_resource']['skip_validation']
&& (false === isset($this->pageData['setup_database_creation'])
|| ! $this->pageData['setup_database_creation']['skip_validation']
)
) {
try { try {
$this->setupDatabase(); $this->setupDatabase();
} catch (Exception $e) { } catch (Exception $e) {
@ -92,10 +95,10 @@ class WebInstaller implements Installer
try { try {
$this->setupAdminAccount(); $this->setupAdminAccount();
$this->log(t('Successfully created initial administrative account.')); $this->log(t('Successfully defined initial administrative account.'));
} catch (Exception $e) { } catch (Exception $e) {
$success = false; $success = false;
$this->log(sprintf(t('Failed to create initial administrative account: %s'), $e->getMessage())); $this->log(sprintf(t('Failed to define initial administrative account: %s'), $e->getMessage()), false);
} }
return $success; return $success;
@ -361,11 +364,16 @@ class WebInstaller implements Installer
} }
/** /**
* Create the initial administrative account * Define the initial administrative account
*/ */
protected function setupAdminAccount() protected function setupAdminAccount()
{ {
if ($this->pageData['setup_admin_account']['user_type'] === 'new_user') { if ($this->pageData['setup_admin_account']['user_type'] === 'new_user'
&& ! $this->pageData['setup_db_resource']['skip_validation']
&& (false === isset($this->pageData['setup_database_creation'])
|| ! $this->pageData['setup_database_creation']['skip_validation']
)
) {
$backend = new DbUserBackend( $backend = new DbUserBackend(
ResourceFactory::createResource(new Zend_Config($this->pageData['setup_db_resource'])) ResourceFactory::createResource(new Zend_Config($this->pageData['setup_db_resource']))
); );
@ -528,36 +536,67 @@ class WebInstaller implements Installer
) )
); );
if (isset($this->pageData['setup_database_creation'])) { if (isset($this->pageData['setup_db_resource'])) {
$setupDatabase = true;
$resourceConfig = $this->pageData['setup_db_resource']; $resourceConfig = $this->pageData['setup_db_resource'];
if (isset($this->pageData['setup_database_creation'])) {
$resourceConfig['username'] = $this->pageData['setup_database_creation']['username']; $resourceConfig['username'] = $this->pageData['setup_database_creation']['username'];
$resourceConfig['password'] = $this->pageData['setup_database_creation']['password']; $resourceConfig['password'] = $this->pageData['setup_database_creation']['password'];
$db = new DbTool($resourceConfig); }
if ($setupDatabase) {
$db = new DbTool($resourceConfig);
try { try {
$db->connectToDb(); $db->connectToDb();
if (array_search('account', $db->listTables()) === false) {
$message = sprintf( $message = sprintf(
t( t(
'The database user "%s" will be used to setup the missing' 'The database user "%s" will be used to setup the missing'
. ' schema required by Icinga Web 2 in database "%s".' . ' schema required by Icinga Web 2 in database "%s".'
), ),
$this->pageData['setup_database_creation']['username'], $resourceConfig['username'],
$resourceConfig['dbname'] $resourceConfig['dbname']
); );
} else {
$message = sprintf(
t('The database "%s" already seems to be fully set up. No action required.'),
$resourceConfig['dbname']
);
}
} catch (PDOException $e) { } catch (PDOException $e) {
try {
$db->connectToHost();
if ($db->hasLogin($this->pageData['setup_db_resource']['username'])) {
$message = sprintf(
t(
'The database user "%s" will be used to create the missing '
. 'database "%s" with the schema required by Icinga Web 2.'
),
$resourceConfig['username'],
$resourceConfig['dbname']
);
} else {
$message = sprintf( $message = sprintf(
t( t(
'The database user "%s" will be used to create the missing database "%s" ' 'The database user "%s" will be used to create the missing database "%s" '
. 'with the schema required by Icinga Web 2 and a new login called "%s".' . 'with the schema required by Icinga Web 2 and a new login called "%s".'
), ),
$this->pageData['setup_database_creation']['username'], $resourceConfig['username'],
$resourceConfig['dbname'], $resourceConfig['dbname'],
$this->pageData['setup_db_resource']['username'] $this->pageData['setup_db_resource']['username']
); );
} }
} catch (PDOException $e) {
$message = t(
'No connection to database host possible. You\'ll need to setup the'
. ' database with the schema required by Icinga Web 2 manually.'
);
}
}
$summary[t('Database Setup')] = $message; $summary[t('Database Setup')] = $message;
} }
}
return $summary; return $summary;
} }