Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use account method to set all properties
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Mar 18, 2022
commit ad31cfe72d4cb02f000b98499cf284ae371f7d11
20 changes: 2 additions & 18 deletions apps/settings/lib/UserMigration/AccountMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
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;
Expand Down Expand Up @@ -97,24 +95,10 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface

$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);
Expand Down