mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Allow setting unique check callback function on the importer class, to be consistency with relation callbacks
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@71977 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
0c5e363a68
commit
8989e89b4e
@ -140,6 +140,8 @@ class CsvBulkLoader extends BulkLoader {
|
|||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
public function findExistingObject($record) {
|
public function findExistingObject($record) {
|
||||||
|
$SNG_objectClass = singleton($this->objectClass);
|
||||||
|
|
||||||
// checking for existing records (only if not already found)
|
// checking for existing records (only if not already found)
|
||||||
foreach($this->duplicateChecks as $fieldName => $duplicateCheck) {
|
foreach($this->duplicateChecks as $fieldName => $duplicateCheck) {
|
||||||
if(is_string($duplicateCheck)) {
|
if(is_string($duplicateCheck)) {
|
||||||
@ -152,10 +154,17 @@ class CsvBulkLoader extends BulkLoader {
|
|||||||
$existingRecord = DataObject::get_one($this->objectClass, "\"$SQL_fieldName\" = '{$SQL_fieldValue}'");
|
$existingRecord = DataObject::get_one($this->objectClass, "\"$SQL_fieldName\" = '{$SQL_fieldValue}'");
|
||||||
if($existingRecord) return $existingRecord;
|
if($existingRecord) return $existingRecord;
|
||||||
} elseif(is_array($duplicateCheck) && isset($duplicateCheck['callback'])) {
|
} elseif(is_array($duplicateCheck) && isset($duplicateCheck['callback'])) {
|
||||||
$existingRecord = singleton($this->objectClass)->{$duplicateCheck['callback']}($record[$fieldName], $record);
|
if($this->hasMethod($duplicateCheck['callback'])) {
|
||||||
|
$existingRecord = $this->{$duplicateCheck['callback']}($record[$fieldName], $record);
|
||||||
|
} elseif($SNG_objectClass->hasMethod($duplicateCheck['callback'])) {
|
||||||
|
$existingRecord = $SNG_objectClass->{$duplicateCheck['callback']}($record[$fieldName], $record);
|
||||||
|
} else {
|
||||||
|
user_error("CsvBulkLoader::processRecord(): {$duplicateCheck['callback']} not found on importer or object class.", E_USER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
if($existingRecord) return $existingRecord;
|
if($existingRecord) return $existingRecord;
|
||||||
} else {
|
} else {
|
||||||
user_error('CsvBulkLoader:processRecord: Wrong format for $duplicateChecks', E_USER_ERROR);
|
user_error('CsvBulkLoader::processRecord(): Wrong format for $duplicateChecks', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user