Skip to content

Commit

Permalink
Merge pull request #9929 from open-sausages/pulls/4/csvbulkloader-ext…
Browse files Browse the repository at this point in the history
…ension-hooks

Extension hooks for CsvBulkLoader
  • Loading branch information
chillu committed May 20, 2021
2 parents ad4e488 + 8c0efd3 commit cd71f96
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Dev/CsvBulkLoader.php
Expand Up @@ -69,8 +69,10 @@ public function preview($filepath)
protected function processAll($filepath, $preview = false)
{
$previousDetectLE = ini_get('auto_detect_line_endings');

ini_set('auto_detect_line_endings', true);

$this->extend('onBeforeProcessAll', $filepath, $preview);

$result = BulkLoader_Result::create();

try {
Expand Down Expand Up @@ -145,6 +147,9 @@ protected function processAll($filepath, $preview = false)
} finally {
ini_set('auto_detect_line_endings', $previousDetectLE);
}

$this->extend('onAfterProcessAll', $result, $preview);

return $result;
}

Expand Down Expand Up @@ -382,6 +387,8 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals
}
}

$isChanged = $obj->isChanged();

// write record
if (!$preview) {
$obj->write();
Expand All @@ -392,11 +399,15 @@ protected function processRecord($record, $columnMap, &$results, $preview = fals

// save to results
if ($existingObj) {
// We mark as updated regardless of isChanged, since custom formatters and importers
// might have affected relationships and other records.
$results->addUpdated($obj, $message);
} else {
$results->addCreated($obj, $message);
}

$this->extend('onAfterProcessRecord', $obj, $preview, $isChanged);

$objID = $obj->ID;

$obj->destroy();
Expand Down

0 comments on commit cd71f96

Please sign in to comment.