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
@ -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