From e26d6f080ba978fb4c40b7caf190714a67e2e80c Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 22 Oct 2021 22:03:29 +0200 Subject: fix populating account array with missing default values - both $userData and $defaultUserData have numeric indices - each element contains at least the name and other fields - appending the missing data array is sufficient Signed-off-by: Arthur Schiwon --- lib/private/Accounts/AccountManager.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 3416db56ba5..cbd51e71c4a 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -473,15 +473,16 @@ class AccountManager implements IAccountManager { * Make sure that all expected data are set */ protected function addMissingDefaultValues(array $userData, array $defaultUserData): array { - foreach ($defaultUserData as $i => $value) { - // If property doesn't exists, initialize it - if (!array_key_exists($i, $userData)) { - $userData[$i] = []; + foreach ($defaultUserData as $defaultDataItem) { + // If property does not exist, initialize it + $userDataIndex = array_search($defaultDataItem['name'], array_column($userData, 'name')); + if ($userDataIndex === false) { + $userData[] = $defaultDataItem; + continue; } // Merge and extend default missing values - $defaultValueIndex = array_search($value['name'], array_column($defaultUserData, 'name')); - $userData[$i] = array_merge($defaultUserData[$defaultValueIndex], $userData[$i]); + $userData[$userDataIndex] = array_merge($defaultDataItem, $userData[$userDataIndex]); } return $userData; -- cgit v1.2.3