diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:48 +0000 |
commit | e6d4dfc040bbe3cb80a2ce65b82493b557f751fc (patch) | |
tree | 40bd6366b01b06f4d96fc8638f23a772263cb5e9 /library/Director/Objects/ImportSource.php | |
parent | Releasing progress-linux version 1.10.2-2~progress7.99u1. (diff) | |
download | icingaweb2-module-director-e6d4dfc040bbe3cb80a2ce65b82493b557f751fc.tar.xz icingaweb2-module-director-e6d4dfc040bbe3cb80a2ce65b82493b557f751fc.zip |
Merging upstream version 1.11.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/Objects/ImportSource.php')
-rw-r--r-- | library/Director/Objects/ImportSource.php | 79 |
1 files changed, 14 insertions, 65 deletions
diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php index fd892ef..7477472 100644 --- a/library/Director/Objects/ImportSource.php +++ b/library/Director/Objects/ImportSource.php @@ -3,12 +3,14 @@ namespace Icinga\Module\Director\Objects; use Icinga\Application\Benchmark; +use Icinga\Data\Filter\Filter; use Icinga\Exception\NotFoundError; use Icinga\Module\Director\Application\MemoryLimit; use Icinga\Module\Director\Data\Db\DbObjectWithSettings; use Icinga\Module\Director\Db; use Icinga\Module\Director\DirectorObject\Automation\ExportInterface; use Icinga\Module\Director\Exception\DuplicateKeyException; +use Icinga\Module\Director\Filter\FilterEnrichment; use Icinga\Module\Director\Hook\PropertyModifierHook; use Icinga\Module\Director\Import\Import; use Icinga\Module\Director\Import\SyncUtils; @@ -52,68 +54,6 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface private $newRowModifiers; - /** - * @deprecated please use \Icinga\Module\Director\Data\FieldReferenceLoader - * @return \stdClass - */ - public function export() - { - $plain = $this->getProperties(); - $plain['originalId'] = $plain['id']; - unset($plain['id']); - - foreach ($this->stateProperties as $key) { - unset($plain[$key]); - } - - $plain['settings'] = (object) $this->getSettings(); - $plain['modifiers'] = $this->exportRowModifiers(); - ksort($plain); - - return (object) $plain; - } - - /** - * @param $plain - * @param Db $db - * @param bool $replace - * @return ImportSource - * @throws DuplicateKeyException - * @throws NotFoundError - */ - public static function import($plain, Db $db, $replace = false) - { - $properties = (array) $plain; - if (isset($properties['originalId'])) { - $id = $properties['originalId']; - unset($properties['originalId']); - } else { - $id = null; - } - $name = $properties['source_name']; - - if ($replace && $id && static::existsWithNameAndId($name, $id, $db)) { - $object = static::loadWithAutoIncId($id, $db); - } elseif ($replace && static::exists($name, $db)) { - $object = static::load($name, $db); - } elseif (static::existsWithName($name, $db)) { - throw new DuplicateKeyException( - 'Import Source %s already exists', - $name - ); - } else { - $object = static::create([], $db); - } - - if (! isset($properties['modifiers'])) { - $properties['modifiers'] = []; - } - - $object->setProperties($properties); - - return $object; - } - public function setModifiers(array $modifiers) { if ($this->loadedRowModifiers === null && $this->hasBeenLoadedFromDb()) { @@ -314,10 +254,14 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface foreach ($modifiers as $modPair) { /** @var PropertyModifierHook $modifier */ - list($property, $modifier) = $modPair; + /** @var ?Filter $filter */ + list($property, $modifier, $filter) = $modPair; $rejected = []; $newRows = []; foreach ($data as $key => $row) { + if ($filter && ! $filter->matches($row)) { + continue; + } $this->applyPropertyModifierToRow($modifier, $property, $row); if ($modifier->rejectsRow()) { $rejected[] = $key; @@ -434,7 +378,12 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface { $mods = []; foreach ($this->fetchRowModifiers() as $mod) { - $mods[] = [$mod->get('property_name'), $mod->getInstance()]; + if ($filterExpression = $mod->get('filter_expression')) { + $filter = FilterEnrichment::enrichFilter(Filter::fromQueryString($filterExpression)); + } else { + $filter = null; + } + $mods[] = [$mod->get('property_name'), $mod->getInstance(), $filter]; } return $mods; @@ -530,7 +479,7 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface protected function raiseLimits() { MemoryLimit::raiseTo('1024M'); - ini_set('max_execution_time', 0); + ini_set('max_execution_time', '0'); return $this; } |