only try to replace matching target fields
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 13 Apr 2016 14:41:27 +0000 (16:41 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 19 Apr 2016 15:37:18 +0000 (17:37 +0200)
... of related records during import when
targetField option is given
.... and check if it's a scalar, we can't handle
 non-scalars yet

Change-Id: I555aefcf6c67d051de8da8c213d3088ab5b09749
Reviewed-on: http://gerrit.tine20.com/customers/3046
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Import/Abstract.php

index 60806f2..6197060 100644 (file)
@@ -643,8 +643,10 @@ abstract class Tinebase_Import_Abstract implements Tinebase_Import_Interface
         if (isset($field['targetField'])&& isset($field['targetFieldData']) && isset($record)) {
             $unreplaced = $targetField = $field['targetFieldData'];
             foreach ($record as $key => $value) {
-                $targetField = preg_replace('/' . preg_quote($key) . '/', $value, $targetField);
-                $unreplaced = preg_replace('/^[, ]*' . preg_quote($key) . '/', '', $unreplaced);
+                if (preg_match('/' . preg_quote($key) . '/', $targetField) && is_scalar($value)) {
+                    $targetField = preg_replace('/' . preg_quote($key) . '/', $value, $targetField);
+                    $unreplaced = preg_replace('/^[, ]*' . preg_quote($key) . '/', '', $unreplaced);
+                }
             }
             // remove unreplaced stuff
             $targetField = str_replace($unreplaced, '', $targetField);