2015-02-12 19:54:47 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Icinga\Module\Businessprocess;
|
|
|
|
|
|
|
|
|
|
use Icinga\Application\Config;
|
2016-11-28 18:34:28 -05:00
|
|
|
use Icinga\Module\Businessprocess\Html\Link;
|
2015-02-12 19:54:47 -05:00
|
|
|
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
2015-10-16 16:48:57 -04:00
|
|
|
use Exception;
|
2015-02-12 19:54:47 -05:00
|
|
|
|
|
|
|
|
class ImportedNode extends Node
|
|
|
|
|
{
|
2016-11-28 18:34:28 -05:00
|
|
|
/** @var string */
|
2015-02-12 19:54:47 -05:00
|
|
|
protected $configName;
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/** @var BpNode */
|
|
|
|
|
private $node;
|
2015-02-12 19:54:47 -05:00
|
|
|
|
2015-10-05 06:34:47 -04:00
|
|
|
protected $className = 'subtree';
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function __construct(BusinessProcess $bp, $object)
|
|
|
|
|
{
|
|
|
|
|
$this->name = $object->name;
|
|
|
|
|
$this->configName = $object->configName;
|
|
|
|
|
$this->bp = $bp;
|
|
|
|
|
if (isset($object->state)) {
|
|
|
|
|
$this->setState($object->state);
|
|
|
|
|
} else {
|
|
|
|
|
$this->setMissing();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function getConfigName()
|
|
|
|
|
{
|
|
|
|
|
return $this->configName;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function getState()
|
|
|
|
|
{
|
|
|
|
|
if ($this->state === null) {
|
|
|
|
|
$this->state = $this->importedNode()->getState();
|
|
|
|
|
}
|
|
|
|
|
return $this->state;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function getAlias()
|
|
|
|
|
{
|
|
|
|
|
return $this->importedNode()->getAlias();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-22 08:18:13 -05:00
|
|
|
public function getUrl()
|
|
|
|
|
{
|
|
|
|
|
$params = array(
|
|
|
|
|
'config' => $this->getConfigName(),
|
2016-12-22 08:19:00 -05:00
|
|
|
'node' => $this->importedNode()->getName()
|
2016-12-22 08:18:13 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return Url::fromPath('businessprocess/process/show', $params);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function isMissing()
|
|
|
|
|
{
|
2015-03-16 04:08:00 -04:00
|
|
|
// TODO: WHY? return $this->getState() === null;
|
2016-11-28 18:34:28 -05:00
|
|
|
return $this->importedNode()->isMissing();
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function isInDowntime()
|
|
|
|
|
{
|
|
|
|
|
if ($this->downtime === null) {
|
|
|
|
|
$this->downtime = $this->importedNode()->isInDowntime();
|
|
|
|
|
}
|
|
|
|
|
return $this->downtime;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
public function isAcknowledged()
|
|
|
|
|
{
|
|
|
|
|
if ($this->ack === null) {
|
|
|
|
|
$this->downtime = $this->importedNode()->isAcknowledged();
|
|
|
|
|
}
|
|
|
|
|
return $this->ack;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @return BpNode
|
|
|
|
|
*/
|
2015-02-12 19:54:47 -05:00
|
|
|
protected function importedNode()
|
|
|
|
|
{
|
2016-11-28 18:34:28 -05:00
|
|
|
if ($this->node === null) {
|
|
|
|
|
$this->node = $this->loadImportedNode();
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2016-11-28 18:34:28 -05:00
|
|
|
|
|
|
|
|
return $this->node;
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2016-11-28 18:34:28 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return BpNode
|
|
|
|
|
*/
|
|
|
|
|
protected function loadImportedNode()
|
2015-02-12 19:54:47 -05:00
|
|
|
{
|
2016-11-28 18:34:28 -05:00
|
|
|
try {
|
|
|
|
|
$import = $this->storage()->loadProcess($this->configName);
|
|
|
|
|
if ($this->bp->usesSoftStates()) {
|
|
|
|
|
$import->useSoftStates();
|
|
|
|
|
} else {
|
|
|
|
|
$import->useHardStates();
|
|
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
$import->retrieveStatesFromBackend();
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
return $import->getNode($this->name);
|
|
|
|
|
} catch (Exception $e) {
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
return $this->createFailedNode($e);
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
2016-11-28 18:34:28 -05:00
|
|
|
}
|
2015-03-16 04:08:00 -04:00
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @return LegacyStorage
|
|
|
|
|
*/
|
|
|
|
|
protected function storage()
|
|
|
|
|
{
|
|
|
|
|
return new LegacyStorage(
|
|
|
|
|
Config::module('businessprocess')->getSection('global')
|
|
|
|
|
);
|
2015-03-16 04:08:00 -04:00
|
|
|
}
|
|
|
|
|
|
2016-11-28 18:34:28 -05:00
|
|
|
/**
|
|
|
|
|
* @param Exception $e
|
|
|
|
|
*
|
|
|
|
|
* @return BpNode
|
|
|
|
|
*/
|
|
|
|
|
protected function createFailedNode(Exception $e)
|
2015-03-16 04:08:00 -04:00
|
|
|
{
|
2016-11-28 18:34:28 -05:00
|
|
|
$node = new BpNode($this->bp, (object) array(
|
|
|
|
|
'name' => $this->name,
|
|
|
|
|
'operator' => '&',
|
|
|
|
|
'child_names' => array()
|
2015-03-16 04:08:00 -04:00
|
|
|
));
|
2016-11-28 18:34:28 -05:00
|
|
|
$node->setState(2);
|
|
|
|
|
$node->setMissing(false)
|
|
|
|
|
->setDowntime(false)
|
|
|
|
|
->setAck(false)
|
|
|
|
|
->setAlias($e->getMessage());
|
|
|
|
|
|
|
|
|
|
return $node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
*/
|
|
|
|
|
public function getLink()
|
|
|
|
|
{
|
|
|
|
|
return Link::create(
|
|
|
|
|
$this->getAlias(),
|
|
|
|
|
'businessprocess/process/show',
|
|
|
|
|
array(
|
|
|
|
|
'config' => $this->configName,
|
|
|
|
|
'process' => $this->name
|
|
|
|
|
)
|
|
|
|
|
);
|
2015-02-12 19:54:47 -05:00
|
|
|
}
|
|
|
|
|
}
|