diff options
author | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-02-08 12:35:57 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2023-03-20 10:21:45 +0100 |
commit | 78c17168185c21b6b788e40602f95c690fe441f9 (patch) | |
tree | ef53bbc85e48499a0e3e949f581b0e6e0c5b9565 /lib | |
parent | 8dc5f8218979a8bf05ac5a8e84649f750dcab5ec (diff) | |
download | nextcloud-server-78c17168185c21b6b788e40602f95c690fe441f9.tar.gz nextcloud-server-78c17168185c21b6b788e40602f95c690fe441f9.zip |
Move loadApps to the AppManager
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/App/AppManager.php | 49 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 35 | ||||
-rw-r--r-- | lib/public/App/IAppManager.php | 14 |
3 files changed, 66 insertions, 32 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php index 59df44cbd17..d969f1d0260 100644 --- a/lib/private/App/AppManager.php +++ b/lib/private/App/AppManager.php @@ -179,6 +179,55 @@ class AppManager implements IAppManager { } /** + * Loads all apps + * + * @param string[] $types + * @return bool + * + * This function walks through the Nextcloud directory and loads all apps + * it can find. A directory contains an app if the file /appinfo/info.xml + * exists. + * + * if $types is set to non-empty array, only apps of those types will be loaded + */ + public function loadApps(array $types = []): bool { + if ($this->config->getSystemValueBool('maintenance', false)) { + return false; + } + // Load the enabled apps here + $apps = \OC_App::getEnabledApps(); + + // Add each apps' folder as allowed class path + foreach ($apps as $app) { + // If the app is already loaded then autoloading it makes no sense + if (!$this->isAppLoaded($app)) { + $path = \OC_App::getAppPath($app); + if ($path !== false) { + \OC_App::registerAutoloading($app, $path); + } + } + } + + // prevent app.php from printing output + ob_start(); + foreach ($apps as $app) { + if (!$this->isAppLoaded($app) && ($types === [] || $this->isType($app, $types))) { + try { + $this->loadApp($app); + } catch (\Throwable $e) { + $this->logger->emergency('Error during app loading: ' . $e->getMessage(), [ + 'exception' => $e, + 'app' => $app, + ]); + } + } + } + ob_end_clean(); + + return true; + } + + /** * check if an app is of a specific type * * @param string $app diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index ec57d43f9a6..5d7941ffa3f 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -116,40 +116,11 @@ class OC_App { * if $types is set to non-empty array, only apps of those types will be loaded */ public static function loadApps(array $types = []): bool { - if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) { + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { + // This should be done before calling this method so that appmanager can be used return false; } - // Load the enabled apps here - $apps = self::getEnabledApps(); - - // Add each apps' folder as allowed class path - foreach ($apps as $app) { - // If the app is already loaded then autoloading it makes no sense - if (!self::isAppLoaded($app)) { - $path = self::getAppPath($app); - if ($path !== false) { - self::registerAutoloading($app, $path); - } - } - } - - // prevent app.php from printing output - ob_start(); - foreach ($apps as $app) { - if (!self::isAppLoaded($app) && ($types === [] || self::isType($app, $types))) { - try { - self::loadApp($app); - } catch (\Throwable $e) { - \OC::$server->get(LoggerInterface::class)->emergency('Error during app loading: ' . $e->getMessage(), [ - 'exception' => $e, - 'app' => $app, - ]); - } - } - } - ob_end_clean(); - - return true; + return \OC::$server->get(IAppManager::class)->loadApps($types); } /** diff --git a/lib/public/App/IAppManager.php b/lib/public/App/IAppManager.php index 8440b757d40..5387e104fd9 100644 --- a/lib/public/App/IAppManager.php +++ b/lib/public/App/IAppManager.php @@ -197,6 +197,20 @@ interface IAppManager { public function isShipped($appId); /** + * Loads all apps + * + * @param string[] $types + * @return bool + * + * This function walks through the Nextcloud directory and loads all apps + * it can find. A directory contains an app if the file /appinfo/info.xml + * exists. + * + * if $types is set to non-empty array, only apps of those types will be loaded + */ + public function loadApps(array $types = []): bool; + + /** * Check if an app is of a specific type * @since 26.0.0 */ |