fix: empty object
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -177,8 +177,8 @@ class UserAccountsStore
|
|||||||
$userData['uid'] = $userData['uid'] ?? UUID::v4();
|
$userData['uid'] = $userData['uid'] ?? UUID::v4();
|
||||||
$userData['enabled'] = $userData['enabled'] ?? true;
|
$userData['enabled'] = $userData['enabled'] ?? true;
|
||||||
$userData['roles'] = $userData['roles'] ?? [];
|
$userData['roles'] = $userData['roles'] ?? [];
|
||||||
$userData['profile'] = $userData['profile'] ?? [];
|
$userData['profile'] = (object) ($userData['profile'] ?? []);
|
||||||
$userData['settings'] = $userData['settings'] ?? [];
|
$userData['settings'] = (object) ($userData['settings'] ?? []);
|
||||||
|
|
||||||
$this->store->selectCollection('user_accounts')->insertOne($userData);
|
$this->store->selectCollection('user_accounts')->insertOne($userData);
|
||||||
|
|
||||||
@@ -232,16 +232,25 @@ class UserAccountsStore
|
|||||||
return false;
|
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 = [];
|
$updates = [];
|
||||||
foreach ($profileFields as $key => $value) {
|
foreach ($profileFields as $key => $value) {
|
||||||
$updates["profile.{$key}"] = $value;
|
$updates["profile.{$key}"] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->store->selectCollection('user_accounts')->updateOne(
|
$result = $collection->updateOne(
|
||||||
['tid' => $tenant, 'uid' => $uid],
|
['tid' => $tenant, 'uid' => $uid],
|
||||||
['$set' => $updates]
|
['$set' => $updates]
|
||||||
);
|
);
|
||||||
|
|
||||||
return $result->getModifiedCount() > 0;
|
return $result->getModifiedCount() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,16 +316,25 @@ class UserAccountsStore
|
|||||||
return false;
|
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 = [];
|
$updates = [];
|
||||||
foreach ($settings as $key => $value) {
|
foreach ($settings as $key => $value) {
|
||||||
$updates["settings.{$key}"] = $value;
|
$updates["settings.{$key}"] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->store->selectCollection('user_accounts')->updateOne(
|
$result = $collection->updateOne(
|
||||||
['tid' => $tenant, 'uid' => $uid],
|
['tid' => $tenant, 'uid' => $uid],
|
||||||
['$set' => $updates]
|
['$set' => $updates]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Return true if document was matched (exists), even if not modified
|
// Return true if document was matched (exists), even if not modified
|
||||||
return $result->getMatchedCount() > 0;
|
return $result->getMatchedCount() > 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user