Skip to content

Commit

Permalink
fix populating account array with missing default values
Browse files Browse the repository at this point in the history
- 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 <blizzz@arthur-schiwon.de>
  • Loading branch information
blizzz committed Oct 22, 2021
1 parent 6b099ec commit 3aa67e4
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/private/Accounts/AccountManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,11 @@ protected function sendEmailVerificationEmail(IUser $user, string $email): bool
* 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
if (!array_key_exists($defaultDataItem['name'], $userData)) {
$userData[] = $defaultDataItem;
}

// Merge and extend default missing values
$defaultValueIndex = array_search($value['name'], array_column($defaultUserData, 'name'));
$userData[$i] = array_merge($defaultUserData[$defaultValueIndex], $userData[$i]);
}

return $userData;
Expand Down

0 comments on commit 3aa67e4

Please sign in to comment.