diff options
author | Christopher Ng <chrng8@gmail.com> | 2022-07-08 21:58:02 +0300 |
---|---|---|
committer | Pytal (Rebase PR Action) <Pytal@users.noreply.github.com> | 2022-09-01 18:27:37 +0300 |
commit | 98bc98ac98addd603925c9d10a97f700aba34285 (patch) | |
tree | 8f05e28655f553604dc828b9079967d540dc0bb4 /apps/settings/lib | |
parent | 253c0641b138d6eeb4397f82ba3738d9adb132a2 (diff) |
Add profile config migration
Signed-off-by: Christopher Ng <chrng8@gmail.com>
Diffstat (limited to 'apps/settings/lib')
-rw-r--r-- | apps/settings/lib/UserMigration/AccountMigrator.php | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/apps/settings/lib/UserMigration/AccountMigrator.php b/apps/settings/lib/UserMigration/AccountMigrator.php index 4db28306eb1..e8c70624224 100644 --- a/apps/settings/lib/UserMigration/AccountMigrator.php +++ b/apps/settings/lib/UserMigration/AccountMigrator.php @@ -28,7 +28,9 @@ namespace OCA\Settings\UserMigration; use InvalidArgumentException; use OC\Accounts\TAccountsHelper; +use OC\Core\Db\ProfileConfigMapper; use OC\NotSquareException; +use OC\Profile\ProfileManager; use OCA\Settings\AppInfo\Application; use OCP\Accounts\IAccountManager; use OCP\IAvatarManager; @@ -51,6 +53,10 @@ class AccountMigrator implements IMigrator, ISizeEstimationMigrator { private IAvatarManager $avatarManager; + private ProfileManager $profileManager; + + private ProfileConfigMapper $configMapper; + private IL10N $l10n; private const PATH_ROOT = Application::APP_ID . '/'; @@ -59,13 +65,19 @@ class AccountMigrator implements IMigrator, ISizeEstimationMigrator { private const AVATAR_BASENAME = 'avatar'; + private const PATH_CONFIG_FILE = AccountMigrator::PATH_ROOT . 'config.json'; + public function __construct( IAccountManager $accountManager, IAvatarManager $avatarManager, + ProfileManager $profileManager, + ProfileConfigMapper $configMapper, IL10N $l10n ) { $this->accountManager = $accountManager; $this->avatarManager = $avatarManager; + $this->profileManager = $profileManager; + $this->configMapper = $configMapper; $this->l10n = $l10n; } @@ -113,6 +125,14 @@ class AccountMigrator implements IMigrator, ISizeEstimationMigrator { } catch (Throwable $e) { throw new AccountMigratorException('Could not export avatar', 0, $e); } + + try { + $output->writeln('Exporting profile config in ' . AccountMigrator::PATH_CONFIG_FILE . '…'); + $config = $this->profileManager->getProfileConfig($user, $user); + $exportDestination->addFileContents(AccountMigrator::PATH_CONFIG_FILE, json_encode($config)); + } catch (Throwable $e) { + throw new AccountMigratorException('Could not export profile config', 0, $e); + } } /** @@ -165,6 +185,19 @@ class AccountMigrator implements IMigrator, ISizeEstimationMigrator { throw new AccountMigratorException('Failed to import avatar', 0, $e); } } + + try { + $output->writeln('Importing profile config from ' . AccountMigrator::PATH_CONFIG_FILE . '…'); + /** @var array $configData */ + $configData = json_decode($importSource->getFileContents(AccountMigrator::PATH_CONFIG_FILE), true, 512, JSON_THROW_ON_ERROR); + // Ensure that a profile config entry exists in the database + $this->profileManager->getProfileConfig($user, $user); + $config = $this->configMapper->get($user->getUID()); + $config->setConfigArray($configData); + $this->configMapper->update($config); + } catch (Throwable $e) { + throw new AccountMigratorException('Failed to import profile config'); + } } /** |