2014-09-29 14:18:50 +02:00
|
|
|
<?php
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
// {{{ICINGA_LICENSE_HEADER}}}
|
|
|
|
|
2014-11-10 16:31:40 +01:00
|
|
|
namespace Icinga\Module\Setup;
|
2014-09-29 14:18:50 +02:00
|
|
|
|
2014-10-23 11:41:16 +02:00
|
|
|
use ArrayIterator;
|
|
|
|
use IteratorAggregate;
|
2014-11-10 16:31:40 +01:00
|
|
|
use Icinga\Module\Setup\Exception\SetupException;
|
2014-10-23 11:41:16 +02:00
|
|
|
|
2014-09-29 14:18:50 +02:00
|
|
|
/**
|
2014-11-10 10:30:52 +01:00
|
|
|
* Container for multiple configuration steps
|
2014-09-29 14:18:50 +02:00
|
|
|
*/
|
2014-11-10 10:30:52 +01:00
|
|
|
class Setup implements IteratorAggregate
|
2014-09-29 14:18:50 +02:00
|
|
|
{
|
2014-10-23 11:41:16 +02:00
|
|
|
protected $steps;
|
|
|
|
|
|
|
|
protected $state;
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->steps = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIterator()
|
|
|
|
{
|
|
|
|
return new ArrayIterator($this->getSteps());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addStep(Step $step)
|
|
|
|
{
|
|
|
|
$this->steps[] = $step;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function addSteps(array $steps)
|
|
|
|
{
|
|
|
|
foreach ($steps as $step) {
|
|
|
|
$this->addStep($step);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSteps()
|
|
|
|
{
|
|
|
|
return $this->steps;
|
|
|
|
}
|
|
|
|
|
2014-09-29 14:18:50 +02:00
|
|
|
/**
|
2014-11-10 10:30:52 +01:00
|
|
|
* Run the configuration and return whether it succeeded
|
2014-09-29 14:18:50 +02:00
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
2014-10-23 11:41:16 +02:00
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
$this->state = true;
|
|
|
|
|
|
|
|
try {
|
|
|
|
foreach ($this->steps as $step) {
|
|
|
|
$this->state &= $step->apply();
|
|
|
|
}
|
2014-11-10 10:30:52 +01:00
|
|
|
} catch (SetupException $_) {
|
2014-10-23 11:41:16 +02:00
|
|
|
$this->state = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->state;
|
|
|
|
}
|
2014-09-29 14:18:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a summary of all actions designated to run
|
|
|
|
*
|
2014-10-23 11:41:16 +02:00
|
|
|
* @return array An array of HTML strings
|
2014-09-29 14:18:50 +02:00
|
|
|
*/
|
2014-10-23 11:41:16 +02:00
|
|
|
public function getSummary()
|
|
|
|
{
|
|
|
|
$summaries = array();
|
|
|
|
foreach ($this->steps as $step) {
|
|
|
|
$summaries[] = $step->getSummary();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $summaries;
|
|
|
|
}
|
2014-09-29 14:18:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a report of all actions that were run
|
|
|
|
*
|
2014-10-23 11:41:16 +02:00
|
|
|
* @return array An array of HTML strings
|
2014-09-29 14:18:50 +02:00
|
|
|
*/
|
2014-10-23 11:41:16 +02:00
|
|
|
public function getReport()
|
|
|
|
{
|
|
|
|
$reports = array();
|
|
|
|
foreach ($this->steps as $step) {
|
|
|
|
$reports[] = $step->getReport();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $reports;
|
|
|
|
}
|
2014-09-29 14:18:50 +02:00
|
|
|
}
|