Show error message if a sub element contains parts while recursive deletion of StructuralDBElement

This commit is contained in:
Jan Böhmer 2022-09-21 13:05:52 +02:00
parent 26cc4b4836
commit a9642b27a6
2 changed files with 16 additions and 3 deletions

View file

@ -81,6 +81,8 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Validator\ConstraintViolationList;
use Symfony\Contracts\Translation\TranslatorInterface;
use function Symfony\Component\Translation\t;
abstract class BaseAdminController extends AbstractController
{
protected $entity_class = '';
@ -419,7 +421,7 @@ abstract class BaseAdminController extends AbstractController
/** @var AbstractPartsContainingRepository $repo */
$repo = $this->entityManager->getRepository($this->entity_class);
if ($repo->getPartsCount($entity) > 0) {
$this->addFlash('error', 'entity.delete.must_not_contain_parts');
$this->addFlash('error', t('entity.delete.must_not_contain_parts', ['%PATH%' => $entity->getFullPath()]));
return false;
}
@ -442,7 +444,18 @@ abstract class BaseAdminController extends AbstractController
//Check if we need to remove recursively
if ($entity instanceof AbstractStructuralDBElement && $request->get('delete_recursive', false)) {
$can_delete = true;
//Check if any of the children can not be deleted, cause it contains parts
$recursionHelper->execute($entity, function (AbstractStructuralDBElement $element) use (&$can_delete) {
if(!$this->deleteCheck($element)) {
$can_delete = false;
}
});
if($can_delete) {
$recursionHelper->delete($entity, false);
} else {
return $this->redirectToRoute($this->route_base.'_edit', ['id' => $entity->getID()]);
}
} else {
if ($entity instanceof AbstractStructuralDBElement) {
$parent = $entity->getParent();

View file

@ -9078,7 +9078,7 @@ Element 3</target>
<unit id="D6I2Q6C" name="entity.delete.must_not_contain_parts">
<segment>
<source>entity.delete.must_not_contain_parts</source>
<target>Element still contains parts! You have to move the parts, to be able to delete this element.</target>
<target>Element "%PATH%" still contains parts! You have to move the parts, to be able to delete this element.</target>
</segment>
</unit>
<unit id="hu8Y98Q" name="entity.delete.must_not_contain_attachments">