[icinga-checkins] icinga.org: icingaweb2-module-director/bugfix/loop-templateresolver-11803: ImportSource: allow to transfer nested keys

git at icinga.org git at icinga.org
Mon Oct 31 13:31:45 CET 2016


Module: icingaweb2-module-director
Branch: bugfix/loop-templateresolver-11803
Commit: c10ad0e3a2c63e10b913276dd9487f7b9bb3c943
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=c10ad0e3a2c63e10b913276dd9487f7b9bb3c943

Author: Thomas Gelf <thomas at gelf.net>
Date:   Thu Oct 27 19:01:49 2016 +0000

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 385d710..c266f9c 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;
                 }
 



More information about the icinga-checkins mailing list