ImportSource: allow Property Modifiers to reject

fixes #1369
This commit is contained in:
Thomas Gelf 2018-01-25 12:16:49 +01:00
parent 14e5aa8da4
commit 8ed76d4888

View File

@ -94,11 +94,20 @@ class ImportSource extends DbObjectWithSettings
{ {
$modifiers = $this->getRowModifiers(); $modifiers = $this->getRowModifiers();
$rejected = [];
if (! empty($modifiers)) { if (! empty($modifiers)) {
foreach ($data as &$row) { foreach ($data as $key => &$row) {
$this->applyModifiersToRow($row); $this->applyModifiersToRow($row);
if (null === $row) {
$rejected[] = $row;
} }
} }
}
foreach ($rejected as $key) {
unset($data[$key]);
}
return $this; return $this;
} }
@ -116,7 +125,7 @@ class ImportSource extends DbObjectWithSettings
foreach ($mods as $mod) { foreach ($mods as $mod) {
$this->applyPropertyModifierToRow($mod, $key, $row); $this->applyPropertyModifierToRow($mod, $key, $row);
if (null === $row) { if (null === $row) {
return $this; return;
} }
} }
} }
@ -154,6 +163,9 @@ class ImportSource extends DbObjectWithSettings
$row->$target = $modifier->transform($value); $row->$target = $modifier->transform($value);
} }
if ($modifier->rejectsRow()) {
$row = null;
}
} }
public function getRowModifiers() public function getRowModifiers()