Skip to content

Commit

Permalink
Fixed exception when trying to export an empty entity list
Browse files Browse the repository at this point in the history
Fixes issue #836
  • Loading branch information
jbtronics committed Feb 1, 2025
1 parent fd7a015 commit aa06e1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Controller/AdminPages/BaseAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,11 @@ protected function _exportAll(EntityManagerInterface $em, EntityExporter $export
$this->denyAccessUnlessGranted('read', $entity);
$entities = $em->getRepository($this->entity_class)->findAll();

if (count($entities) === 0) {
$this->addFlash('error', 'entity.export.flash.error.no_entities');
return $this->redirectToRoute($this->route_base.'_new');
}

return $exporter->exportEntityFromRequest($entities, $request);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Controller/PartImportExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ public function exportParts(Request $request, EntityExporter $entityExporter): R
$ids = $request->query->get('ids', '');
$parts = $this->partsTableActionHandler->idStringToArray($ids);

if ($parts === []) {
throw new \RuntimeException('No parts found!');
if (count($parts) === 0) {
$this->addFlash('error', 'entity.export.flash.error.no_entities');
return $this->redirectToRoute('homepage');
}

//Ensure that we have access to the parts
Expand Down
6 changes: 6 additions & 0 deletions translations/messages.en.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -12323,5 +12323,11 @@ Please note, that you can not impersonate a disabled user. If you try you will g
<target>Profile saved!</target>
</segment>
</unit>
<unit id="8C9ijHM" name="entity.export.flash.error.no_entities">
<segment>
<source>entity.export.flash.error.no_entities</source>
<target>There are no entities to export!</target>
</segment>
</unit>
</file>
</xliff>

0 comments on commit aa06e1d

Please sign in to comment.