Skip to content

Commit d47b202

Browse files
jedateachchillu
authored andcommitted
Restored c4eac53 (merge error)
FIX: Instead of CsvBulkLoader->findExistingRecord out right failing (i.e. no duplicate found) when the duplicate check field is empty, it will now continue on to check other duplicateCheck fields. Added extra testing data to CSVBulkLoaderTest so that it fails.
1 parent 3b02d22 commit d47b202

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

dev/CsvBulkLoader.php

+8-10
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,22 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals
9494
$obj->{"{$relationName}ID"} = $relationObj->ID;
9595
//write if we are not previewing
9696
if (!$preview) {
97-
$obj->write();
98-
$obj->flushCache(); // avoid relation caching confusion
97+
$obj->write();
98+
$obj->flushCache(); // avoid relation caching confusion
9999
}
100100

101101
} elseif(strpos($fieldName, '.') !== false) {
102102
// we have a relation column with dot notation
103-
list($relationName,$columnName) = explode('.', $fieldName);
103+
list($relationName, $columnName) = explode('.', $fieldName);
104104
// always gives us an component (either empty or existing)
105105
$relationObj = $obj->getComponent($relationName);
106106
if (!$preview) $relationObj->write();
107107
$obj->{"{$relationName}ID"} = $relationObj->ID;
108108
//write if we are not previewing
109109
if (!$preview) {
110-
$obj->write();
111-
$obj->flushCache(); // avoid relation caching confusion
112-
}
110+
$obj->write();
111+
$obj->flushCache(); // avoid relation caching confusion
112+
}
113113
}
114114

115115
}
@@ -166,10 +166,8 @@ public function findExistingObject($record) {
166166
foreach($this->duplicateChecks as $fieldName => $duplicateCheck) {
167167
if(is_string($duplicateCheck)) {
168168
$SQL_fieldName = Convert::raw2sql($duplicateCheck);
169-
if(!isset($record[$SQL_fieldName])) {
170-
return false;
171-
//user_error("CsvBulkLoader:processRecord: Couldn't find duplicate identifier '{$fieldName}'
172-
//in columns", E_USER_ERROR);
169+
if(!isset($record[$SQL_fieldName]) || empty($record[$SQL_fieldName])) { //skip current duplicate check if field value is empty
170+
continue;
173171
}
174172
$SQL_fieldValue = Convert::raw2sql($record[$SQL_fieldName]);
175173
$existingRecord = DataObject::get_one($this->objectClass, "\"$SQL_fieldName\" = '{$SQL_fieldValue}'");

tests/dev/CsvBulkLoaderTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ public function testLoadWithIdentifiers() {
152152
$filepath = $this->getCurrentAbsolutePath() . '/CsvBulkLoaderTest_PlayersWithId.csv';
153153
$loader->duplicateChecks = array(
154154
'ExternalIdentifier' => 'ExternalIdentifier',
155+
'NonExistantIdentifier' => 'ExternalIdentifier',
155156
'ExternalIdentifier' => 'ExternalIdentifier',
157+
'AdditionalIdentifier' => 'ExternalIdentifier'
156158
);
157159
$results = $loader->load($filepath);
158160
$createdPlayers = $results->Created();

0 commit comments

Comments
 (0)