From 1f258f7043ef45ecfa3c8177df0f0177a7c1c8e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Zapletal?= Date: Tue, 9 Apr 2024 21:36:53 -0600 Subject: [PATCH] Improved user datagrid --- src/Collection/ReadBuilder/ReadBuilder.php | 5 ----- src/Collection/WriteBuilder/WriteBuilder.php | 5 ----- src/Http/Request/Collection/DeleteRequest.php | 11 ++++++++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Collection/ReadBuilder/ReadBuilder.php b/src/Collection/ReadBuilder/ReadBuilder.php index 0138ef1..6bbaf00 100644 --- a/src/Collection/ReadBuilder/ReadBuilder.php +++ b/src/Collection/ReadBuilder/ReadBuilder.php @@ -227,11 +227,6 @@ public function toArray(): array return array_values($cols); } - public function dump(): void - { - dumpe($this->build()->toArray()); - } - protected function addIdColumnIfNotExists(): void { if (!array_key_exists('id', $this->columns)) { diff --git a/src/Collection/WriteBuilder/WriteBuilder.php b/src/Collection/WriteBuilder/WriteBuilder.php index e8ab19d..ed5db8a 100644 --- a/src/Collection/WriteBuilder/WriteBuilder.php +++ b/src/Collection/WriteBuilder/WriteBuilder.php @@ -313,11 +313,6 @@ public function getSerializedValues(): array return $values; } - public function dump(): void - { - dumpe($this->build()->toArray()); - } - private function recreateRules(IField $field): IField { $rules = $field->getRules(); diff --git a/src/Http/Request/Collection/DeleteRequest.php b/src/Http/Request/Collection/DeleteRequest.php index 0c5cc4f..89a8a70 100644 --- a/src/Http/Request/Collection/DeleteRequest.php +++ b/src/Http/Request/Collection/DeleteRequest.php @@ -3,6 +3,8 @@ namespace Megio\Http\Request\Collection; +use Doctrine\DBAL\Exception\ConstraintViolationException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Megio\Collection\RecipeFinder; use Megio\Event\Collection\EventType; use Megio\Http\Request\Request; @@ -74,7 +76,14 @@ public function process(array $data): Response return $dispatcher->getResponse(); } - $qb->delete()->getQuery()->execute(); + try { + $qb->delete()->getQuery()->execute(); + } catch (ConstraintViolationException $e) { + $response = $this->error([$e->getMessage()], 400); + $event = new OnExceptionEvent(EventType::DELETE, $data, $recipe, $e, $this->request, $response); + $dispatcher = $this->dispatcher->dispatch($event, Events::ON_EXCEPTION->value); + return $dispatcher->getResponse(); + } $result = [ 'ids' => $data['ids'],