From 98acc2486992987af6eddcbe9795ff5f77c5ce1f Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 28 Oct 2014 09:36:08 +0100 Subject: [PATCH] Create configuration sub directories as part of the setup wizard refs #7163 --- .../Application/Installation/MakeDirStep.php | 102 ++++++++++++++++++ library/Icinga/Application/WebSetup.php | 14 ++- 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 library/Icinga/Application/Installation/MakeDirStep.php diff --git a/library/Icinga/Application/Installation/MakeDirStep.php b/library/Icinga/Application/Installation/MakeDirStep.php new file mode 100644 index 0000000000..3d9232d0eb --- /dev/null +++ b/library/Icinga/Application/Installation/MakeDirStep.php @@ -0,0 +1,102 @@ +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 .= '

' . $createMsg . '

'; + + $pageHtml .= ''; + } + + $existing = array_diff($this->paths, $toBeCreated); + if (false === empty($existing)) { + $pageHtml .= '

' . $existsMsg . '

'; + + $pageHtml .= ''; + } + + return '

' . $pageTitle . '

' . $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 .= '

' . sprintf($failMessage, basename($path), dirname($path)) . '

' + . '

' . $this->errors[$path]['message'] . '

'; + } else { + $report .= '

' . sprintf($okMessage, basename($path), dirname($path)) . '

'; + } + } else { + $report .= '

' . sprintf($existsMessage, basename($path), dirname($path)) . '

'; + } + } + + return $report; + } +} diff --git a/library/Icinga/Application/WebSetup.php b/library/Icinga/Application/WebSetup.php index c2a609f23c..770a0b14fb 100644 --- a/library/Icinga/Application/WebSetup.php +++ b/library/Icinga/Application/WebSetup.php @@ -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; @@ -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()); @@ -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');