ImportSource: fix property modifier handling when
...restoring baskets fixes #1949
This commit is contained in:
parent
3f984af534
commit
ecf56ff1a7
|
@ -178,7 +178,7 @@ abstract class PropertyModifierHook
|
||||||
return $this->db;
|
return $this->db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setSettings($settings)
|
public function setSettings(array $settings)
|
||||||
{
|
{
|
||||||
$this->settings = $settings;
|
$this->settings = $settings;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -204,6 +204,11 @@ abstract class PropertyModifierHook
|
||||||
return (object) $this->settings;
|
return (object) $this->settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSettings()
|
||||||
|
{
|
||||||
|
return $this->settings;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override this method if you want to extend the settings form
|
* Override this method if you want to extend the settings form
|
||||||
*
|
*
|
||||||
|
|
|
@ -68,6 +68,13 @@ class ImportRowModifier extends DbObjectWithSettings
|
||||||
return (object) $properties;
|
return (object) $properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setSettings($settings)
|
||||||
|
{
|
||||||
|
$settings = $this->getInstance()->setSettings((array) $settings)->getSettings();
|
||||||
|
|
||||||
|
return parent::setSettings($settings); // TODO: Change the autogenerated stub
|
||||||
|
}
|
||||||
|
|
||||||
protected function beforeStore()
|
protected function beforeStore()
|
||||||
{
|
{
|
||||||
if (! $this->hasBeenLoadedFromDb() && $this->get('priority') === null) {
|
if (! $this->hasBeenLoadedFromDb() && $this->get('priority') === null) {
|
||||||
|
|
|
@ -47,6 +47,8 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface
|
||||||
|
|
||||||
private $rowModifiers;
|
private $rowModifiers;
|
||||||
|
|
||||||
|
private $loadedRowModifiers;
|
||||||
|
|
||||||
private $newRowModifiers;
|
private $newRowModifiers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,16 +103,45 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface
|
||||||
$object = static::create([], $db);
|
$object = static::create([], $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
$object->newRowModifiers = $properties['modifiers'];
|
|
||||||
unset($properties['modifiers']);
|
|
||||||
$object->setProperties($properties);
|
$object->setProperties($properties);
|
||||||
if ($id !== null) {
|
if ($id !== null) {
|
||||||
|
// TODO: really?
|
||||||
$object->reallySet('id', $id);
|
$object->reallySet('id', $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setModifiers(array $modifiers)
|
||||||
|
{
|
||||||
|
if ($this->loadedRowModifiers === null) {
|
||||||
|
$this->loadedRowModifiers = $this->fetchRowModifiers();
|
||||||
|
}
|
||||||
|
$current = $this->loadedRowModifiers;
|
||||||
|
if (count($current) !== count($modifiers)) {
|
||||||
|
$this->newRowModifiers = $modifiers;
|
||||||
|
} else {
|
||||||
|
$i = 0;
|
||||||
|
$modified = false;
|
||||||
|
foreach ($modifiers as $props) {
|
||||||
|
$this->loadedRowModifiers[$i]->setProperties((array) $props);
|
||||||
|
if ($this->loadedRowModifiers[$i]->hasBeenModified()) {
|
||||||
|
$modified = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($modified) {
|
||||||
|
// TOOD: no newRowModifiers, directly store loaded ones if diff
|
||||||
|
$this->newRowModifiers = $modifiers;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasBeenModified()
|
||||||
|
{
|
||||||
|
return $this->newRowModifiers !== null
|
||||||
|
|| parent::hasBeenModified();
|
||||||
|
}
|
||||||
|
|
||||||
public function getUniqueIdentifier()
|
public function getUniqueIdentifier()
|
||||||
{
|
{
|
||||||
return $this->get('source_name');
|
return $this->get('source_name');
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace Icinga\Module\Director\PropertyModifier;
|
namespace Icinga\Module\Director\PropertyModifier;
|
||||||
|
|
||||||
use Icinga\Module\Director\Forms\ImportRowModifierForm;
|
|
||||||
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
use Icinga\Module\Director\Hook\PropertyModifierHook;
|
||||||
use Icinga\Module\Director\Objects\ImportRowModifier;
|
use Icinga\Module\Director\Objects\ImportRowModifier;
|
||||||
use Icinga\Module\Director\Objects\ImportSource;
|
use Icinga\Module\Director\Objects\ImportSource;
|
||||||
|
@ -67,6 +66,24 @@ class PropertyModifierGetPropertyFromOtherImportSource extends PropertyModifierH
|
||||||
] + $extra);
|
] + $extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $settings
|
||||||
|
* @return PropertyModifierHook
|
||||||
|
* @throws \Icinga\Exception\NotFoundError
|
||||||
|
*/
|
||||||
|
public function setSettings(array $settings)
|
||||||
|
{
|
||||||
|
if (isset($settings['import_source'])) {
|
||||||
|
$settings['import_source_id'] = ImportSource::load(
|
||||||
|
$settings['import_source'],
|
||||||
|
$this->getDb()
|
||||||
|
)->get('id');
|
||||||
|
unset($settings['import_source']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::setSettings($settings);
|
||||||
|
}
|
||||||
|
|
||||||
public function transform($value)
|
public function transform($value)
|
||||||
{
|
{
|
||||||
$data = $this->getImportedData();
|
$data = $this->getImportedData();
|
||||||
|
|
Loading…
Reference in New Issue