Import: apply row modifiers
This commit is contained in:
parent
dd7a914fea
commit
348aebcf41
|
@ -162,6 +162,26 @@ class Import
|
||||||
)->fetchData();
|
)->fetchData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$modifiers = $this->prepareModifiers();
|
||||||
|
|
||||||
|
if (empty($modifiers)) {
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->data as & $row) {
|
||||||
|
foreach ($modifiers as $key => $mods) {
|
||||||
|
foreach ($mods as $mod) {
|
||||||
|
if (is_array($row->$key)) {
|
||||||
|
foreach ($row->$key as & $k) {
|
||||||
|
$k = $mod->transform($k);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$row->$key = $mod->transform($row->$key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $this->data;
|
return $this->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,6 +217,24 @@ class Import
|
||||||
return $this->properties[$checksum];
|
return $this->properties[$checksum];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: move to ImportSource, this duplicates logic from preview
|
||||||
|
protected function prepareModifiers()
|
||||||
|
{
|
||||||
|
$modifiers = $this->source->fetchRowModifiers();
|
||||||
|
$propertyModifiers = array();
|
||||||
|
|
||||||
|
foreach ($modifiers as $mod) {
|
||||||
|
if (! array_key_exists($mod->property_name, $propertyModifiers)) {
|
||||||
|
$propertyModifiers[$mod->property_name] = array();
|
||||||
|
}
|
||||||
|
$obj = new $mod->provider_class;
|
||||||
|
$obj->setSettings($mod->getSettings());
|
||||||
|
$propertyModifiers[$mod->property_name][] = $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $propertyModifiers;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walk through each row, prepare properties and calculate checksums
|
* Walk through each row, prepare properties and calculate checksums
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue