ImportSource: use target_property for transforms
This commit is contained in:
parent
f12e4b2033
commit
9a6320c2f4
|
@ -21,7 +21,12 @@ class ImportsourceHookTable extends QuickTable
|
||||||
public function getColumns()
|
public function getColumns()
|
||||||
{
|
{
|
||||||
if ($this->columnCache === null) {
|
if ($this->columnCache === null) {
|
||||||
$this->columnCache = $this->sourceHook()->listColumns();
|
$this->columnCache = array_merge(
|
||||||
|
$this->sourceHook()->listColumns(),
|
||||||
|
$this->source->listModifierTargetProperties()
|
||||||
|
);
|
||||||
|
|
||||||
|
sort($this->columnCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->columnCache;
|
return $this->columnCache;
|
||||||
|
|
|
@ -39,8 +39,12 @@ abstract class PropertyModifierHook
|
||||||
return $this->targetProperty !== null;
|
return $this->targetProperty !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTargetProperty()
|
public function getTargetProperty($default = null)
|
||||||
{
|
{
|
||||||
|
if ($this->targetProperty === null) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
return $this->targetProperty;
|
return $this->targetProperty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,12 +99,17 @@ class ImportSource extends DbObjectWithSettings
|
||||||
if (! property_exists($row, $key)) {
|
if (! property_exists($row, $key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$target = $mod->getTargetProperty($key);
|
||||||
|
|
||||||
if (is_array($row->$key)) {
|
if (is_array($row->$key)) {
|
||||||
foreach ($row->$key as & $k) {
|
$new = array();
|
||||||
$k = $mod->transform($k);
|
foreach ($row->$key as $k => $v) {
|
||||||
|
$new[$k] = $mod->transform($v);
|
||||||
}
|
}
|
||||||
|
$row->$target = $new;
|
||||||
} else {
|
} else {
|
||||||
$row->$key = $mod->transform($row->$key);
|
$row->$target = $mod->transform($row->$key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,6 +158,20 @@ class ImportSource extends DbObjectWithSettings
|
||||||
$this->rowModifiers = $modifiers;
|
$this->rowModifiers = $modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function listModifierTargetProperties()
|
||||||
|
{
|
||||||
|
$list = array();
|
||||||
|
foreach ($this->getRowModifiers() as $rowMods) {
|
||||||
|
foreach ($rowMods as $mod) {
|
||||||
|
if ($mod->hasTargetProperty()) {
|
||||||
|
$list[$mod->getTargetProperty()] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_keys($list);
|
||||||
|
}
|
||||||
|
|
||||||
public function checkForChanges($runImport = false)
|
public function checkForChanges($runImport = false)
|
||||||
{
|
{
|
||||||
$hadChanges = false;
|
$hadChanges = false;
|
||||||
|
|
Loading…
Reference in New Issue