mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Restored c4eac5310e
(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.
This commit is contained in:
parent
3b02d22989
commit
d47b202697
@ -94,22 +94,22 @@ class CsvBulkLoader extends BulkLoader {
|
|||||||
$obj->{"{$relationName}ID"} = $relationObj->ID;
|
$obj->{"{$relationName}ID"} = $relationObj->ID;
|
||||||
//write if we are not previewing
|
//write if we are not previewing
|
||||||
if (!$preview) {
|
if (!$preview) {
|
||||||
$obj->write();
|
$obj->write();
|
||||||
$obj->flushCache(); // avoid relation caching confusion
|
$obj->flushCache(); // avoid relation caching confusion
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif(strpos($fieldName, '.') !== false) {
|
} elseif(strpos($fieldName, '.') !== false) {
|
||||||
// we have a relation column with dot notation
|
// we have a relation column with dot notation
|
||||||
list($relationName,$columnName) = explode('.', $fieldName);
|
list($relationName, $columnName) = explode('.', $fieldName);
|
||||||
// always gives us an component (either empty or existing)
|
// always gives us an component (either empty or existing)
|
||||||
$relationObj = $obj->getComponent($relationName);
|
$relationObj = $obj->getComponent($relationName);
|
||||||
if (!$preview) $relationObj->write();
|
if (!$preview) $relationObj->write();
|
||||||
$obj->{"{$relationName}ID"} = $relationObj->ID;
|
$obj->{"{$relationName}ID"} = $relationObj->ID;
|
||||||
//write if we are not previewing
|
//write if we are not previewing
|
||||||
if (!$preview) {
|
if (!$preview) {
|
||||||
$obj->write();
|
$obj->write();
|
||||||
$obj->flushCache(); // avoid relation caching confusion
|
$obj->flushCache(); // avoid relation caching confusion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -166,10 +166,8 @@ class CsvBulkLoader extends BulkLoader {
|
|||||||
foreach($this->duplicateChecks as $fieldName => $duplicateCheck) {
|
foreach($this->duplicateChecks as $fieldName => $duplicateCheck) {
|
||||||
if(is_string($duplicateCheck)) {
|
if(is_string($duplicateCheck)) {
|
||||||
$SQL_fieldName = Convert::raw2sql($duplicateCheck);
|
$SQL_fieldName = Convert::raw2sql($duplicateCheck);
|
||||||
if(!isset($record[$SQL_fieldName])) {
|
if(!isset($record[$SQL_fieldName]) || empty($record[$SQL_fieldName])) { //skip current duplicate check if field value is empty
|
||||||
return false;
|
continue;
|
||||||
//user_error("CsvBulkLoader:processRecord: Couldn't find duplicate identifier '{$fieldName}'
|
|
||||||
//in columns", E_USER_ERROR);
|
|
||||||
}
|
}
|
||||||
$SQL_fieldValue = Convert::raw2sql($record[$SQL_fieldName]);
|
$SQL_fieldValue = Convert::raw2sql($record[$SQL_fieldName]);
|
||||||
$existingRecord = DataObject::get_one($this->objectClass, "\"$SQL_fieldName\" = '{$SQL_fieldValue}'");
|
$existingRecord = DataObject::get_one($this->objectClass, "\"$SQL_fieldName\" = '{$SQL_fieldValue}'");
|
||||||
|
@ -152,7 +152,9 @@ class CsvBulkLoaderTest extends SapphireTest {
|
|||||||
$filepath = $this->getCurrentAbsolutePath() . '/CsvBulkLoaderTest_PlayersWithId.csv';
|
$filepath = $this->getCurrentAbsolutePath() . '/CsvBulkLoaderTest_PlayersWithId.csv';
|
||||||
$loader->duplicateChecks = array(
|
$loader->duplicateChecks = array(
|
||||||
'ExternalIdentifier' => 'ExternalIdentifier',
|
'ExternalIdentifier' => 'ExternalIdentifier',
|
||||||
|
'NonExistantIdentifier' => 'ExternalIdentifier',
|
||||||
'ExternalIdentifier' => 'ExternalIdentifier',
|
'ExternalIdentifier' => 'ExternalIdentifier',
|
||||||
|
'AdditionalIdentifier' => 'ExternalIdentifier'
|
||||||
);
|
);
|
||||||
$results = $loader->load($filepath);
|
$results = $loader->load($filepath);
|
||||||
$createdPlayers = $results->Created();
|
$createdPlayers = $results->Created();
|
||||||
|
Loading…
Reference in New Issue
Block a user