diff --git a/src/Database/Database.php b/src/Database/Database.php index 004eb044b..c276ce232 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) {