From 34139987d609386c3351c46fd60b0f932795b6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 24 Feb 2025 12:44:50 +0100 Subject: [PATCH] fix: Replace OC_App calls by IAppManager MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- .../lib/CalDAV/Activity/Provider/Event.php | 3 +-- apps/files_sharing/tests/UpdaterTest.php | 7 +++--- core/Command/Maintenance/Repair.php | 2 +- lib/base.php | 23 +++++++++++-------- lib/private/Route/Router.php | 6 ++--- lib/private/Server.php | 2 +- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/apps/dav/lib/CalDAV/Activity/Provider/Event.php b/apps/dav/lib/CalDAV/Activity/Provider/Event.php index d3cfd00b742..41b610542df 100644 --- a/apps/dav/lib/CalDAV/Activity/Provider/Event.php +++ b/apps/dav/lib/CalDAV/Activity/Provider/Event.php @@ -5,7 +5,6 @@ */ namespace OCA\DAV\CalDAV\Activity\Provider; -use OC_App; use OCP\Activity\Exceptions\UnknownActivityException; use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; @@ -67,7 +66,7 @@ class Event extends Base { if (isset($eventData['link']) && is_array($eventData['link']) && $this->appManager->isEnabledForUser('calendar')) { try { // The calendar app needs to be manually loaded for the routes to be loaded - OC_App::loadApp('calendar'); + $this->appManager->loadApp('calendar'); $linkData = $eventData['link']; $calendarUri = $this->urlencodeLowerHex($linkData['calendar_uri']); if ($affectedUser === $linkData['owner']) { diff --git a/apps/files_sharing/tests/UpdaterTest.php b/apps/files_sharing/tests/UpdaterTest.php index 70e644f9207..efdbeebdf3f 100644 --- a/apps/files_sharing/tests/UpdaterTest.php +++ b/apps/files_sharing/tests/UpdaterTest.php @@ -59,8 +59,9 @@ class UpdaterTest extends TestCase { * that the mount point doesn't end up at the trash bin */ public function testDeleteParentFolder(): void { - $status = Server::get(IAppManager::class)->isEnabledForUser('files_trashbin'); - (new \OC_App())->enable('files_trashbin'); + $appManager = Server::get(IAppManager::class); + $status = $appManager->isEnabledForUser('files_trashbin'); + $appManager->enableApp('files_trashbin'); // register trashbin hooks $trashbinApp = new Application(); @@ -116,7 +117,7 @@ class UpdaterTest extends TestCase { $rootView->deleteAll('files_trashin'); if ($status === false) { - Server::get(IAppManager::class)->disableApp('files_trashbin'); + $appManager->disableApp('files_trashbin'); } Filesystem::getLoader()->removeStorageWrapper('oc_trashbin'); diff --git a/core/Command/Maintenance/Repair.php b/core/Command/Maintenance/Repair.php index 35f4ef7a8d5..f0c88f6811b 100644 --- a/core/Command/Maintenance/Repair.php +++ b/core/Command/Maintenance/Repair.php @@ -70,7 +70,7 @@ class Repair extends Command { if (!is_array($info)) { continue; } - \OC_App::loadApp($app); + $this->appManager->loadApp($app); $steps = $info['repair-steps']['post-migration']; foreach ($steps as $step) { try { diff --git a/lib/base.php b/lib/base.php index 546a119479b..811055c982b 100644 --- a/lib/base.php +++ b/lib/base.php @@ -675,7 +675,10 @@ class OC { throw new \OCP\HintException('The PHP SimpleXML/PHP-XML extension is not installed.', 'Install the extension or make sure it is enabled.'); } - OC_App::loadApps(['session']); + $appManager = Server::get(\OCP\App\IAppManager::class); + if ($systemConfig->getValue('installed', false)) { + $appManager->loadApps(['session']); + } if (!self::$CLI) { self::initSession(); } @@ -759,7 +762,7 @@ class OC { // Make sure that the application class is not loaded before the database is setup if ($systemConfig->getValue('installed', false)) { - OC_App::loadApp('settings'); + $appManager->loadApp('settings'); /* Build core application to make sure that listeners are registered */ Server::get(\OC\Core\Application::class); } @@ -1002,19 +1005,21 @@ class OC { } } + $appManager = Server::get(\OCP\App\IAppManager::class); + // Always load authentication apps - OC_App::loadApps(['authentication']); - OC_App::loadApps(['extended_authentication']); + $appManager->loadApps(['authentication']); + $appManager->loadApps(['extended_authentication']); // Load minimum set of apps if (!\OCP\Util::needUpgrade() && !((bool)$systemConfig->getValue('maintenance', false))) { // For logged-in users: Load everything if (Server::get(IUserSession::class)->isLoggedIn()) { - OC_App::loadApps(); + $appManager->loadApps(); } else { // For guests: Load only filesystem and logging - OC_App::loadApps(['filesystem', 'logging']); + $appManager->loadApps(['filesystem', 'logging']); // Don't try to login when a client is trying to get a OAuth token. // OAuth needs to support basic auth too, so the login is not valid @@ -1027,9 +1032,9 @@ class OC { if (!self::$CLI) { try { - if (!((bool)$systemConfig->getValue('maintenance', false)) && !\OCP\Util::needUpgrade()) { - OC_App::loadApps(['filesystem', 'logging']); - OC_App::loadApps(); + if (!\OCP\Util::needUpgrade()) { + $appManager->loadApps(['filesystem', 'logging']); + $appManager->loadApps(); } Server::get(\OC\Route\Router::class)->match($request->getRawPathInfo()); return; diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php index 3277b983d0f..d073132516d 100644 --- a/lib/private/Route/Router.php +++ b/lib/private/Route/Router.php @@ -142,7 +142,7 @@ class Router implements IRouter { foreach ($routingFiles as $app => $file) { if (!isset($this->loadedApps[$app])) { - if (!\OC_App::isAppLoaded($app)) { + if (!$this->appManager->isAppLoaded($app)) { // app MUST be loaded before app routes // try again next time loadRoutes() is called $this->loaded = false; @@ -257,8 +257,8 @@ class Router implements IRouter { $this->loadRoutes('settings'); } elseif (str_starts_with($url, '/core/')) { \OC::$REQUESTEDAPP = $url; - if (!$this->config->getSystemValueBool('maintenance') && !Util::needUpgrade()) { - \OC_App::loadApps(); + if ($this->config->getSystemValueBool('installed', false) && !Util::needUpgrade()) { + $this->appManager->loadApps(); } $this->loadRoutes('core'); } else { diff --git a/lib/private/Server.php b/lib/private/Server.php index 77759de30c5..8c5ec8ed252 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -838,7 +838,7 @@ class Server extends ServerContainer implements IServerContainer { if ($busClass) { [$app, $class] = explode('::', $busClass, 2); if ($c->get(IAppManager::class)->isEnabledForUser($app)) { - \OC_App::loadApp($app); + $c->get(IAppManager::class)->loadApp($app); return $c->get($class); } else { throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");