Show messages, when an element can not be deleted.

Fixes issue #43.
This commit is contained in:
Jan Böhmer 2020-05-17 21:52:47 +02:00
parent be47680b60
commit 8951940be1
6 changed files with 973 additions and 888 deletions

View file

@ -43,10 +43,14 @@ declare(strict_types=1);
namespace App\Controller\AdminPages;
use App\DataTables\LogDataTable;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\AbstractNamedDBElement;
use App\Entity\Base\AbstractPartsContainingDBElement;
use App\Entity\Base\AbstractStructuralDBElement;
use App\Entity\Base\PartsContainingRepositoryInterface;
use App\Entity\LabelSystem\LabelProfile;
use App\Entity\PriceInformations\Currency;
use App\Entity\UserSystem\Group;
use App\Entity\UserSystem\User;
use App\Events\SecurityEvent;
use App\Events\SecurityEvents;
@ -385,6 +389,35 @@ abstract class BaseAdminController extends AbstractController
if ($this->isCsrfTokenValid('delete'.$entity->getId(), $request->request->get('_token'))) {
$entityManager = $this->getDoctrine()->getManager();
//Check if we can delete the part (it must not contain Parts)
if ($entity instanceof AbstractPartsContainingDBElement) {
/** @var AbstractPartsContainingRepository $repo */
$repo = $this->entityManager->getRepository($this->entity_class);
if ($repo->getPartsCount($entity) > 0) {
$this->addFlash('error', 'entity.delete.must_not_contain_parts');
return $this->redirectToRoute($this->route_base.'_new');
}
} elseif ($entity instanceof AttachmentType) {
if ($entity->getAttachmentsForType()->count() > 0) {
$this->addFlash('error', 'entity.delete.must_not_contain_attachments');
return $this->redirectToRoute($this->route_base.'_new');
}
} elseif ($entity instanceof Currency) {
if ($entity->getPricedetails()->count() > 0) {
$this->addFlash('error', 'entity.delete.must_not_contain_prices');
return $this->redirectToRoute($this->route_base.'_new');
}
} elseif ($entity instanceof Group) {
if ($entity->getUsers()->count() > 0) {
$this->addFlash('error', 'entity.delete.must_not_contain_users');
return $this->redirectToRoute($this->route_base.'_new');
}
} elseif ($entity instanceof User) {
//TODO: Find a better solution
$this->addFlash('error', 'Currently it is not possible to delete a user, as this would break the log... This will be implemented later...');
return $this->redirectToRoute($this->route_base.'_new');
}
//Check if we need to remove recursively
if ($entity instanceof AbstractStructuralDBElement && $request->get('delete_recursive', false)) {
$recursionHelper->delete($entity, false);