Skip to content

Commit

Permalink
FIX Use valid class for model importers
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jan 23, 2024
1 parent 5d57649 commit c06b2f2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions code/ModelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,17 +545,20 @@ public function isManagedModel(string $modelClassOrModelTab): bool
public function getModelImporters()
{
$importerClasses = $this->config()->get('model_importers');
$models = $this->getManagedModels();

// fallback to all defined models if not explicitly defined
if (is_null($importerClasses)) {
$models = $this->getManagedModels();
foreach ($models as $modelName => $options) {
$importerClasses[$modelName] = 'SilverStripe\\Dev\\CsvBulkLoader';
}
}

$importers = [];
foreach ($importerClasses as $modelClass => $importerClass) {
if (isset($models[$modelClass])) {
$modelClass = $models[$modelClass]['dataClass'];
}
$importer = new $importerClass($modelClass);
if (ClassInfo::hasMethod($importer, 'setCheckPermissions')) {
$importer->setCheckPermissions(true);
Expand Down Expand Up @@ -675,8 +678,7 @@ public function import(array $data, Form $form): HTTPResponse
$results = $loader->load($_FILES['_CsvFile']['tmp_name']);
} catch (HTTPResponse_Exception $e) {
$form->sessionMessage($e->getMessage(), ValidationResult::TYPE_ERROR);
$this->redirectBack();
return false;
return $this->redirectBack();
}

$message = '';
Expand Down

0 comments on commit c06b2f2

Please sign in to comment.