2015-03-16 04:08:00 -04:00
|
|
|
<?php
|
|
|
|
|
|
2016-11-23 06:27:55 -05:00
|
|
|
namespace Icinga\Module\Businessprocess\Modification;
|
|
|
|
|
|
2017-01-11 08:04:45 -05:00
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
2016-11-23 06:27:55 -05:00
|
|
|
use Icinga\Module\Businessprocess\Node;
|
2015-03-16 04:08:00 -04:00
|
|
|
|
|
|
|
|
class NodeModifyAction extends NodeAction
|
|
|
|
|
{
|
|
|
|
|
protected $properties = array();
|
|
|
|
|
|
|
|
|
|
protected $formerProperties = array();
|
|
|
|
|
|
|
|
|
|
protected $preserveProperties = array('formerProperties', 'properties');
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* Set properties for a specific node
|
|
|
|
|
*
|
|
|
|
|
* Can be called multiple times
|
|
|
|
|
*
|
|
|
|
|
* @param Node $node
|
|
|
|
|
* @param array $properties
|
|
|
|
|
*
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
|
|
|
|
public function setNodeProperties(Node $node, array $properties)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
|
|
|
|
foreach (array_keys($properties) as $key) {
|
|
|
|
|
$this->properties[$key] = $properties[$key];
|
|
|
|
|
|
|
|
|
|
if (array_key_exists($key, $this->formerProperties)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$func = 'get' . ucfirst($key);
|
|
|
|
|
$this->formerProperties[$key] = $node->$func();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function appliesTo(BpConfig $config)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
|
|
|
|
$name = $this->getNodeName();
|
|
|
|
|
|
2017-01-11 11:36:32 -05:00
|
|
|
if (! $config->hasNode($name)) {
|
2015-03-16 04:08:00 -04:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-11 11:36:32 -05:00
|
|
|
$node = $config->getNode($name);
|
2015-03-16 04:08:00 -04:00
|
|
|
|
|
|
|
|
foreach ($this->properties as $key => $val) {
|
|
|
|
|
$func = 'get' . ucfirst($key);
|
|
|
|
|
if ($this->formerProperties[$key] !== $node->$func()) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2017-01-11 11:36:32 -05:00
|
|
|
public function applyTo(BpConfig $config)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
2017-01-11 11:36:32 -05:00
|
|
|
$node = $config->getNode($this->getNodeName());
|
2015-03-16 04:08:00 -04:00
|
|
|
|
|
|
|
|
foreach ($this->properties as $key => $val) {
|
|
|
|
|
$func = 'set' . ucfirst($key);
|
|
|
|
|
$node->$func($val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @param $properties
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
public function setProperties($properties)
|
|
|
|
|
{
|
|
|
|
|
$this->properties = $properties;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @param $properties
|
|
|
|
|
* @return $this
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
public function setFormerProperties($properties)
|
|
|
|
|
{
|
|
|
|
|
$this->formerProperties = $properties;
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
public function getProperties()
|
|
|
|
|
{
|
|
|
|
|
return $this->properties;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:11:26 -05:00
|
|
|
/**
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2015-03-16 04:08:00 -04:00
|
|
|
public function getFormerProperties()
|
|
|
|
|
{
|
|
|
|
|
return $this->formerProperties;
|
|
|
|
|
}
|
|
|
|
|
}
|