From c10ad0e3a2c63e10b913276dd9487f7b9bb3c943 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 27 Oct 2016 19:01:49 +0000 Subject: [PATCH] ImportSource: allow to transfer nested keys --- library/Director/Objects/ImportSource.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php index 385d710a..c266f9c0 100644 --- a/library/Director/Objects/ImportSource.php +++ b/library/Director/Objects/ImportSource.php @@ -3,9 +3,11 @@ namespace Icinga\Module\Director\Objects; use Icinga\Application\Benchmark; +use Icinga\Exception\ConfigurationError; use Icinga\Exception\NotFoundError; use Icinga\Module\Director\Data\Db\DbObjectWithSettings; use Icinga\Module\Director\Import\Import; +use Icinga\Module\Director\Import\SyncUtils; use Exception; class ImportSource extends DbObjectWithSettings @@ -97,6 +99,22 @@ class ImportSource extends DbObjectWithSettings foreach ($modifiers as $key => $mods) { foreach ($mods as $mod) { if (! property_exists($row, $key)) { + // Partial support for nested keys. Must write result to + // a dedicated flat key + if (strpos($key, '.') !== false) { + $val = SyncUtils::getSpecificValue($row, $key); + if ($val !== null) { + $target = $mod->getTargetProperty($key); + if (strpos($target, '.') !== false) { + throw new ConfigurationError( + 'Cannot set value for nested key "%s"', + $target + ); + } + + $row->$target = $mod->transform($val); + } + continue; }