Skip to content

Commit

Permalink
Wrap report message registration in a specific method
Browse files Browse the repository at this point in the history
refs #7163
  • Loading branch information
Johannes Meyer committed Oct 7, 2014
1 parent 627a19a commit 1136a09
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions library/Icinga/Application/WebInstaller.php
Expand Up @@ -52,46 +52,28 @@ public function run()
$configIniPath = Config::resolvePath('config.ini');
try {
$this->writeConfigIni($configIniPath);
$this->report[] = (object) array(
'state' => true,
'message' => sprintf(t('Successfully created: %s'), $configIniPath)
);
$this->log(sprintf(t('Successfully created: %s'), $configIniPath));
} catch (Exception $e) {
$success = false;
$this->report[] = (object) array(
'state' => false,
'message' => sprintf(t('Unable to create: %s (%s)'), $configIniPath, $e->getMessage())
);
$this->log(sprintf(t('Unable to create: %s (%s)'), $configIniPath, $e->getMessage()), false);
}

$resourcesIniPath = Config::resolvePath('resources.ini');
try {
$this->writeResourcesIni($resourcesIniPath);
$this->report[] = (object) array(
'state' => true,
'message' => sprintf(t('Successfully created: %s'), $resourcesIniPath)
);
$this->log(sprintf(t('Successfully created: %s'), $resourcesIniPath));
} catch (Exception $e) {
$success = false;
$this->report[] = (object) array(
'state' => false,
'message' => sprintf(t('Unable to create: %s (%s)'), $resourcesIniPath, $e->getMessage())
);
$this->log(sprintf(t('Unable to create: %s (%s)'), $resourcesIniPath, $e->getMessage()), false);
}

$authenticationIniPath = Config::resolvePath('authentication.ini');
try {
$this->writeAuthenticationIni($authenticationIniPath);
$this->report[] = (object) array(
'state' => true,
'message' => sprintf(t('Successfully created: %s'), $authenticationIniPath)
);
$this->log(sprintf(t('Successfully created: %s'), $authenticationIniPath));
} catch (Exception $e) {
$success = false;
$this->report[] = (object) array(
'state' => false,
'message' => sprintf(t('Unable to create: %s (%s)'), $authenticationIniPath, $e->getMessage())
);
$this->log(sprintf(t('Unable to create: %s (%s)'), $authenticationIniPath, $e->getMessage()), false);
}

return $success;
Expand Down Expand Up @@ -365,7 +347,10 @@ public function getSummary()
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".'),
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']
);
Expand Down Expand Up @@ -394,4 +379,18 @@ public function getReport()
{
return $this->report;
}

/**
* Add a message to the report
*
* @param string $message The message to add
* @param bool $success Whether the message represents a success (true) or a failure (false)
*/
protected function log($message, $success = true)
{
$this->report[] = (object) array(
'state' => (bool) $success,
'message' => $message
);
}
}

0 comments on commit 1136a09

Please sign in to comment.