Merge pull request #9929 from open-sausages/pulls/4/csvbulkloader-extension-hooks

Extension hooks for CsvBulkLoader
This commit is contained in:
Ingo Schommer 2021-05-21 11:48:56 +12:00 committed by GitHub
commit cd71f964cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -69,8 +69,10 @@ class CsvBulkLoader extends BulkLoader
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 {
@ -145,6 +147,9 @@ class CsvBulkLoader extends BulkLoader
} finally {
ini_set('auto_detect_line_endings', $previousDetectLE);
}
$this->extend('onAfterProcessAll', $result, $preview);
return $result;
}
@ -382,6 +387,8 @@ class CsvBulkLoader extends BulkLoader
}
}
$isChanged = $obj->isChanged();
// write record
if (!$preview) {
$obj->write();
@ -392,11 +399,15 @@ class CsvBulkLoader extends BulkLoader
// 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();