summaryrefslogtreecommitdiffstats
path: root/library/Businessprocess/Modification/NodeCopyAction.php
blob: 80d781bb07ff20e3db6eb7d0c98a2c331e16b766 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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);
    }
}