From a048124ab736cd4a617cf63da0b5a19a6e1935e7 Mon Sep 17 00:00:00 2001 From: fogelito Date: Wed, 21 Aug 2024 12:58:00 +0300 Subject: [PATCH] return if empty --- src/Database/Database.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Database/Database.php b/src/Database/Database.php index 004eb044b..7675166cf 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4317,8 +4317,13 @@ public function increaseDocumentAttribute(string $collection, string $id, string $validator = new Authorization(self::PERMISSION_UPDATE); + /* @var $document Document */ $document = Authorization::skip(fn () => $this->silent(fn () => $this->getDocument($collection, $id))); // Skip ensures user does not need read permission for this + if($document->isEmpty()){ + return false; + } + $collection = $this->silent(fn () => $this->getCollection($collection)); if ($collection->getId() !== self::METADATA) { @@ -4407,8 +4412,13 @@ public function decreaseDocumentAttribute(string $collection, string $id, string $validator = new Authorization(self::PERMISSION_UPDATE); + /* @var $document Document */ $document = Authorization::skip(fn () => $this->silent(fn () => $this->getDocument($collection, $id))); // Skip ensures user does not need read permission for this + if($document->isEmpty()){ + return false; + } + $collection = $this->silent(fn () => $this->getCollection($collection)); if ($collection->getId() !== self::METADATA) { @@ -4494,11 +4504,16 @@ public function deleteDocument(string $collection, string $id): bool $collection = $this->silent(fn () => $this->getCollection($collection)); $deleted = $this->withTransaction(function () use ($collection, $id, &$document) { + /* @var $document Document */ $document = Authorization::skip(fn () => $this->silent( fn () => $this->getDocument($collection->getId(), $id, forUpdate: true) )); + if($document->isEmpty()){ + return false; + } + $validator = new Authorization(self::PERMISSION_DELETE); if ($collection->getId() !== self::METADATA) {