Skip to content

Commit

Permalink
return if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
fogelito committed Aug 21, 2024
1 parent 0b48921 commit a048124
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a048124

Please sign in to comment.