Skip to content

Commit 30aa37f

Browse files
committed
Fix missing tenant on return value
1 parent a24dc08 commit 30aa37f

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/Database/Database.php

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4144,6 +4144,10 @@ public function updateDocuments(
41444144
unset($updates['$createdAt']);
41454145
unset($updates['$tenant']);
41464146

4147+
if ($this->adapter->getSharedTables()) {
4148+
$updates['$tenant'] = $this->adapter->getTenant();
4149+
}
4150+
41474151
if (!$this->preserveDates) {
41484152
$updates['$updatedAt'] = DateTime::now();
41494153
}
@@ -4165,7 +4169,6 @@ public function updateDocuments(
41654169
$last = $cursor;
41664170
$modified = 0;
41674171

4168-
// Resolve and update relationships
41694172
while (true) {
41704173
if ($limit && $limit < $batchSize) {
41714174
$batchSize = $limit;
@@ -4192,12 +4195,14 @@ public function updateDocuments(
41924195
}
41934196

41944197
foreach ($batch as &$document) {
4198+
$new = new Document(\array_merge($document->getArrayCopy(), $updates->getArrayCopy()));
4199+
41954200
if ($this->resolveRelationships) {
4196-
$newDocument = new Document(array_merge($document->getArrayCopy(), $updates->getArrayCopy()));
4197-
$this->silent(fn () => $this->updateDocumentRelationships($collection, $document, $newDocument));
4198-
$document = $newDocument;
4201+
$this->silent(fn () => $this->updateDocumentRelationships($collection, $document, $new));
41994202
}
42004203

4204+
$document = $new;
4205+
42014206
// Check if document was updated after the request timestamp
42024207
try {
42034208
$oldUpdatedAt = new \DateTime($document->getUpdatedAt());
@@ -4220,19 +4225,10 @@ public function updateDocuments(
42204225
);
42214226
});
42224227

4223-
unset($document);
4224-
4225-
foreach ($batch as $document) {
4226-
if ($this->getSharedTables() && $this->getTenantPerDocument()) {
4227-
$this->withTenant($document->getTenant(), function () use ($collection, $document) {
4228-
$this->purgeCachedDocument($collection->getId(), $document->getId());
4229-
});
4230-
} else {
4231-
$this->purgeCachedDocument($collection->getId(), $document->getId());
4232-
}
4233-
4234-
$document = $this->decode($collection, $document);
4235-
$onNext && $onNext($document);
4228+
foreach ($batch as $i=>$doc) {
4229+
$this->purgeCachedDocument($collection->getId(), $doc->getId());
4230+
$doc = $this->decode($collection, $doc);
4231+
$onNext && $onNext($doc);
42364232
$modified++;
42374233
}
42384234

@@ -6112,7 +6108,7 @@ public function decode(Document $collection, Document $document, array $selectio
61126108
}
61136109
}
61146110

6115-
$attributes = array_merge($attributes, $this->getInternalAttributes());
6111+
$attributes = \array_merge($attributes, $this->getInternalAttributes());
61166112

61176113
foreach ($attributes as $attribute) {
61186114
$key = $attribute['$id'] ?? '';
@@ -6132,7 +6128,7 @@ public function decode(Document $collection, Document $document, array $selectio
61326128
$value = (is_null($value)) ? [] : $value;
61336129

61346130
foreach ($value as &$node) {
6135-
foreach (array_reverse($filters) as $filter) {
6131+
foreach (\array_reverse($filters) as $filter) {
61366132
$node = $this->decodeAttribute($filter, $node, $document);
61376133
}
61386134
}

0 commit comments

Comments
 (0)