IcingaDependency: allow for basket snapshots

fixes #1739
This commit is contained in:
Thomas Gelf 2019-02-14 21:54:11 +01:00
parent dc48a7e6a0
commit 640da36c62
3 changed files with 54 additions and 2 deletions

View File

@ -18,6 +18,7 @@ before switching to a new version.
* FIX: Activity Log used to ignore Host filters (#1613)
* FIX: Basket failed to restore depending on PHP version (#1782)
* FIX: Loop detection works again (#1631)
* FIX: Snapshots for Baskets with Dependencies are now possible (#1739)
* FEATURE: RO users could want to see where a configured service originated (#1785)
### REST API

View File

@ -7,6 +7,7 @@ use Icinga\Module\Director\Db;
use Icinga\Module\Director\Data\Db\DbObject;
use Icinga\Module\Director\Objects\DirectorDatafield;
use Icinga\Module\Director\Objects\IcingaCommand;
use Icinga\Module\Director\Objects\IcingaDependency;
use Icinga\Module\Director\Objects\IcingaObject;
use InvalidArgumentException;
use RuntimeException;
@ -378,7 +379,7 @@ class BasketSnapshot extends DbObject
if ($dummy instanceof IcingaCommand) {
$select = $db->select()->from($dummy->getTableName())
->where('object_type != ?', 'external_object');
} elseif (! $dummy->isGroup()) {
} elseif (! $dummy->isGroup() && ! $dummy instanceof IcingaDependency) {
$select = $db->select()->from($dummy->getTableName())
->where('object_type = ?', 'template');
} else {

View File

@ -3,11 +3,14 @@
namespace Icinga\Module\Director\Objects;
use Icinga\Exception\ConfigurationError;
use Icinga\Module\Director\Db;
use Icinga\Module\Director\DirectorObject\Automation\ExportInterface;
use Icinga\Module\Director\Exception\DuplicateKeyException;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use Icinga\Exception\NotFoundError;
use Icinga\Data\Filter\Filter;
class IcingaDependency extends IcingaObject
class IcingaDependency extends IcingaObject implements ExportInterface
{
protected $table = 'icinga_dependency';
@ -55,6 +58,53 @@ class IcingaDependency extends IcingaObject
'ignore_soft_states' => 'ignore_soft_states'
];
public function getUniqueIdentifier()
{
return $this->getObjectName();
}
/**
* @return object
* @throws \Icinga\Exception\NotFoundError
*/
public function export()
{
$props = (array) $this->toPlainObject();
ksort($props);
return (object) $props;
}
/**
* @param $plain
* @param Db $db
* @param bool $replace
* @return static
* @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(
'Service Template "%s" already exists',
$name
);
} else {
$object = static::create([], $db);
}
$object->setProperties($properties);
return $object;
}
/**
* Do not render internal property apply_to
*