ImportSource: allow to transfer nested keys

This commit is contained in:
Thomas Gelf 2016-10-27 19:01:49 +00:00
parent 27634fe722
commit c10ad0e3a2
1 changed files with 18 additions and 0 deletions

View File

@ -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;
}