@@ -1272,14 +1272,28 @@ public function updateDocument(Document $collection, string $id, Document $docum
12721272 $ spatialAttributes = $ this ->getSpatialAttributes ($ collection );
12731273 $ collection = $ collection ->getId ();
12741274 $ attributes = $ document ->getAttributes ();
1275- $ attributes ['_createdAt ' ] = $ document ->getCreatedAt ();
1276- $ attributes ['_updatedAt ' ] = $ document ->getUpdatedAt ();
1277- $ attributes ['_permissions ' ] = json_encode ($ document ->getPermissions ());
1275+
1276+ if ($ document ->offsetExists ('$updatedAt ' )) {
1277+ $ attributes ['_updatedAt ' ] = $ document ->getUpdatedAt ();
1278+ }
1279+ if ($ document ->offsetExists ('$createdAt ' )) {
1280+ $ attributes ['_createdAt ' ] = $ document ->getCreatedAt ();
1281+ }
1282+ if ($ document ->offsetExists ('$id ' )) {
1283+ $ attributes ['_uid ' ] = $ document ->getId ();
1284+ }
1285+ if ($ document ->offsetExists ('$permissions ' )) {
1286+ $ attributes ['_permissions ' ] = json_encode ($ document ->getPermissions ());
1287+ }
12781288
12791289 if ($ this ->sharedTables ) {
12801290 $ attributes ['_tenant ' ] = $ this ->tenant ;
12811291 }
12821292
1293+ if (empty ($ attributes )) {
1294+ return $ document ;
1295+ }
1296+
12831297 $ name = $ this ->filter ($ collection );
12841298 $ columns = '' ;
12851299
@@ -1297,7 +1311,7 @@ public function updateDocument(Document $collection, string $id, Document $docum
12971311 * Get current permissions from the database
12981312 */
12991313 $ permissionsStmt = $ this ->getPDO ()->prepare ($ sql );
1300- $ permissionsStmt ->bindValue (':_uid ' , $ document -> getId () );
1314+ $ permissionsStmt ->bindValue (':_uid ' , $ id );
13011315
13021316 if ($ this ->sharedTables ) {
13031317 $ permissionsStmt ->bindValue (':_tenant ' , $ this ->tenant );
@@ -1369,7 +1383,7 @@ public function updateDocument(Document $collection, string $id, Document $docum
13691383 $ removeQuery = $ this ->trigger (Database::EVENT_PERMISSIONS_DELETE , $ removeQuery );
13701384
13711385 $ stmtRemovePermissions = $ this ->getPDO ()->prepare ($ removeQuery );
1372- $ stmtRemovePermissions ->bindValue (':_uid ' , $ document -> getId () );
1386+ $ stmtRemovePermissions ->bindValue (':_uid ' , $ id );
13731387
13741388 if ($ this ->sharedTables ) {
13751389 $ stmtRemovePermissions ->bindValue (':_tenant ' , $ this ->tenant );
@@ -1404,7 +1418,8 @@ public function updateDocument(Document $collection, string $id, Document $docum
14041418
14051419 $ stmtAddPermissions = $ this ->getPDO ()->prepare ($ sql );
14061420
1407- $ stmtAddPermissions ->bindValue (":_uid " , $ document ->getId ());
1421+ $ newUid = $ document ->offsetExists ('$id ' ) ? $ document ->getId () : $ id ;
1422+ $ stmtAddPermissions ->bindValue (":_uid " , $ newUid );
14081423 if ($ this ->sharedTables ) {
14091424 $ stmtAddPermissions ->bindValue (":_tenant " , $ this ->tenant );
14101425 }
@@ -1456,7 +1471,7 @@ public function updateDocument(Document $collection, string $id, Document $docum
14561471
14571472 $ sql = "
14581473 UPDATE ` {$ this ->getNamespace ()}_ {$ name }`
1459- SET {$ columns }, _uid = :_newUid
1474+ SET {$ columns }
14601475 WHERE _uid = :_existingUid
14611476 {$ this ->getTenantQuery ($ collection )}
14621477 " ;
@@ -1466,7 +1481,6 @@ public function updateDocument(Document $collection, string $id, Document $docum
14661481 $ stmt = $ this ->getPDO ()->prepare ($ sql );
14671482
14681483 $ stmt ->bindValue (':_existingUid ' , $ id );
1469- $ stmt ->bindValue (':_newUid ' , $ document ->getId ());
14701484
14711485 if ($ this ->sharedTables ) {
14721486 $ stmt ->bindValue (':_tenant ' , $ this ->tenant );
0 commit comments