Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ protected function doBackgroundImport($request)
$this->redirect($importSelectRoute);
}

// Redirect user if they are attempting to upload an invalid CSV file
// Redirect user if they are attempting to upload an invalid CSV/XML file
if ('xml' == $importType && 'xml' !== strtolower(pathinfo($file['name'], PATHINFO_EXTENSION))) {
$errorMessage = $this->context->i18n->__('Not an XML file.');
$this->context->user->setFlash('error', $errorMessage);
$this->redirect($importSelectRoute);
}

if ('csv' == $importType && !$this->checkForValidCsvFile($request, $file['tmp_name'])) {
$errorMessage = $this->context->i18n->__('Not a CSV file (or CSV columns not recognized).');
$this->context->user->setFlash('error', $errorMessage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ protected function doBackgroundValidate($request)
$this->redirect($validateCsvRoute);
}

if ('csv' !== strtolower(pathinfo($file['name'], PATHINFO_EXTENSION))) {
$errorMessage = $this->context->i18n->__('Not a CSV file.');
$this->context->user->setFlash('error', $errorMessage);
$this->redirect($validateCsvRoute);
}

// if we got here without a file upload, go to file selection
if (0 == count($file) || empty($file['tmp_name'])) {
$this->redirect($validateCsvRoute);
Expand All @@ -83,7 +89,7 @@ protected function doBackgroundValidate($request)
// Choose import type based on importType parameter
// This decision used to be based in the file extension but some users
// experienced problems when the extension was omitted
'importType' => $importType,
'importType' => 'csv',
'file' => $file,
];

Expand Down
3 changes: 2 additions & 1 deletion apps/qubit/modules/object/templates/importSelectSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,9 @@
<div id="file-collapse" class="accordion-collapse collapse show" aria-labelledby="file-heading">
<div class="accordion-body">
<div class="mb-3">
<?php 'csv' == $type ? $acceptedType = '.csv' : $acceptedType = '.xml'; ?>
<label for="import-file" class="form-label"><?php echo __('Select a file to import'); ?></label>
<input class="form-control" type="file" id="import-file" name="file">
<input class="form-control" type="file" id="import-file" name="file" accept="<?php echo $acceptedType; ?>">
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/qubit/modules/object/templates/validateCsvSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<div class="accordion-body">
<div class="mb-3">
<label for="file-input" class="form-label"><?php echo __('Select a CSV file to validate'); ?></label>
<input class="form-control" type="file" id="file-input" name="file">
<input class="form-control" type="file" id="file-input" name="file" accept=".csv">
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function addField($name)
{
switch ($name) {
case 'file':
$this->form->setWidget('file', new sfWidgetFormInputFile());
$this->form->setWidget('file', new sfWidgetFormInputFile([], ['accept' => '.skos,.rdf,.xml,.ttl']));
$this->form->setValidator('file', new sfValidatorFile());

break;
Expand Down
Loading