icingaweb2-module-businessp.../library/Businessprocess/Modification/NodeCopyAction.php
Johannes Meyer 52c150c56b Use the new Sort trait where applicable
Moves the entire order processing to the renderers as that's
where it's mostly relevant. The only cases where nodes are
still ordered outside the rendering is where changes are
applied based on user input, which happened based on what's
been previously rendered.
2023-08-03 15:19:28 +02:00

48 lines
1.1 KiB
PHP

<?php
namespace Icinga\Module\Businessprocess\Modification;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\Common\Sort;
class NodeCopyAction extends NodeAction
{
use Sort;
/**
* @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();
$display = 1;
if ($config->getMetadata()->isManuallyOrdered()) {
$rootNodes = self::applyManualSorting($config->getRootNodes());
$display = end($rootNodes)->getDisplay() + 1;
}
$config->addRootNode($name)
->getBpNode($name)
->setDisplay($display);
}
}