From b58f6e947979f260f31e75a88aa27c83dd022baf Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Sat, 25 Jul 2026 21:28:00 -0400 Subject: [PATCH] fix: empty object Signed-off-by: Sebastian Krupinski --- core/lib/Stores/UserAccountsStore.php | 30 +++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/core/lib/Stores/UserAccountsStore.php b/core/lib/Stores/UserAccountsStore.php index 743c48d..3a20c91 100644 --- a/core/lib/Stores/UserAccountsStore.php +++ b/core/lib/Stores/UserAccountsStore.php @@ -177,8 +177,8 @@ class UserAccountsStore $userData['uid'] = $userData['uid'] ?? UUID::v4(); $userData['enabled'] = $userData['enabled'] ?? true; $userData['roles'] = $userData['roles'] ?? []; - $userData['profile'] = $userData['profile'] ?? []; - $userData['settings'] = $userData['settings'] ?? []; + $userData['profile'] = (object) ($userData['profile'] ?? []); + $userData['settings'] = (object) ($userData['settings'] ?? []); $this->store->selectCollection('user_accounts')->insertOne($userData); @@ -232,16 +232,25 @@ class UserAccountsStore return false; } + $collection = $this->store->selectCollection('user_accounts'); + + // Repair legacy documents where 'profile' was stored as an empty BSON array: + // dot-notation $set below cannot add a named field to an array. + $collection->updateOne( + ['tid' => $tenant, 'uid' => $uid, 'profile' => []], + ['$set' => ['profile' => (object) []]] + ); + $updates = []; foreach ($profileFields as $key => $value) { $updates["profile.{$key}"] = $value; } - $result = $this->store->selectCollection('user_accounts')->updateOne( + $result = $collection->updateOne( ['tid' => $tenant, 'uid' => $uid], ['$set' => $updates] ); - + return $result->getModifiedCount() > 0; } @@ -307,16 +316,25 @@ class UserAccountsStore return false; } + $collection = $this->store->selectCollection('user_accounts'); + + // Repair legacy documents where 'settings' was stored as an empty BSON array: + // dot-notation $set below cannot add a named field to an array. + $collection->updateOne( + ['tid' => $tenant, 'uid' => $uid, 'settings' => []], + ['$set' => ['settings' => (object) []]] + ); + $updates = []; foreach ($settings as $key => $value) { $updates["settings.{$key}"] = $value; } - $result = $this->store->selectCollection('user_accounts')->updateOne( + $result = $collection->updateOne( ['tid' => $tenant, 'uid' => $uid], ['$set' => $updates] ); - + // Return true if document was matched (exists), even if not modified return $result->getMatchedCount() > 0; }