IcingaCommand: import/export with fields

fixes #1747
This commit is contained in:
Thomas Gelf 2019-02-14 22:55:24 +01:00
parent 4417a78c55
commit e15a612fbe
2 changed files with 36 additions and 5 deletions

View File

@ -19,6 +19,7 @@ before switching to a new version.
* 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)
* FIX: Commands snapshots now carry fields in your Basket (#1747)
* FEATURE: Add TimePeriod support to Configuration Baskets (#1735)
* FEATURE: RO users could want to see where a configured service originated (#1785)

View File

@ -211,16 +211,18 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI
*/
public function export()
{
$object = $this->toPlainObject();
if (property_exists($object, 'arguments')) {
foreach ($object->arguments as $key => $argument) {
$props = (array) $this->toPlainObject();
if (isset($props['arguments'])) {
foreach ($props['arguments'] as $key => $argument) {
if (property_exists($argument, 'command_id')) {
unset($argument->command_id);
unset($props['arguments'][$key]->command_id);
}
}
}
$props['fields'] = $this->loadFieldReferences();
ksort($props);
return $object;
return (object) $props;
}
/**
@ -248,11 +250,39 @@ class IcingaCommand extends IcingaObject implements ObjectWithArguments, ExportI
$object = static::create([], $db);
}
unset($properties['fields']);
$object->setProperties($properties);
return $object;
}
protected function loadFieldReferences()
{
$db = $this->getDb();
$res = $db->fetchAll(
$db->select()->from([
'cf' => 'icinga_command_field'
], [
'cf.datafield_id',
'cf.is_required',
'cf.var_filter',
])->join(['df' => 'director_datafield'], 'df.id = cf.datafield_id', [])
->where('command_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;
}
}
protected function renderCommand()
{
$command = $this->get('command');