File: NodeCopyAction.php

package info (click to toggle)
icingaweb2-module-businessprocess 2.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,720 kB
  • sloc: php: 10,971; javascript: 2,019; sh: 115; xml: 49; makefile: 18
file content (48 lines) | stat: -rw-r--r-- 1,123 bytes parent folder | download | duplicates (2)
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);
    }
}