Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Use valid class for model importers #1657

Merged
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
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();
Comment on lines -678 to +681
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false is not a valid return type for this method in Silverstripe CMS 5.
It causes a behat failure in various scenarios of the "Import in GridField" behat feature:

Uncaught TypeError: SilverStripe\Admin\ModelAdmin::import(): Return value must be of type SilverStripe\Control\HTTPResponse, bool returned

}

$message = '';
Expand Down
Loading