From 8ed76d488880c04177aa32e19acd9e4077cb8cf5 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Thu, 25 Jan 2018 12:16:49 +0100 Subject: [PATCH] ImportSource: allow Property Modifiers to reject fixes #1369 --- library/Director/Objects/ImportSource.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php index 8f30ee9c..bdc58a10 100644 --- a/library/Director/Objects/ImportSource.php +++ b/library/Director/Objects/ImportSource.php @@ -94,12 +94,21 @@ class ImportSource extends DbObjectWithSettings { $modifiers = $this->getRowModifiers(); + $rejected = []; + if (! empty($modifiers)) { - foreach ($data as &$row) { + foreach ($data as $key => &$row) { $this->applyModifiersToRow($row); + if (null === $row) { + $rejected[] = $row; + } } } + foreach ($rejected as $key) { + unset($data[$key]); + } + return $this; } @@ -116,7 +125,7 @@ class ImportSource extends DbObjectWithSettings foreach ($mods as $mod) { $this->applyPropertyModifierToRow($mod, $key, $row); if (null === $row) { - return $this; + return; } } } @@ -154,6 +163,9 @@ class ImportSource extends DbObjectWithSettings $row->$target = $modifier->transform($value); } + if ($modifier->rejectsRow()) { + $row = null; + } } public function getRowModifiers()