Skip to content

Commit fcd166b

Browse files
authored
Merge pull request #683 from utopia-php/fix-update
Don't wait to return empty
2 parents 06ffa2b + 82aa0e8 commit fcd166b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Database/Database.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4275,6 +4275,9 @@ public function updateDocument(string $collection, string $id, Document $documen
42754275
$old = Authorization::skip(fn () => $this->silent(
42764276
fn () => $this->getDocument($collection->getId(), $id, forUpdate: true)
42774277
));
4278+
if ($old->isEmpty()) {
4279+
return new Document();
4280+
}
42784281

42794282
$skipPermissionsUpdate = true;
42804283

@@ -4414,10 +4417,6 @@ public function updateDocument(string $collection, string $id, Document $documen
44144417
}
44154418
}
44164419

4417-
if ($old->isEmpty()) {
4418-
return new Document();
4419-
}
4420-
44214420
if ($shouldUpdate) {
44224421
$document->setAttribute('$updatedAt', ($newUpdatedAt === null || !$this->preserveDates) ? $time : $newUpdatedAt);
44234422
}
@@ -4450,6 +4449,10 @@ public function updateDocument(string $collection, string $id, Document $documen
44504449
return $document;
44514450
});
44524451

4452+
if ($document->isEmpty()) {
4453+
return $document;
4454+
}
4455+
44534456
if ($this->resolveRelationships) {
44544457
$document = $this->silent(fn () => $this->populateDocumentRelationships($collection, $document));
44554458
}
@@ -5573,7 +5576,9 @@ public function deleteDocument(string $collection, string $id): bool
55735576
return $result;
55745577
});
55755578

5576-
$this->trigger(self::EVENT_DOCUMENT_DELETE, $document);
5579+
if ($deleted) {
5580+
$this->trigger(self::EVENT_DOCUMENT_DELETE, $document);
5581+
}
55775582

55785583
return $deleted;
55795584
}

0 commit comments

Comments
 (0)