2019-01-16 04:25:11 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess\Modification;
|
|
|
|
|
|
|
|
|
|
use Icinga\Module\Businessprocess\BpConfig;
|
2023-07-26 11:15:26 -04:00
|
|
|
use Icinga\Module\Businessprocess\Common\Sort;
|
2019-01-16 04:25:11 -05:00
|
|
|
|
|
|
|
|
class NodeCopyAction extends NodeAction
|
|
|
|
|
{
|
2023-07-26 11:15:26 -04:00
|
|
|
use Sort;
|
|
|
|
|
|
2019-01-16 04:25:11 -05:00
|
|
|
/**
|
|
|
|
|
* @param BpConfig $config
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function appliesTo(BpConfig $config)
|
|
|
|
|
{
|
|
|
|
|
$name = $this->getNodeName();
|
|
|
|
|
|
|
|
|
|
if (! $config->hasBpNode($name)) {
|
|
|
|
|
$this->error('Process "%s" not found', $name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($config->hasRootNode($name)) {
|
|
|
|
|
$this->error('A toplevel node with name "%s" already exists', $name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param BpConfig $config
|
|
|
|
|
*/
|
|
|
|
|
public function applyTo(BpConfig $config)
|
|
|
|
|
{
|
|
|
|
|
$name = $this->getNodeName();
|
2023-07-26 11:15:26 -04:00
|
|
|
|
|
|
|
|
$display = 1;
|
|
|
|
|
if ($config->getMetadata()->isManuallyOrdered()) {
|
|
|
|
|
$rootNodes = self::applyManualSorting($config->getRootNodes());
|
|
|
|
|
$display = end($rootNodes)->getDisplay() + 1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-16 04:25:11 -05:00
|
|
|
$config->addRootNode($name)
|
|
|
|
|
->getBpNode($name)
|
2023-07-26 11:15:26 -04:00
|
|
|
->setDisplay($display);
|
2019-01-16 04:25:11 -05:00
|
|
|
}
|
|
|
|
|
}
|