From 3020576f082919161bbf5da0a97b1c1b5a8e6c54 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 19 Mar 2013 10:57:51 +0000 Subject: [PATCH 1/2] FIX Adding preview method to CsvBulkLoader Currently the CsvBulkLoader doesn't implement the preview method even though it's processor function has the $preview flag. --- dev/CsvBulkLoader.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/dev/CsvBulkLoader.php b/dev/CsvBulkLoader.php index 5e8022a98..4a7ee4d31 100644 --- a/dev/CsvBulkLoader.php +++ b/dev/CsvBulkLoader.php @@ -32,6 +32,13 @@ class CsvBulkLoader extends BulkLoader { */ public $hasHeaderRow = true; + /** + * @inheritDoc + */ + public function preview($filepath) { + return $this->processAll($filepath, true); + } + protected function processAll($filepath, $preview = false) { $results = new BulkLoader_Result(); From 0d57f7b19af4765dd492c8449da1c6e6d32779f6 Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Tue, 19 Mar 2013 11:23:58 +0000 Subject: [PATCH 2/2] FIX processAll method respects $preview flag The preview flag is now respected more thoroughly to stop writing of related objects --- dev/CsvBulkLoader.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/dev/CsvBulkLoader.php b/dev/CsvBulkLoader.php index 4a7ee4d31..8b4d00c9e 100644 --- a/dev/CsvBulkLoader.php +++ b/dev/CsvBulkLoader.php @@ -88,27 +88,36 @@ class CsvBulkLoader extends BulkLoader { if(!$relationObj || !$relationObj->exists()) { $relationClass = $obj->has_one($relationName); $relationObj = new $relationClass(); - $relationObj->write(); + //write if we aren't previewing + if (!$preview) $relationObj->write(); } $obj->{"{$relationName}ID"} = $relationObj->ID; - $obj->write(); - $obj->flushCache(); // avoid relation caching confusion + //write if we are not previewing + if (!$preview) { + $obj->write(); + $obj->flushCache(); // avoid relation caching confusion + } } elseif(strpos($fieldName, '.') !== false) { // 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) $relationObj = $obj->getComponent($relationName); - $relationObj->write(); + if (!$preview) $relationObj->write(); $obj->{"{$relationName}ID"} = $relationObj->ID; - $obj->write(); - $obj->flushCache(); // avoid relation caching confusion + //write if we are not previewing + if (!$preview) { + $obj->write(); + $obj->flushCache(); // avoid relation caching confusion + } } } // second run: save data foreach($record as $fieldName => $val) { + //break out of the loop if we are previewing + if ($preview) break; if($this->isNullValue($val, $fieldName)) continue; if(strpos($fieldName, '->') !== FALSE) { $funcName = substr($fieldName, 2);