Basket: fix export for Basket and Notifications

fixes #1703
This commit is contained in:
Thomas Gelf 2018-11-14 11:14:13 +01:00
parent 24a7dbcac8
commit 06f5db698f
3 changed files with 60 additions and 13 deletions

View File

@ -12,21 +12,11 @@ use Icinga\Module\Director\Db;
* TODO
* - create a UUID like in RFC4122
*/
class Basket extends DbObject
class Basket extends DbObject implements ExportInterface
{
const SELECTION_ALL = true;
const SELECTION_NONE = false;
protected $validTypes = [
'host_template',
'host_object',
'service_template',
'service_object',
'service_apply',
'import_source',
'sync_rule'
];
protected $table = 'director_basket';
protected $keyName = 'basket_name';
@ -66,6 +56,21 @@ class Basket extends DbObject
$this->chosenObjects = (array) Json::decode($this->get('objects'));
}
public function getUniqueIdentifier()
{
return $this->get('basket_name');
}
public function export()
{
$result = $this->getProperties();
unset($result['uuid']);
$result['objects'] = Json::decode($result['objects']);
ksort($result);
return (object) $result;
}
public function supportsCustomSelectionFor($type)
{
if (! array_key_exists($type, $this->chosenObjects)) {

View File

@ -28,7 +28,7 @@ class BasketSnapshot extends DbObject
'ImportSource' => '\\Icinga\\Module\\Director\\Objects\\ImportSource',
'SyncRule' => '\\Icinga\\Module\\Director\\Objects\\SyncRule',
'DirectorJob' => '\\Icinga\\Module\\Director\\Objects\\DirectorJob',
'Basket' => '\\Icinga\\Module\\Director\\DirectorObject\\Automation\\Automation',
'Basket' => '\\Icinga\\Module\\Director\\DirectorObject\\Automation\\Basket',
];
protected $objects = [];

View File

@ -2,10 +2,11 @@
namespace Icinga\Module\Director\Objects;
use Icinga\Module\Director\DirectorObject\Automation\ExportInterface;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
use RuntimeException;
class IcingaNotification extends IcingaObject
class IcingaNotification extends IcingaObject implements ExportInterface
{
protected $table = 'icinga_notification';
@ -114,6 +115,47 @@ class IcingaNotification extends IcingaObject
return c::renderKeyValue('times', c::renderDictionary($times));
}
public function getUniqueIdentifier()
{
return $this->getObjectName();
}
public function export()
{
// TODO: ksort in toPlainObject?
$props = (array) $this->toPlainObject();
$props['fields'] = $this->loadFieldReferences();
ksort($props);
return (object) $props;
}
protected function loadFieldReferences()
{
$db = $this->getDb();
$res = $db->fetchAll(
$db->select()->from([
'nf' => 'icinga_notification_field'
], [
'nf.datafield_id',
'nf.is_required',
'nf.var_filter',
])->join(['df' => 'director_datafield'], 'df.id = nf.datafield_id', [])
->where('notification_id = ?', $this->get('id'))
->order('varname ASC')
);
if (empty($res)) {
return [];
} else {
foreach ($res as $field) {
$field->datafield_id = (int) $field->datafield_id;
}
return $res;
}
}
/**
* Do not render internal property apply_to
*