Skip to content

Commit

Permalink
FIX Use valid class for model importers (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli authored Feb 1, 2024
1 parent 925e06f commit 725a9a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion code/ModelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,17 +610,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
9 changes: 9 additions & 0 deletions tests/php/ModelAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ public function testGetGridField()
);
}

public function testGetModelImporters()
{
$admin = new ModelAdminTest\MultiModelAdmin();
$importers = $admin->getModelImporters();
$this->assertCount(2, $importers);
$this->assertArrayHasKey(Contact::class, $importers);
$this->assertArrayHasKey(Player::class, $importers);
}

public function testGetManagedModels()
{
$admin = new ModelAdminTest\MultiModelAdmin();
Expand Down

0 comments on commit 725a9a1

Please sign in to comment.