-
Notifications
You must be signed in to change notification settings - Fork 55
Partial update #886
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
base: main
Are you sure you want to change the base?
Partial update #886
Changes from all commits
0e6ad57
90e3634
4e56486
3d91101
8508d63
6b2a7b5
6d4db8d
e29ee24
f94cc01
3a0c449
a879acd
cec6e43
a50e28f
76b2374
d14540d
40d4b5c
93e0eef
5f0caca
5cda737
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -977,9 +977,18 @@ public function updateDocument(Document $collection, string $id, Document $docum | |
| $spatialAttributes = $this->getSpatialAttributes($collection); | ||
| $collection = $collection->getId(); | ||
| $attributes = $document->getAttributes(); | ||
| $attributes['_createdAt'] = $document->getCreatedAt(); | ||
| $attributes['_updatedAt'] = $document->getUpdatedAt(); | ||
| $attributes['_permissions'] = json_encode($document->getPermissions()); | ||
| if ($document->offsetExists('$updatedAt')) { | ||
| $attributes['_updatedAt'] = $document->getUpdatedAt(); | ||
| } | ||
| if ($document->offsetExists('$id')) { | ||
| $attributes['_uid'] = $document->getId(); | ||
| } | ||
| if ($document->offsetExists('$createdAt')) { | ||
| $attributes['_createdAt'] = $document->getCreatedAt(); | ||
| } | ||
| if ($document->offsetExists('$permissions')) { | ||
| $attributes['_permissions'] = json_encode($document->getPermissions()); | ||
| } | ||
|
|
||
| $name = $this->filter($collection); | ||
| $columns = ''; | ||
|
|
@@ -998,7 +1007,8 @@ public function updateDocument(Document $collection, string $id, Document $docum | |
| * Get current permissions from the database | ||
| */ | ||
| $sqlPermissions = $this->getPDO()->prepare($sql); | ||
| $sqlPermissions->bindValue(':_uid', $document->getId()); | ||
|
|
||
| $sqlPermissions->bindValue(':_uid', $id); | ||
|
|
||
| if ($this->sharedTables) { | ||
| $sqlPermissions->bindValue(':_tenant', $this->tenant); | ||
|
|
@@ -1071,7 +1081,7 @@ public function updateDocument(Document $collection, string $id, Document $docum | |
| $removeQuery = $this->trigger(Database::EVENT_PERMISSIONS_DELETE, $removeQuery); | ||
|
|
||
| $stmtRemovePermissions = $this->getPDO()->prepare($removeQuery); | ||
| $stmtRemovePermissions->bindValue(':_uid', $document->getId()); | ||
| $stmtRemovePermissions->bindValue(':_uid', $id); | ||
|
|
||
| if ($this->sharedTables) { | ||
| $stmtRemovePermissions->bindValue(':_tenant', $this->tenant); | ||
|
|
@@ -1119,7 +1129,8 @@ public function updateDocument(Document $collection, string $id, Document $docum | |
|
|
||
| $stmtAddPermissions = $this->getPDO()->prepare($sql); | ||
|
|
||
| $stmtAddPermissions->bindValue(":_uid", $document->getId()); | ||
| $newUid = $document->offsetExists('$id') ? $document->getId() : $id; | ||
| $stmtAddPermissions->bindValue(":_uid", $newUid); | ||
|
|
||
| if ($this->sharedTables) { | ||
| $stmtAddPermissions->bindValue(":_tenant", $this->tenant); | ||
|
|
@@ -1168,7 +1179,7 @@ public function updateDocument(Document $collection, string $id, Document $docum | |
|
|
||
| $sql = " | ||
| UPDATE {$this->getSQLTable($name)} | ||
| SET {$columns} _uid = :_newUid | ||
| SET " . \rtrim($columns, ',') . " | ||
| WHERE _id=:_sequence | ||
| {$this->getTenantQuery($collection)} | ||
| "; | ||
|
Comment on lines
1180
to
1185
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Before this PR, One concrete path: A guard before the |
||
|
|
@@ -1178,7 +1189,6 @@ public function updateDocument(Document $collection, string $id, Document $docum | |
| $stmt = $this->getPDO()->prepare($sql); | ||
|
|
||
| $stmt->bindValue(':_sequence', $document->getSequence()); | ||
| $stmt->bindValue(':_newUid', $document->getId()); | ||
|
|
||
| if ($this->sharedTables) { | ||
| $stmt->bindValue(':_tenant', $this->tenant); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before this PR the SET clause always had at least
_uid = :_newUidas a guaranteed trailing column. That fallback is now removed. When the partial document carries no regular attributes (e.g.$permissions-only) and$shouldUpdateis false (so$updatedAtis not injected),$attributesis empty,$columnsstays'', and\rtrim('', ',')returns''. The resulting SQL —UPDATE … SET WHERE _id=:_sequence— is a syntax error that causes a PDO exception.A concrete failing path:
updateDocument($col, $id, new Document(['$permissions' => $exactSamePerms])). No attribute changes →$shouldUpdate = false→ no$updatedAtattribute set. No$idin the document → no_uidin attributes. Permissions unchanged →$skipPermissionsUpdate = true. Adapter called with empty$attributes→$columns = ''→ invalid SQL.The same gap exists in
Postgres.phpandSQLite.php.