]> source.dussan.org Git - nextcloud-server.git/commitdiff
Use account method to set all properties
authorChristopher Ng <chrng8@gmail.com>
Fri, 18 Mar 2022 04:10:22 +0000 (04:10 +0000)
committerChristopher Ng <chrng8@gmail.com>
Fri, 18 Mar 2022 04:51:26 +0000 (04:51 +0000)
Signed-off-by: Christopher Ng <chrng8@gmail.com>
apps/settings/lib/UserMigration/AccountMigrator.php

index 7129a8f8349b8344dba5c5cfe517624301c8baf5..71b2b3afe20cc2dbc0ed219e68670f305c9de265 100644 (file)
@@ -27,8 +27,6 @@ declare(strict_types=1);
 namespace OCA\Settings\UserMigration;
 
 use InvalidArgumentException;
-use OC\Accounts\AccountProperty;
-use OC\Accounts\AccountPropertyCollection;
 use OC\Accounts\TAccountsHelper;
 use OC\NotSquareException;
 use OCP\Accounts\IAccountManager;
@@ -97,24 +95,10 @@ class AccountMigrator implements IMigrator {
 
                $account = $this->accountManager->getAccount($user);
 
-               /** @var array<string, array> $data */
+               /** @var array<string, array<string, string>>|array<string, array<int, array<string, string>>> $data */
                $data = json_decode($importSource->getFileContents(AccountMigrator::EXPORT_ACCOUNT_FILE), true, 512, JSON_THROW_ON_ERROR);
 
-               foreach ($data as $propertyName => $propertyData) {
-                       if ($this->isCollection($propertyName)) {
-                               $collection = new AccountPropertyCollection($propertyName);
-                               /** @var array<int, array{name: string, value: string, scope: string, verified: string, verificationData: string}> $collectionData */
-                               $collectionData = $propertyData[$propertyName];
-                               foreach ($collectionData as ['value' => $value, 'scope' => $scope, 'verified' => $verified, 'verificationData' => $verificationData]) {
-                                       $collection->addProperty(new AccountProperty($collection->getName(), $value, $scope, $verified, $verificationData));
-                               }
-                               $account->setPropertyCollection($collection);
-                       } else {
-                               /** @var array{name: string, value: string, scope: string, verified: string, verificationData: string} $propertyData */
-                               ['value' => $value, 'scope' => $scope, 'verified' => $verified, 'verificationData' => $verificationData] = $propertyData;
-                               $account->setProperty($propertyName, $value, $scope, $verified, $verificationData);
-                       }
-               }
+               $account->setAllPropertiesFromJson($data);
 
                try {
                        $this->accountManager->updateAccount($account);