2014-10-28 09:36:08 +01:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-11-10 16:31:40 +01:00
|
|
|
namespace Icinga\Module\Setup\Utils;
|
|
|
|
|
|
|
|
use Icinga\Module\Setup\Step;
|
2014-10-28 09:36:08 +01:00
|
|
|
|
|
|
|
class MakeDirStep extends Step
|
|
|
|
{
|
|
|
|
protected $paths;
|
|
|
|
|
|
|
|
protected $dirmode;
|
|
|
|
|
|
|
|
protected $errors;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $paths
|
2014-11-12 09:18:19 +01:00
|
|
|
* @param int $dirmode
|
2014-10-28 09:36:08 +01:00
|
|
|
*/
|
|
|
|
public function __construct($paths, $dirmode)
|
|
|
|
{
|
|
|
|
$this->paths = $paths;
|
2014-11-12 09:18:19 +01:00
|
|
|
$this->dirmode = $dirmode;
|
2014-10-28 09:36:08 +01:00
|
|
|
$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()
|
|
|
|
{
|
2014-11-10 10:30:52 +01:00
|
|
|
// This step is usually being used for directories which are required for the configuration but
|
|
|
|
// are not defined in any way by the user. So there is no need to show a summary for this step.
|
2014-10-28 09:36:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getReport()
|
|
|
|
{
|
2014-11-11 09:24:53 +01:00
|
|
|
$okMessage = mt('setup', 'Directory "%s" in "%s" has been successfully created.');
|
|
|
|
$failMessage = mt('setup', 'Unable to create directory "%s" in "%s". An error occured:');
|
2014-10-28 09:36:08 +01:00
|
|
|
|
|
|
|
$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>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $report;
|
|
|
|
}
|
|
|
|
}
|