From 32c1e3e677a117501e51f27731d4b6e7f0484e14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 24 Mar 2025 17:02:50 +0100 Subject: [PATCH 1/8] feat: Add a replacement for OC_App::getAppVersions is IAppManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/App/AppManager.php | 16 ++++++++++++++++ lib/private/legacy/OC_App.php | 4 ++-- lib/public/App/IAppManager.php | 8 ++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 067cc89d67429..d7fd0c33a3058 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -19,6 +19,7 @@ use OCP\Collaboration\Collaborators\ISearch as ICollaboratorSearch; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; @@ -811,6 +812,21 @@ public function getAppVersion(string $appId, bool $useCache = true): string { return $this->appVersions[$appId]; } + /** + * Returns the installed versions of all apps + * + * @return array + */ + public function getAppInstalledVersions(): array { + static $versions; + + if (!$versions) { + /** @var array */ + $versions = $this->getAppConfig()->searchValues('installed_version', false, IAppConfig::VALUE_STRING); + } + return $versions; + } + /** * Returns a list of apps incompatible with the given version * diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 7fee946b77682..8f3284b09557b 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -456,10 +456,9 @@ public static function getAllApps(): array { /** * List all supported apps * - * @return array + * @deprecated 32.0.0 Use \OCP\Support\Subscription\IRegistry::delegateGetSupportedApps instead */ public function getSupportedApps(): array { - /** @var \OCP\Support\Subscription\IRegistry $subscriptionRegistry */ $subscriptionRegistry = \OCP\Server::get(\OCP\Support\Subscription\IRegistry::class); $supportedApps = $subscriptionRegistry->delegateGetSupportedApps(); return $supportedApps; @@ -643,6 +642,7 @@ public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ /** * get the installed version of all apps + * @deprecated 32.0.0 Use IAppManager::getAppInstalledVersions instead */ public static function getAppVersions() { static $versions; diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index fa35819b779c8..67ef2d796be51 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -51,6 +51,14 @@ public function getAppInfoByPath(string $path, ?string $lang = null): ?array; */ public function getAppVersion(string $appId, bool $useCache = true): string; + /** + * Returns the installed version of all apps + * + * @return array + * @since 32.0.0 + */ + public function getAppInstalledVersions(): array; + /** * Returns the app icon or null if none is found * From 4b099bd532448b1ab4ec11f9a88d7074fe856fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 24 Mar 2025 17:21:17 +0100 Subject: [PATCH 2/8] chore: Replace calls to OC_App::getAppVersions with app manager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/Notification/Notifier.php | 22 +++++++------------ core/Command/App/ListApps.php | 12 +++++----- lib/private/TemplateLayout.php | 7 +++--- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/apps/updatenotification/lib/Notification/Notifier.php b/apps/updatenotification/lib/Notification/Notifier.php index 8cee44144b295..8ce6bfc2d3d5a 100644 --- a/apps/updatenotification/lib/Notification/Notifier.php +++ b/apps/updatenotification/lib/Notification/Notifier.php @@ -20,8 +20,7 @@ use OCP\Notification\INotification; use OCP\Notification\INotifier; use OCP\Notification\UnknownNotificationException; -use OCP\Server; -use OCP\Util; +use OCP\ServerVersion; class Notifier implements INotifier { /** @var string[] */ @@ -44,8 +43,10 @@ public function __construct( protected IFactory $l10NFactory, protected IUserSession $userSession, protected IGroupManager $groupManager, + protected IAppManager $appManager, + protected ServerVersion $serverVersion, ) { - $this->appVersions = $this->getAppVersions(); + $this->appVersions = $this->appManager->getAppInstalledVersions(); } /** @@ -144,15 +145,12 @@ public function prepare(INotification $notification, string $languageCode): INot * @param string $installedVersion * @throws AlreadyProcessedException When the update is already installed */ - protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) { + protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion): void { if (version_compare($notification->getObjectId(), $installedVersion, '<=')) { throw new AlreadyProcessedException(); } } - /** - * @return bool - */ protected function isAdmin(): bool { $user = $this->userSession->getUser(); @@ -164,14 +162,10 @@ protected function isAdmin(): bool { } protected function getCoreVersions(): string { - return implode('.', Util::getVersion()); - } - - protected function getAppVersions(): array { - return \OC_App::getAppVersions(); + return implode('.', $this->serverVersion->getVersion()); } - protected function getAppInfo($appId, $languageCode) { - return Server::get(IAppManager::class)->getAppInfo($appId, false, $languageCode); + protected function getAppInfo(string $appId, ?string $languageCode): ?array { + return $this->appManager->getAppInfo($appId, false, $languageCode); } } diff --git a/core/Command/App/ListApps.php b/core/Command/App/ListApps.php index 5244d66e0d8dd..bb59e4411195b 100644 --- a/core/Command/App/ListApps.php +++ b/core/Command/App/ListApps.php @@ -14,7 +14,7 @@ class ListApps extends Base { public function __construct( - protected IAppManager $manager, + protected IAppManager $appManager, ) { parent::__construct(); } @@ -56,16 +56,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int $showEnabledApps = $input->getOption('enabled') || !$input->getOption('disabled'); $showDisabledApps = $input->getOption('disabled') || !$input->getOption('enabled'); - $apps = \OC_App::getAllApps(); + $apps = $this->appManager->getAllAppsInAppsFolders(); $enabledApps = $disabledApps = []; - $versions = \OC_App::getAppVersions(); + $versions = $this->appManager->getAppInstalledVersions(); //sort enabled apps above disabled apps foreach ($apps as $app) { - if ($shippedFilter !== null && $this->manager->isShipped($app) !== $shippedFilter) { + if ($shippedFilter !== null && $this->appManager->isShipped($app) !== $shippedFilter) { continue; } - if ($this->manager->isEnabledForAnyone($app)) { + if ($this->appManager->isEnabledForAnyone($app)) { $enabledApps[] = $app; } else { $disabledApps[] = $app; @@ -88,7 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int sort($disabledApps); foreach ($disabledApps as $app) { - $apps['disabled'][$app] = $this->manager->getAppVersion($app) . (isset($versions[$app]) ? ' (installed ' . $versions[$app] . ')' : ''); + $apps['disabled'][$app] = $this->appManager->getAppVersion($app) . (isset($versions[$app]) ? ' (installed ' . $versions[$app] . ')' : ''); } } diff --git a/lib/private/TemplateLayout.php b/lib/private/TemplateLayout.php index 9c1d7ca1d2c06..01d22edc0fb06 100644 --- a/lib/private/TemplateLayout.php +++ b/lib/private/TemplateLayout.php @@ -48,6 +48,7 @@ public function __construct( private InitialStateService $initialState, private INavigationManager $navigationManager, private ITemplateManager $templateManager, + private ServerVersion $serverVersion, ) { } @@ -204,8 +205,8 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { if ($this->config->getSystemValueBool('installed', false)) { if (empty(self::$versionHash)) { - $v = \OC_App::getAppVersions(); - $v['core'] = implode('.', \OCP\Util::getVersion()); + $v = $this->appManager->getAppInstalledVersions(); + $v['core'] = implode('.', $this->serverVersion->getVersion()); self::$versionHash = substr(md5(implode(',', $v)), 0, 8); } } else { @@ -220,7 +221,7 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate { // this is on purpose outside of the if statement below so that the initial state is prefilled (done in the getConfig() call) // see https://github.com/nextcloud/server/pull/22636 for details $jsConfigHelper = new JSConfigHelper( - \OCP\Server::get(ServerVersion::class), + $this->serverVersion, \OCP\Util::getL10N('lib'), \OCP\Server::get(Defaults::class), $this->appManager, From 0a027c3906b193de5ac497a004b2f129aac64bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 24 Mar 2025 17:41:39 +0100 Subject: [PATCH 3/8] chore: Cleanup Server.php a bit and remove OC_App usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Server.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index 523fc7b9914c1..5e61dfe083627 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -604,13 +604,14 @@ public function __construct($webRoot, \OC\Config $config) { $config = $c->get(SystemConfig::class); /** @var ServerVersion $serverVersion */ $serverVersion = $c->get(ServerVersion::class); + $appManager = $c->get(IAppManager::class); if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { $logQuery = $config->getValue('log_query'); - $prefixClosure = function () use ($logQuery, $serverVersion) { + $prefixClosure = function () use ($logQuery, $serverVersion, $appManager): ?string { if (!$logQuery) { try { - $v = \OC_App::getAppVersions(); + $v = $appManager->getAppInstalledVersions(); } catch (\Doctrine\DBAL\Exception $e) { // Database service probably unavailable // Probably related to https://github.com/nextcloud/server/issues/37424 @@ -867,15 +868,15 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerDeprecatedAlias('IntegrityCodeChecker', Checker::class); $this->registerService(Checker::class, function (ContainerInterface $c) { - // IConfig and IAppManager requires a working database. This code - // might however be called when ownCloud is not yet setup. + // IConfig requires a working database. This code + // might however be called when Nextcloud is not yet setup. if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) { $config = $c->get(\OCP\IConfig::class); $appConfig = $c->get(\OCP\IAppConfig::class); } else { - $config = $appConfig = $appManager = null; + $config = null; + $appConfig = null; } - $appManager = $c->get(IAppManager::class); return new Checker( $c->get(ServerVersion::class), @@ -885,7 +886,7 @@ public function __construct($webRoot, \OC\Config $config) { $config, $appConfig, $c->get(ICacheFactory::class), - $appManager, + $c->get(IAppManager::class), $c->get(IMimeTypeDetector::class) ); }); From 8caa1a70e95449708f53e5f8882225e82304a27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 24 Mar 2025 18:01:47 +0100 Subject: [PATCH 4/8] fix: Do not try to load IAppManager too soon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Server.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index 5e61dfe083627..0347ef81534c2 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -604,14 +604,13 @@ public function __construct($webRoot, \OC\Config $config) { $config = $c->get(SystemConfig::class); /** @var ServerVersion $serverVersion */ $serverVersion = $c->get(ServerVersion::class); - $appManager = $c->get(IAppManager::class); if ($config->getValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { $logQuery = $config->getValue('log_query'); - $prefixClosure = function () use ($logQuery, $serverVersion, $appManager): ?string { + $prefixClosure = function () use ($logQuery, $serverVersion): ?string { if (!$logQuery) { try { - $v = $appManager->getAppInstalledVersions(); + $v = \OCP\Server::get(IAppManager::class)->getAppVersions(); } catch (\Doctrine\DBAL\Exception $e) { // Database service probably unavailable // Probably related to https://github.com/nextcloud/server/issues/37424 From 49cf5ba318add68160aede0e2ad624800983d183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 25 Mar 2025 14:11:24 +0100 Subject: [PATCH 5/8] fix: Put back OC_App::getAppVersions in Server.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Server.php b/lib/private/Server.php index 0347ef81534c2..0b37c2e2abbdf 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -610,7 +610,7 @@ public function __construct($webRoot, \OC\Config $config) { $prefixClosure = function () use ($logQuery, $serverVersion): ?string { if (!$logQuery) { try { - $v = \OCP\Server::get(IAppManager::class)->getAppVersions(); + $v = \OC_App::getAppVersions(); } catch (\Doctrine\DBAL\Exception $e) { // Database service probably unavailable // Probably related to https://github.com/nextcloud/server/issues/37424 From 34d7a957e0e80df1280e931533111a2f2f3555ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 25 Mar 2025 14:20:59 +0100 Subject: [PATCH 6/8] chore(tests): Adapt TemplateLayoutTest to constructor change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- tests/lib/TemplateLayoutTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/lib/TemplateLayoutTest.php b/tests/lib/TemplateLayoutTest.php index 29e31b3f3911a..b389552540871 100644 --- a/tests/lib/TemplateLayoutTest.php +++ b/tests/lib/TemplateLayoutTest.php @@ -15,6 +15,7 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; use OCP\INavigationManager; +use OCP\ServerVersion; use OCP\Template\ITemplateManager; use PHPUnit\Framework\MockObject\MockObject; @@ -24,6 +25,7 @@ class TemplateLayoutTest extends \Test\TestCase { private InitialStateService&MockObject $initialState; private INavigationManager&MockObject $navigationManager; private ITemplateManager&MockObject $templateManager; + private ServerVersion&MockObject $serverVersion; private TemplateLayout $templateLayout; @@ -35,6 +37,7 @@ protected function setUp(): void { $this->initialState = $this->createMock(InitialStateService::class); $this->navigationManager = $this->createMock(INavigationManager::class); $this->templateManager = $this->createMock(ITemplateManager::class); + $this->serverVersion = $this->createMock(ServerVersion::class); } /** @dataProvider dataVersionHash */ @@ -69,6 +72,7 @@ public function testVersionHash($path, $file, $installed, $debug, $expected): vo $this->initialState, $this->navigationManager, $this->templateManager, + $this->serverVersion, ]) ->getMock(); From 1ae3e8e77dfe6b70c76d430ad06bb49bd8d0e069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 25 Mar 2025 14:58:26 +0100 Subject: [PATCH 7/8] chore(tests): Adapt updatenotification tests to constructor change MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../tests/Notification/NotifierTest.php | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/apps/updatenotification/tests/Notification/NotifierTest.php b/apps/updatenotification/tests/Notification/NotifierTest.php index 1e53b8d4aea24..45c4fc9960fe3 100644 --- a/apps/updatenotification/tests/Notification/NotifierTest.php +++ b/apps/updatenotification/tests/Notification/NotifierTest.php @@ -9,6 +9,7 @@ namespace OCA\UpdateNotification\Tests\Notification; use OCA\UpdateNotification\Notification\Notifier; +use OCP\App\IAppManager; use OCP\IConfig; use OCP\IGroupManager; use OCP\IURLGenerator; @@ -17,22 +18,20 @@ use OCP\Notification\AlreadyProcessedException; use OCP\Notification\IManager; use OCP\Notification\INotification; +use OCP\ServerVersion; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class NotifierTest extends TestCase { - /** @var IURLGenerator|\PHPUnit\Framework\MockObject\MockObject */ - protected $urlGenerator; - /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */ - protected $config; - /** @var IManager|\PHPUnit\Framework\MockObject\MockObject */ - protected $notificationManager; - /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */ - protected $l10nFactory; - /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ - protected $userSession; - /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ - protected $groupManager; + protected IURLGenerator&MockObject $urlGenerator; + protected IConfig&MockObject $config; + protected IManager&MockObject $notificationManager; + protected IFactory&MockObject $l10nFactory; + protected IUserSession&MockObject $userSession; + protected IGroupManager&MockObject $groupManager; + protected IAppManager&MockObject $appManager; + protected ServerVersion&MockObject $serverVersion; protected function setUp(): void { parent::setUp(); @@ -43,6 +42,8 @@ protected function setUp(): void { $this->l10nFactory = $this->createMock(IFactory::class); $this->userSession = $this->createMock(IUserSession::class); $this->groupManager = $this->createMock(IGroupManager::class); + $this->appManager = $this->createMock(IAppManager::class); + $this->serverVersion = $this->createMock(ServerVersion::class); } /** @@ -57,7 +58,9 @@ protected function getNotifier(array $methods = []) { $this->notificationManager, $this->l10nFactory, $this->userSession, - $this->groupManager + $this->groupManager, + $this->appManager, + $this->serverVersion, ); } { @@ -69,6 +72,8 @@ protected function getNotifier(array $methods = []) { $this->l10nFactory, $this->userSession, $this->groupManager, + $this->appManager, + $this->serverVersion, ]) ->onlyMethods($methods) ->getMock(); From c7037d7b38d794ad49c93cbc1dfb8721898bd191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 25 Mar 2025 16:18:51 +0100 Subject: [PATCH 8/8] fix: Move getAppInstalledVersions to AppConfig so that it can be used earlier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call it from OC_App to make sure there is only one request to DB. Signed-off-by: Côme Chilliet --- lib/private/App/AppManager.php | 9 +-------- lib/private/AppConfig.php | 16 ++++++++++++++++ lib/private/AppFramework/Services/AppConfig.php | 9 +++++++++ lib/private/Server.php | 2 +- lib/private/legacy/OC_App.php | 13 +++---------- lib/public/IAppConfig.php | 8 ++++++++ 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index d7fd0c33a3058..740da31770d1f 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -19,7 +19,6 @@ use OCP\Collaboration\Collaborators\ISearch as ICollaboratorSearch; use OCP\Diagnostics\IEventLogger; use OCP\EventDispatcher\IEventDispatcher; -use OCP\IAppConfig; use OCP\ICacheFactory; use OCP\IConfig; use OCP\IGroup; @@ -818,13 +817,7 @@ public function getAppVersion(string $appId, bool $useCache = true): string { * @return array */ public function getAppInstalledVersions(): array { - static $versions; - - if (!$versions) { - /** @var array */ - $versions = $this->getAppConfig()->searchValues('installed_version', false, IAppConfig::VALUE_STRING); - } - return $versions; + return $this->getAppConfig()->getAppInstalledVersions(); } /** diff --git a/lib/private/AppConfig.php b/lib/private/AppConfig.php index ad9299f01fdaa..1228b9c20e381 100644 --- a/lib/private/AppConfig.php +++ b/lib/private/AppConfig.php @@ -62,6 +62,9 @@ class AppConfig implements IAppConfig { /** @var array, strictness: ConfigLexiconStrictness}> ['app_id' => ['strictness' => ConfigLexiconStrictness, 'entries' => ['config_key' => ConfigLexiconEntry[]]] */ private array $configLexiconDetails = []; + /** @var ?array */ + private ?array $appVersionsCache = null; + public function __construct( protected IDBConnection $connection, protected LoggerInterface $logger, @@ -1647,4 +1650,17 @@ private function getConfigDetailsFromLexicon(string $appId): array { return $this->configLexiconDetails[$appId]; } + + /** + * Returns the installed versions of all apps + * + * @return array + */ + public function getAppInstalledVersions(): array { + if ($this->appVersionsCache === null) { + /** @var array */ + $this->appVersionsCache = $this->searchValues('installed_version', false, IAppConfig::VALUE_STRING); + } + return $this->appVersionsCache; + } } diff --git a/lib/private/AppFramework/Services/AppConfig.php b/lib/private/AppFramework/Services/AppConfig.php index 423a9eb5814ea..77c5ea4de0cb2 100644 --- a/lib/private/AppFramework/Services/AppConfig.php +++ b/lib/private/AppFramework/Services/AppConfig.php @@ -337,4 +337,13 @@ public function getUserValue(string $userId, string $key, string $default = ''): public function deleteUserValue(string $userId, string $key): void { $this->config->deleteUserValue($userId, $this->appName, $key); } + + /** + * Returns the installed versions of all apps + * + * @return array + */ + public function getAppInstalledVersions(): array { + return $this->appConfig->getAppInstalledVersions(); + } } diff --git a/lib/private/Server.php b/lib/private/Server.php index 0b37c2e2abbdf..4d79fefd2615f 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -610,7 +610,7 @@ public function __construct($webRoot, \OC\Config $config) { $prefixClosure = function () use ($logQuery, $serverVersion): ?string { if (!$logQuery) { try { - $v = \OC_App::getAppVersions(); + $v = \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(); } catch (\Doctrine\DBAL\Exception $e) { // Database service probably unavailable // Probably related to https://github.com/nextcloud/server/issues/37424 diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index 8f3284b09557b..ecceafa65b332 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -642,17 +642,10 @@ public static function isAppCompatible(string $ocVersion, array $appInfo, bool $ /** * get the installed version of all apps - * @deprecated 32.0.0 Use IAppManager::getAppInstalledVersions instead + * @deprecated 32.0.0 Use IAppManager::getAppInstalledVersions or IAppConfig::getAppInstalledVersions instead */ - public static function getAppVersions() { - static $versions; - - if (!$versions) { - /** @var IAppConfig $appConfig */ - $appConfig = \OCP\Server::get(IAppConfig::class); - $versions = $appConfig->searchValues('installed_version'); - } - return $versions; + public static function getAppVersions(): array { + return \OCP\Server::get(IAppConfig::class)->getAppInstalledVersions(); } /** diff --git a/lib/public/IAppConfig.php b/lib/public/IAppConfig.php index d4d5c1c09c740..f42107934760b 100644 --- a/lib/public/IAppConfig.php +++ b/lib/public/IAppConfig.php @@ -507,4 +507,12 @@ public function getValues($app, $key); * @deprecated 29.0.0 Use {@see getAllValues()} or {@see searchValues()} */ public function getFilteredValues($app); + + /** + * Returns the installed version of all apps + * + * @return array + * @since 32.0.0 + */ + public function getAppInstalledVersions(): array; }