diff --git a/src/Database/Database.php b/src/Database/Database.php index 94716b7d7..43f4cd923 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -4721,18 +4721,18 @@ public function createOrUpdateDocumentsWithIncrease( $old = Authorization::skip(fn () => $this->withTenant($document->getTenant(), fn () => $this->silent(fn () => $this->getDocument( $collection->getId(), $document->getId(), - [Query::select($selects)], )))); } else { $old = Authorization::skip(fn () => $this->silent(fn () => $this->getDocument( $collection->getId(), $document->getId(), - [Query::select($selects)], ))); } - $disallowed = ['$tenant', '$internalId']; - if ($old->getArrayCopy(disallow: $disallowed) == $document->getArrayCopy(disallow: $disallowed)) { + $updatesPermissions = \in_array('$permissions', \array_keys($document->getArrayCopy())) + && $document->getPermissions() != $old->getPermissions(); + + if ($old->getAttributes() == $document->getAttributes() && !$updatesPermissions) { unset($documents[$key]); continue; } @@ -4767,6 +4767,10 @@ public function createOrUpdateDocumentsWithIncrease( ->setAttribute('$createdAt', empty($createdAt) || !$this->preserveDates ? $time : $createdAt) ->setAttribute('$updatedAt', empty($updatedAt) || !$this->preserveDates ? $time : $updatedAt); + if (!$updatesPermissions) { + $document->setAttribute('$permissions', $old->getPermissions()); + } + if ($this->adapter->getSharedTables()) { if ($this->adapter->getTenantPerDocument()) { if ($document->getTenant() === null) {