Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return on empty docs #440

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading