parent
9f6ba150f6
commit
14e5aa8da4
|
@ -103,6 +103,10 @@ class ImportSource extends DbObjectWithSettings
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
* @throws ConfigurationError
|
||||
*/
|
||||
public function applyModifiersToRow(& $row)
|
||||
{
|
||||
$modifiers = $this->getRowModifiers();
|
||||
|
@ -110,16 +114,29 @@ class ImportSource extends DbObjectWithSettings
|
|||
foreach ($modifiers as $key => $mods) {
|
||||
/** @var PropertyModifierHook $mod */
|
||||
foreach ($mods as $mod) {
|
||||
if ($mod->requiresRow()) {
|
||||
$mod->setRow($row);
|
||||
$this->applyPropertyModifierToRow($mod, $key, $row);
|
||||
if (null === $row) {
|
||||
return $this;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyPropertyModifierToRow(PropertyModifierHook $modifier, $key, & $row)
|
||||
{
|
||||
if ($modifier->requiresRow()) {
|
||||
$modifier->setRow($row);
|
||||
}
|
||||
|
||||
if (property_exists($row, $key)) {
|
||||
$value = $row->$key;
|
||||
} elseif (strpos($key, '.') !== false) {
|
||||
$value = SyncUtils::getSpecificValue($row, $key);
|
||||
} else {
|
||||
$value = null;
|
||||
}
|
||||
|
||||
$target = $modifier->getTargetProperty($key);
|
||||
if (strpos($target, '.') !== false) {
|
||||
throw new ConfigurationError(
|
||||
'Cannot set value for nested key "%s"',
|
||||
|
@ -127,28 +144,16 @@ class ImportSource extends DbObjectWithSettings
|
|||
);
|
||||
}
|
||||
|
||||
$row->$target = $mod->transform($val);
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$target = $mod->getTargetProperty($key);
|
||||
|
||||
if (is_array($row->$key) && ! $mod->hasArraySupport()) {
|
||||
$new = array();
|
||||
foreach ($row->$key as $k => $v) {
|
||||
$new[$k] = $mod->transform($v);
|
||||
if (is_array($value) && ! $modifier->hasArraySupport()) {
|
||||
$new = [];
|
||||
foreach ($value as $k => $v) {
|
||||
$new[$k] = $modifier->transform($v);
|
||||
}
|
||||
$row->$target = $new;
|
||||
} else {
|
||||
$row->$target = $mod->transform($row->$key);
|
||||
}
|
||||
}
|
||||
$row->$target = $modifier->transform($value);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRowModifiers()
|
||||
|
|
Loading…
Reference in New Issue