From 3d3c77b7746fbf3eb41ded8612099a351fd36224 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 4 Jun 2025 15:33:25 +0200 Subject: [PATCH] feat(lexicon): migrate keys on app update Signed-off-by: Maxence Lange --- lib/private/App/AppManager.php | 13 +++++++------ lib/private/legacy/OC_App.php | 4 ++++ lib/public/App/Events/AppUpdateEvent.php | 8 +++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 4db58f8ca0f..8c6f1ce78dc 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -28,6 +28,7 @@ use OCP\INavigationManager; use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserSession; +use OCP\Server; use OCP\ServerVersion; use OCP\Settings\IManager as ISettingsManager; use Psr\Log\LoggerInterface; @@ -88,7 +89,7 @@ class AppManager implements IAppManager { private function getNavigationManager(): INavigationManager { if ($this->navigationManager === null) { - $this->navigationManager = \OCP\Server::get(INavigationManager::class); + $this->navigationManager = Server::get(INavigationManager::class); } return $this->navigationManager; } @@ -114,7 +115,7 @@ class AppManager implements IAppManager { if (!$this->config->getSystemValueBool('installed', false)) { throw new \Exception('Nextcloud is not installed yet, AppConfig is not available'); } - $this->appConfig = \OCP\Server::get(AppConfig::class); + $this->appConfig = Server::get(AppConfig::class); return $this->appConfig; } @@ -125,7 +126,7 @@ class AppManager implements IAppManager { if (!$this->config->getSystemValueBool('installed', false)) { throw new \Exception('Nextcloud is not installed yet, AppConfig is not available'); } - $this->urlGenerator = \OCP\Server::get(IURLGenerator::class); + $this->urlGenerator = Server::get(IURLGenerator::class); return $this->urlGenerator; } @@ -460,7 +461,7 @@ class AppManager implements IAppManager { ]); } - $coordinator = \OCP\Server::get(Coordinator::class); + $coordinator = Server::get(Coordinator::class); $coordinator->bootApp($app); $eventLogger->start("bootstrap:load_app:$app:info", "Load info.xml for $app and register any services defined in it"); @@ -570,7 +571,7 @@ class AppManager implements IAppManager { )); $this->clearAppsCache(); - \OCP\Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId); + Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId); } /** @@ -630,7 +631,7 @@ class AppManager implements IAppManager { )); $this->clearAppsCache(); - \OCP\Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId); + Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId); } /** diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 4f0fff8884e..10aa14803eb 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -9,6 +9,7 @@ declare(strict_types=1); use OC\App\DependencyAnalyzer; use OC\App\Platform; use OC\AppFramework\Bootstrap\Coordinator; +use OC\Config\ConfigManager; use OC\DB\MigrationService; use OC\Installer; use OC\Repair; @@ -714,6 +715,9 @@ class OC_App { $version = \OCP\Server::get(\OCP\App\IAppManager::class)->getAppVersion($appId); \OC::$server->getConfig()->setAppValue($appId, 'installed_version', $version); + // migrate eventual new config keys in the process + Server::get(ConfigManager::class)->migrateConfigLexiconKeys($appId); + \OC::$server->get(IEventDispatcher::class)->dispatchTyped(new AppUpdateEvent($appId)); \OC::$server->get(IEventDispatcher::class)->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( ManagerEvent::EVENT_APP_UPDATE, $appId diff --git a/lib/public/App/Events/AppUpdateEvent.php b/lib/public/App/Events/AppUpdateEvent.php index 344e7def080..2cf59ff7949 100644 --- a/lib/public/App/Events/AppUpdateEvent.php +++ b/lib/public/App/Events/AppUpdateEvent.php @@ -16,15 +16,13 @@ use OCP\EventDispatcher\Event; * @since 27.0.0 */ class AppUpdateEvent extends Event { - private string $appId; - /** * @since 27.0.0 */ - public function __construct(string $appId) { + public function __construct( + private readonly string $appId, + ) { parent::__construct(); - - $this->appId = $appId; } /**