Permalink
Browse files

FIX processAll method respects $preview flag

The preview flag is now respected more thoroughly to stop writing of related objects
  • Loading branch information...
1 parent 3020576 commit 0d57f7b19af4765dd492c8449da1c6e6d32779f6 @dhensby dhensby committed Mar 19, 2013
Showing with 16 additions and 7 deletions.
  1. +16 −7 dev/CsvBulkLoader.php
View
@@ -88,27 +88,36 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals
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);

0 comments on commit 0d57f7b

Please sign in to comment.