mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
BUGFIX: CSVBulkLoader import method now no longer requires files to end in '.csv'. Some projects want to import files in CSV format, but not of csv file type.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@108887 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
229760a1e1
commit
31a9271c85
@ -523,19 +523,18 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
* @param SS_HTTPRequest $request
|
||||
*/
|
||||
function import($data, $form, $request) {
|
||||
|
||||
|
||||
$modelName = $data['ClassName'];
|
||||
|
||||
|
||||
if(!$this->showImportForm() || (is_array($this->showImportForm()) && !in_array($modelName,$this->showImportForm()))) return false;
|
||||
$importers = $this->parentController->getModelImporters();
|
||||
$importerClass = $importers[$modelName];
|
||||
|
||||
|
||||
$loader = new $importerClass($data['ClassName']);
|
||||
|
||||
|
||||
// File wasn't properly uploaded, show a reminder to the user
|
||||
if(
|
||||
empty($_FILES['_CsvFile']['tmp_name']) ||
|
||||
array_search($_FILES['_CsvFile']['type'], array('text/csv', 'text/plain')) === false ||
|
||||
file_get_contents($_FILES['_CsvFile']['tmp_name']) == ''
|
||||
) {
|
||||
$form->sessionMessage(_t('ModelAdmin.NOCSVFILE', 'Please browse for a CSV file to import'), 'good');
|
||||
@ -543,14 +542,14 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($data['EmptyBeforeImport']) && $data['EmptyBeforeImport']) { //clear database before import
|
||||
if (!empty($data['EmptyBeforeImport']) && $data['EmptyBeforeImport']) { //clear database before import
|
||||
$loader->deleteExistingRecords = true;
|
||||
}
|
||||
$results = $loader->load($_FILES['_CsvFile']['tmp_name']);
|
||||
|
||||
$message = '';
|
||||
if($results->CreatedCount()) $message .= sprintf(
|
||||
_t('ModelAdmin.IMPORTEDRECORDS', "Imported %s records."),
|
||||
_t('ModelAdmin.IMPORTEDRECORDS', "Imported %s records."),
|
||||
$results->CreatedCount()
|
||||
);
|
||||
if($results->UpdatedCount()) $message .= sprintf(
|
||||
@ -562,11 +561,12 @@ class ModelAdmin_CollectionController extends Controller {
|
||||
$results->DeletedCount()
|
||||
);
|
||||
if(!$results->CreatedCount() && !$results->UpdatedCount()) $message .= _t('ModelAdmin.NOIMPORT', "Nothing to import");
|
||||
|
||||
|
||||
$form->sessionMessage($message, 'good');
|
||||
Director::redirectBack();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the columns available in the column selection field.
|
||||
* Overload this to make other columns available
|
||||
|
Loading…
Reference in New Issue
Block a user