From bd5c8520bbd2b7de2d2f214e7f4e9cd50dc481e0 Mon Sep 17 00:00:00 2001 From: Fred Condo Date: Mon, 29 Apr 2013 17:22:12 -0700 Subject: [PATCH] FIX: Use the correct variable as the key into $record It was using $fieldName, which is the CSV field name, not the database field name. This prevents duplicate detection from working. It now properly uses $SQL_fieldName. Update CsvBulkLoaderTest to remove keys that are nonexistent in the CSV test data. Having them causes the test to fail with an undefined-index error. This did not previously fail because of the bug in CsvBulkLoader that this patch fixes. This partially reverts c4eac53. --- dev/CsvBulkLoader.php | 2 +- tests/dev/CsvBulkLoaderTest.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/dev/CsvBulkLoader.php b/dev/CsvBulkLoader.php index 0fb246be9..db166d890 100644 --- a/dev/CsvBulkLoader.php +++ b/dev/CsvBulkLoader.php @@ -166,7 +166,7 @@ class CsvBulkLoader extends BulkLoader { foreach($this->duplicateChecks as $fieldName => $duplicateCheck) { if(is_string($duplicateCheck)) { $SQL_fieldName = Convert::raw2sql($duplicateCheck); - if(!isset($record[$fieldName]) || empty($record[$fieldName])) { //skip current duplicate check if field value is empty + if(!isset($record[$SQL_fieldName]) || empty($record[$SQL_fieldName])) { //skip current duplicate check if field value is empty continue; } $SQL_fieldValue = Convert::raw2sql($record[$fieldName]); diff --git a/tests/dev/CsvBulkLoaderTest.php b/tests/dev/CsvBulkLoaderTest.php index d1df15000..53cacbdb5 100644 --- a/tests/dev/CsvBulkLoaderTest.php +++ b/tests/dev/CsvBulkLoaderTest.php @@ -152,9 +152,7 @@ class CsvBulkLoaderTest extends SapphireTest { $filepath = $this->getCurrentAbsolutePath() . '/CsvBulkLoaderTest_PlayersWithId.csv'; $loader->duplicateChecks = array( 'ExternalIdentifier' => 'ExternalIdentifier', - 'NonExistantIdentifier' => 'ExternalIdentifier', 'ExternalIdentifier' => 'ExternalIdentifier', - 'AdditionalIdentifier' => 'ExternalIdentifier' ); $results = $loader->load($filepath); $createdPlayers = $results->Created();