Permalink
Browse files

BUGFIX: CSVBulkLoader import method now no longer requires files to e…

…nd 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
  • Loading branch information...
1 parent 229760a commit 31a9271c85be73e301a85a2ee98130c166ec90a6 Julian Seidenberg committed with sminnee Aug 4, 2010
Showing with 8 additions and 8 deletions.
  1. +8 −8 code/ModelAdmin.php
View
@@ -523,34 +523,33 @@ public function ImportForm() {
* @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');
Director::redirectBack();
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 @@ function import($data, $form, $request) {
$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

0 comments on commit 31a9271

Please sign in to comment.