2016-03-09 20:53:57 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Objects;
|
|
|
|
|
2018-10-08 06:30:31 +02:00
|
|
|
use Icinga\Module\Director\Db;
|
|
|
|
use Icinga\Module\Director\DirectorObject\Automation\ExportInterface;
|
|
|
|
use Icinga\Module\Director\Exception\DuplicateKeyException;
|
|
|
|
|
|
|
|
abstract class IcingaObjectGroup extends IcingaObject implements ExportInterface
|
2016-03-09 20:53:57 +01:00
|
|
|
{
|
|
|
|
protected $supportsImports = true;
|
|
|
|
|
2016-10-13 15:44:53 +02:00
|
|
|
protected $supportedInLegacy = true;
|
|
|
|
|
2018-06-08 20:45:02 +02:00
|
|
|
protected $defaultProperties = [
|
2016-10-24 05:41:37 +02:00
|
|
|
'id' => null,
|
|
|
|
'object_name' => null,
|
|
|
|
'object_type' => null,
|
|
|
|
'disabled' => 'n',
|
|
|
|
'display_name' => null,
|
|
|
|
'assign_filter' => null,
|
2018-06-08 20:45:02 +02:00
|
|
|
];
|
2016-05-02 10:26:41 +02:00
|
|
|
|
2018-10-08 06:30:31 +02:00
|
|
|
public function getUniqueIdentifier()
|
|
|
|
{
|
|
|
|
return $this->getObjectName();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return object
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
|
|
|
public function export()
|
|
|
|
{
|
|
|
|
return $this->toPlainObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $plain
|
|
|
|
* @param Db $db
|
|
|
|
* @param bool $replace
|
|
|
|
* @return IcingaObjectGroup
|
|
|
|
* @throws DuplicateKeyException
|
|
|
|
* @throws \Icinga\Exception\NotFoundError
|
|
|
|
*/
|
|
|
|
public static function import($plain, Db $db, $replace = false)
|
|
|
|
{
|
|
|
|
$properties = (array) $plain;
|
|
|
|
$name = $properties['object_name'];
|
|
|
|
$key = $name;
|
|
|
|
|
|
|
|
if ($replace && static::exists($key, $db)) {
|
|
|
|
$object = static::load($key, $db);
|
|
|
|
} elseif (static::exists($key, $db)) {
|
|
|
|
throw new DuplicateKeyException(
|
|
|
|
'Group "%s" already exists',
|
|
|
|
$name
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$object = static::create([], $db);
|
|
|
|
}
|
|
|
|
|
|
|
|
$object->setProperties($properties);
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
2018-07-13 10:35:28 +02:00
|
|
|
protected function prefersGlobalZone()
|
2016-05-02 10:26:41 +02:00
|
|
|
{
|
2018-07-13 10:35:28 +02:00
|
|
|
return true;
|
2016-05-02 10:26:41 +02:00
|
|
|
}
|
2016-03-09 20:53:57 +01:00
|
|
|
}
|