fix: empty object

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-07-25 21:28:00 -04:00
parent f958cdd6a3
commit b58f6e9479
+24 -6
View File
@@ -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;
}