|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\UserOIDC\Migration; |
| 11 | + |
| 12 | +use Closure; |
| 13 | +use OCA\UserOIDC\AppInfo\Application; |
| 14 | +use OCA\UserOIDC\Db\ProviderMapper; |
| 15 | +use OCA\UserOIDC\Service\ProviderService; |
| 16 | +use OCP\IAppConfig; |
| 17 | +use OCP\Migration\IOutput; |
| 18 | +use OCP\Migration\SimpleMigrationStep; |
| 19 | + |
| 20 | +class Version080101Date20251201121749 extends SimpleMigrationStep { |
| 21 | + |
| 22 | + public function __construct( |
| 23 | + private IAppConfig $appConfig, |
| 24 | + private ProviderService $providerService, |
| 25 | + private ProviderMapper $providerMapper, |
| 26 | + ) { |
| 27 | + } |
| 28 | + |
| 29 | + /** |
| 30 | + * @param IOutput $output |
| 31 | + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
| 32 | + * @param array $options |
| 33 | + */ |
| 34 | + public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
| 35 | + // make admin settings lazy |
| 36 | + $keys = [ |
| 37 | + 'store_login_token', |
| 38 | + 'id4me_enabled', |
| 39 | + 'allow_multiple_user_backends', |
| 40 | + ]; |
| 41 | + foreach ($keys as $key) { |
| 42 | + try { |
| 43 | + if ($this->appConfig->hasKey(Application::APP_ID, $key)) { |
| 44 | + $value = $this->appConfig->getValueString(Application::APP_ID, $key); |
| 45 | + $this->appConfig->setValueString(Application::APP_ID, $key, $value, lazy: true); |
| 46 | + } |
| 47 | + } catch (\Exception) { |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + // make all provider settings lazy |
| 52 | + $providers = $this->providerMapper->getProviders(); |
| 53 | + $supportedSettingKeys = $this->providerService->getSupportedSettings(); |
| 54 | + $supportedSettingKeys[] = ProviderService::SETTING_JWKS_CACHE; |
| 55 | + $supportedSettingKeys[] = ProviderService::SETTING_JWKS_CACHE_TIMESTAMP; |
| 56 | + foreach ($supportedSettingKeys as $key) { |
| 57 | + foreach ($providers as $provider) { |
| 58 | + $realKey = $this->providerService->getSettingsKey($provider->getId(), $key); |
| 59 | + if ($this->appConfig->hasKey(Application::APP_ID, $realKey)) { |
| 60 | + try { |
| 61 | + $value = $this->appConfig->getValueString(Application::APP_ID, $realKey); |
| 62 | + $this->appConfig->setValueString(Application::APP_ID, $realKey, $value, lazy: true); |
| 63 | + } catch (\Exception) { |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments