Skip to content

Commit

Permalink
Improve the db-summary text and db-creation/-resource step handling
Browse files Browse the repository at this point in the history
refs #7163
  • Loading branch information
Johannes Meyer committed Oct 8, 2014
1 parent 8fa8642 commit 7c202dd
Showing 1 changed file with 72 additions and 33 deletions.
105 changes: 72 additions & 33 deletions library/Icinga/Application/WebInstaller.php
Expand Up @@ -8,8 +8,6 @@
use Zend_Config;
use PDOException;
use Icinga\Web\Setup\DbTool;
use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Web\Setup\Installer;
use Icinga\Data\ResourceFactory;
use Icinga\Config\PreservingIniWriter;
Expand Down Expand Up @@ -52,7 +50,12 @@ public function run()
{
$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 {
$this->setupDatabase();
} catch (Exception $e) {
Expand Down Expand Up @@ -92,10 +95,10 @@ public function run()

try {
$this->setupAdminAccount();
$this->log(t('Successfully created initial administrative account.'));
$this->log(t('Successfully defined initial administrative account.'));
} catch (Exception $e) {
$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;
Expand Down Expand Up @@ -361,11 +364,16 @@ private function setupPgsqlDatabase(DbTool $db)
}

/**
* Create the initial administrative account
* Define the initial administrative account
*/
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(
ResourceFactory::createResource(new Zend_Config($this->pageData['setup_db_resource']))
);
Expand Down Expand Up @@ -528,35 +536,66 @@ public function getSummary()
)
);

if (isset($this->pageData['setup_database_creation'])) {
if (isset($this->pageData['setup_db_resource'])) {
$setupDatabase = true;
$resourceConfig = $this->pageData['setup_db_resource'];
$resourceConfig['username'] = $this->pageData['setup_database_creation']['username'];
$resourceConfig['password'] = $this->pageData['setup_database_creation']['password'];
$db = new DbTool($resourceConfig);

try {
$db->connectToDb();
$message = sprintf(
t(
'The database user "%s" will be used to setup the missing'
. ' schema required by Icinga Web 2 in database "%s".'
),
$this->pageData['setup_database_creation']['username'],
$resourceConfig['dbname']
);
} catch (PDOException $e) {
$message = sprintf(
t(
'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".'
),
$this->pageData['setup_database_creation']['username'],
$resourceConfig['dbname'],
$this->pageData['setup_db_resource']['username']
);
if (isset($this->pageData['setup_database_creation'])) {
$resourceConfig['username'] = $this->pageData['setup_database_creation']['username'];
$resourceConfig['password'] = $this->pageData['setup_database_creation']['password'];
}

$summary[t('Database Setup')] = $message;
if ($setupDatabase) {
$db = new DbTool($resourceConfig);
try {
$db->connectToDb();
if (array_search('account', $db->listTables()) === false) {
$message = sprintf(
t(
'The database user "%s" will be used to setup the missing'
. ' schema required by Icinga Web 2 in database "%s".'
),
$resourceConfig['username'],
$resourceConfig['dbname']
);
} else {
$message = sprintf(
t('The database "%s" already seems to be fully set up. No action required.'),
$resourceConfig['dbname']
);
}
} 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(
t(
'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".'
),
$resourceConfig['username'],
$resourceConfig['dbname'],
$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;
}
}

return $summary;
Expand Down

0 comments on commit 7c202dd

Please sign in to comment.