mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Show error message if a sub element contains parts while recursive deletion of StructuralDBElement
This commit is contained in:
parent
26cc4b4836
commit
a9642b27a6
2 changed files with 16 additions and 3 deletions
|
@ -81,6 +81,8 @@ use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||||
use Symfony\Component\Validator\ConstraintViolationList;
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
|
use function Symfony\Component\Translation\t;
|
||||||
|
|
||||||
abstract class BaseAdminController extends AbstractController
|
abstract class BaseAdminController extends AbstractController
|
||||||
{
|
{
|
||||||
protected $entity_class = '';
|
protected $entity_class = '';
|
||||||
|
@ -419,7 +421,7 @@ abstract class BaseAdminController extends AbstractController
|
||||||
/** @var AbstractPartsContainingRepository $repo */
|
/** @var AbstractPartsContainingRepository $repo */
|
||||||
$repo = $this->entityManager->getRepository($this->entity_class);
|
$repo = $this->entityManager->getRepository($this->entity_class);
|
||||||
if ($repo->getPartsCount($entity) > 0) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -442,7 +444,18 @@ abstract class BaseAdminController extends AbstractController
|
||||||
|
|
||||||
//Check if we need to remove recursively
|
//Check if we need to remove recursively
|
||||||
if ($entity instanceof AbstractStructuralDBElement && $request->get('delete_recursive', false)) {
|
if ($entity instanceof AbstractStructuralDBElement && $request->get('delete_recursive', false)) {
|
||||||
$recursionHelper->delete($entity, 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 {
|
} else {
|
||||||
if ($entity instanceof AbstractStructuralDBElement) {
|
if ($entity instanceof AbstractStructuralDBElement) {
|
||||||
$parent = $entity->getParent();
|
$parent = $entity->getParent();
|
||||||
|
|
|
@ -9078,7 +9078,7 @@ Element 3</target>
|
||||||
<unit id="D6I2Q6C" name="entity.delete.must_not_contain_parts">
|
<unit id="D6I2Q6C" name="entity.delete.must_not_contain_parts">
|
||||||
<segment>
|
<segment>
|
||||||
<source>entity.delete.must_not_contain_parts</source>
|
<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>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
<unit id="hu8Y98Q" name="entity.delete.must_not_contain_attachments">
|
<unit id="hu8Y98Q" name="entity.delete.must_not_contain_attachments">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue