Skip to content

Commit

Permalink
Create configuration sub directories as part of the setup wizard
Browse files Browse the repository at this point in the history
refs #7163
  • Loading branch information
Johannes Meyer committed Oct 29, 2014
1 parent 85f7dcf commit 98acc24
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 1 deletion.
102 changes: 102 additions & 0 deletions library/Icinga/Application/Installation/MakeDirStep.php
@@ -0,0 +1,102 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Application\Installation;

use Icinga\Web\Setup\Step;

class MakeDirStep extends Step
{
protected $paths;

protected $dirmode;

protected $errors;

/**
* @param array $paths
* @param string $dirmode
*/
public function __construct($paths, $dirmode)
{
$this->paths = $paths;
$this->dirmode = octdec($dirmode) | octdec('111'); // Make sure that the directories can be traversed
$this->errors = array();
}

public function apply()
{
$success = true;
foreach ($this->paths as $path) {
if (false === file_exists($path)) {
if (false === @mkdir($path)) {
$this->errors[$path] = error_get_last();
$success = false;
} else {
$this->errors[$path] = null;
$old = umask(0);
chmod($path, $this->dirmode);
umask($old);
}
}
}

return $success;
}

public function getSummary()
{
$pageHtml = '';
$pageTitle = t('Directory Creation');
$createMsg = t('The setup will create the following directories:');
$existsMsg = t('The setup does not need to create the following already existing directories:');

$toBeCreated = array_filter($this->paths, function ($p) { return false === file_exists($p); });
if (false === empty($toBeCreated)) {
$pageHtml .= '<p>' . $createMsg . '</p>';

$pageHtml .= '<ul>';
foreach ($toBeCreated as $path) {
$pageHtml .= '<li>' . $path . '</li>';
}
$pageHtml .= '</ul>';
}

$existing = array_diff($this->paths, $toBeCreated);
if (false === empty($existing)) {
$pageHtml .= '<p>' . $existsMsg . '</p>';

$pageHtml .= '<ul>';
foreach ($existing as $path) {
$pageHtml .= '<li>' . $path . '</li>';
}
$pageHtml .= '</ul>';
}

return '<h2>' . $pageTitle . '</h2>' . $pageHtml;
}

public function getReport()
{
$okMessage = t('Directory "%s" in "%s" has been successfully created.');
$existsMessage = t('Directory "%s" does already exist in "%s". Nothing to do.');
$failMessage = t('Unable to create directory "%s" in "%s". An error occured:');

$report = '';
foreach ($this->paths as $path) {
if (array_key_exists($path, $this->errors)) {
if (is_array($this->errors[$path])) {
$report .= '<p class="error">' . sprintf($failMessage, basename($path), dirname($path)) . '</p>'
. '<p>' . $this->errors[$path]['message'] . '</p>';
} else {
$report .= '<p>' . sprintf($okMessage, basename($path), dirname($path)) . '</p>';
}
} else {
$report .= '<p>' . sprintf($existsMessage, basename($path), dirname($path)) . '</p>';
}
}

return $report;
}
}
14 changes: 13 additions & 1 deletion library/Icinga/Application/WebSetup.php
Expand Up @@ -19,6 +19,7 @@
use Icinga\Form\Setup\GeneralConfigPage;
use Icinga\Form\Setup\AuthenticationPage;
use Icinga\Form\Setup\DatabaseCreationPage;
use Icinga\Application\Installation\MakeDirStep;
use Icinga\Application\Installation\DatabaseStep;
use Icinga\Application\Installation\GeneralConfigStep;
use Icinga\Application\Installation\ResourceStep;
Expand Down Expand Up @@ -313,6 +314,18 @@ public function getInstaller()
);
}

$configDir = $this->getConfigDir();
$installer->addStep(
new MakeDirStep(
array(
$configDir . '/modules',
$configDir . '/preferences',
$configDir . '/enabledModules'
),
$pageData['setup_general_config']['global_filemode']
)
);

foreach ($this->getPage('setup_modules')->getWizards() as $wizard) {
if ($wizard->isFinished()) {
$installer->addSteps($wizard->getInstaller()->getSteps());
Expand Down Expand Up @@ -410,7 +423,6 @@ public function getRequirements()
$pgsqlAdapterFound ? t('The Zend database adapter for PostgreSQL is available.') : (
t('The Zend database adapter for PostgreSQL is missing.')
)

);

$defaultTimezone = Platform::getPhpConfig('date.timezone');
Expand Down

0 comments on commit 98acc24

Please sign in to comment.