aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorCôme Chilliet <91878298+come-nc@users.noreply.github.com>2024-09-13 17:44:38 +0200
committerGitHub <noreply@github.com>2024-09-13 17:44:38 +0200
commitbcb4e781a407798ef9d071dc3a15a1d0ac9e0e8d (patch)
treee210686e9c6d7fdd33b7e0cc905fbd38143db0a3 /lib/private
parent032f17c7956748fd25e33edf5d85d1d25b1ee94b (diff)
parent7a16d01ea79bf8effedd5e0e9ac7c2e4b4ea41f8 (diff)
downloadnextcloud-server-bcb4e781a407798ef9d071dc3a15a1d0ac9e0e8d.tar.gz
nextcloud-server-bcb4e781a407798ef9d071dc3a15a1d0ac9e0e8d.zip
Merge pull request #47927 from nextcloud/fix/migrate-away-from-oc_app
Migrate away from OC_App to IAppManager
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/App/AppManager.php40
-rw-r--r--lib/private/Authentication/TwoFactorAuth/ProviderLoader.php30
-rw-r--r--lib/private/IntegrityCheck/Checker.php4
-rw-r--r--lib/private/IntegrityCheck/Helpers/AppLocator.php9
-rw-r--r--lib/private/L10N/Factory.php2
-rw-r--r--lib/private/Route/Router.php26
-rw-r--r--lib/private/Server.php2
-rw-r--r--lib/private/legacy/OC_App.php31
8 files changed, 74 insertions, 70 deletions
diff --git a/lib/private/App/AppManager.php b/lib/private/App/AppManager.php
index fe2f7b74b22..4ffddef98c3 100644
--- a/lib/private/App/AppManager.php
+++ b/lib/private/App/AppManager.php
@@ -156,6 +156,37 @@ class AppManager implements IAppManager {
}
/**
+ * Get a list of all apps in the apps folder
+ *
+ * @return list<string> an array of app names (string IDs)
+ */
+ public function getAllAppsInAppsFolders(): array {
+ $apps = [];
+
+ foreach (\OC::$APPSROOTS as $apps_dir) {
+ if (!is_readable($apps_dir['path'])) {
+ $this->logger->warning('unable to read app folder : ' . $apps_dir['path'], ['app' => 'core']);
+ continue;
+ }
+ $dh = opendir($apps_dir['path']);
+
+ if (is_resource($dh)) {
+ while (($file = readdir($dh)) !== false) {
+ if (
+ $file[0] != '.' &&
+ is_dir($apps_dir['path'] . '/' . $file) &&
+ is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')
+ ) {
+ $apps[] = $file;
+ }
+ }
+ }
+ }
+
+ return array_values(array_unique($apps));
+ }
+
+ /**
* List all apps enabled for a user
*
* @param \OCP\IUser $user
@@ -647,11 +678,9 @@ class AppManager implements IAppManager {
/**
* Get the directory for the given app.
*
- * @param string $appId
- * @return string
* @throws AppPathNotFoundException if app folder can't be found
*/
- public function getAppPath($appId) {
+ public function getAppPath(string $appId): string {
$appPath = \OC_App::getAppPath($appId);
if ($appPath === false) {
throw new AppPathNotFoundException('Could not find path for ' . $appId);
@@ -877,4 +906,9 @@ class AppManager implements IAppManager {
return false;
}
+
+ public function cleanAppId(string $app): string {
+ // FIXME should list allowed characters instead
+ return str_replace(['<', '>', '"', "'", '\0', '/', '\\', '..'], '', $app);
+ }
}
diff --git a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php
index b9a0a97bec4..7e674a01dd8 100644
--- a/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php
+++ b/lib/private/Authentication/TwoFactorAuth/ProviderLoader.php
@@ -9,8 +9,7 @@ declare(strict_types=1);
namespace OC\Authentication\TwoFactorAuth;
use Exception;
-use OC;
-use OC_App;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\App\IAppManager;
use OCP\AppFramework\QueryException;
use OCP\Authentication\TwoFactorAuth\IProvider;
@@ -19,15 +18,10 @@ use OCP\IUser;
class ProviderLoader {
public const BACKUP_CODES_APP_ID = 'twofactor_backupcodes';
- /** @var IAppManager */
- private $appManager;
-
- /** @var OC\AppFramework\Bootstrap\Coordinator */
- private $coordinator;
-
- public function __construct(IAppManager $appManager, OC\AppFramework\Bootstrap\Coordinator $coordinator) {
- $this->appManager = $appManager;
- $this->coordinator = $coordinator;
+ public function __construct(
+ private IAppManager $appManager,
+ private Coordinator $coordinator,
+ ) {
}
/**
@@ -58,12 +52,12 @@ class ProviderLoader {
}
}
- $registeredProviders = $this->coordinator->getRegistrationContext()->getTwoFactorProviders();
+ $registeredProviders = $this->coordinator->getRegistrationContext()?->getTwoFactorProviders() ?? [];
foreach ($registeredProviders as $provider) {
try {
$this->loadTwoFactorApp($provider->getAppId());
- $provider = \OCP\Server::get($provider->getService());
- $providers[$provider->getId()] = $provider;
+ $providerInstance = \OCP\Server::get($provider->getService());
+ $providers[$providerInstance->getId()] = $providerInstance;
} catch (QueryException $exc) {
// Provider class can not be resolved
throw new Exception('Could not load two-factor auth provider ' . $provider->getService());
@@ -75,12 +69,10 @@ class ProviderLoader {
/**
* Load an app by ID if it has not been loaded yet
- *
- * @param string $appId
*/
- protected function loadTwoFactorApp(string $appId) {
- if (!OC_App::isAppLoaded($appId)) {
- OC_App::loadApp($appId);
+ protected function loadTwoFactorApp(string $appId): void {
+ if (!$this->appManager->isAppLoaded($appId)) {
+ $this->appManager->loadApp($appId);
}
}
}
diff --git a/lib/private/IntegrityCheck/Checker.php b/lib/private/IntegrityCheck/Checker.php
index d38ccf497f4..6443c43d210 100644
--- a/lib/private/IntegrityCheck/Checker.php
+++ b/lib/private/IntegrityCheck/Checker.php
@@ -46,7 +46,7 @@ class Checker {
private ?IConfig $config,
private ?IAppConfig $appConfig,
ICacheFactory $cacheFactory,
- private ?IAppManager $appManager,
+ private IAppManager $appManager,
private IMimeTypeDetector $mimeTypeDetector,
) {
$this->cache = $cacheFactory->createDistributed(self::CACHE_KEY);
@@ -536,7 +536,7 @@ class Checker {
public function runInstanceVerification() {
$this->cleanResults();
$this->verifyCoreSignature();
- $appIds = $this->appLocator->getAllApps();
+ $appIds = $this->appManager->getAllAppsInAppsFolders();
foreach ($appIds as $appId) {
// If an application is shipped a valid signature is required
$isShipped = $this->appManager->isShipped($appId);
diff --git a/lib/private/IntegrityCheck/Helpers/AppLocator.php b/lib/private/IntegrityCheck/Helpers/AppLocator.php
index 3da5cc13227..148a3aeda76 100644
--- a/lib/private/IntegrityCheck/Helpers/AppLocator.php
+++ b/lib/private/IntegrityCheck/Helpers/AppLocator.php
@@ -30,13 +30,4 @@ class AppLocator {
}
return $path;
}
-
- /**
- * Providers \OC_App::getAllApps()
- *
- * @return array
- */
- public function getAllApps(): array {
- return \OC_App::getAllApps();
- }
}
diff --git a/lib/private/L10N/Factory.php b/lib/private/L10N/Factory.php
index 6b6dc5d3b40..fc76a15b07b 100644
--- a/lib/private/L10N/Factory.php
+++ b/lib/private/L10N/Factory.php
@@ -81,7 +81,7 @@ class Factory implements IFactory {
*/
public function get($app, $lang = null, $locale = null) {
return new LazyL10N(function () use ($app, $lang, $locale) {
- $app = \OC_App::cleanAppId($app);
+ $app = $this->appManager->cleanAppId($app);
if ($lang !== null) {
$lang = str_replace(['\0', '/', '\\', '..'], '', $lang);
}
diff --git a/lib/private/Route/Router.php b/lib/private/Route/Router.php
index 646d1d4e6ed..ba369eecac0 100644
--- a/lib/private/Route/Router.php
+++ b/lib/private/Route/Router.php
@@ -104,7 +104,7 @@ class Router implements IRouter {
*/
public function loadRoutes($app = null) {
if (is_string($app)) {
- $app = \OC_App::cleanAppId($app);
+ $app = $this->appManager->cleanAppId($app);
}
$requestedApp = $app;
@@ -123,11 +123,15 @@ class Router implements IRouter {
if (isset($this->loadedApps[$app])) {
return;
}
- $appPath = \OC_App::getAppPath($app);
- $file = $appPath . '/appinfo/routes.php';
- if ($appPath !== false && file_exists($file)) {
- $routingFiles = [$app => $file];
- } else {
+ try {
+ $appPath = $this->appManager->getAppPath($app);
+ $file = $appPath . '/appinfo/routes.php';
+ if (file_exists($file)) {
+ $routingFiles = [$app => $file];
+ } else {
+ $routingFiles = [];
+ }
+ } catch (AppPathNotFoundException) {
$routingFiles = [];
}
@@ -238,14 +242,14 @@ class Router implements IRouter {
// empty string / 'apps' / $app / rest of the route
[, , $app,] = explode('/', $url, 4);
- $app = \OC_App::cleanAppId($app);
+ $app = $this->appManager->cleanAppId($app);
\OC::$REQUESTEDAPP = $app;
$this->loadRoutes($app);
} elseif (str_starts_with($url, '/ocsapp/apps/')) {
// empty string / 'ocsapp' / 'apps' / $app / rest of the route
[, , , $app,] = explode('/', $url, 5);
- $app = \OC_App::cleanAppId($app);
+ $app = $this->appManager->cleanAppId($app);
\OC::$REQUESTEDAPP = $app;
$this->loadRoutes($app);
} elseif (str_starts_with($url, '/settings/')) {
@@ -433,7 +437,11 @@ class Router implements IRouter {
$appControllerPath = __DIR__ . '/../../../core/Controller';
$appNameSpace = 'OC\\Core';
} else {
- $appControllerPath = \OC_App::getAppPath($app) . '/lib/Controller';
+ try {
+ $appControllerPath = $this->appManager->getAppPath($app) . '/lib/Controller';
+ } catch (AppPathNotFoundException) {
+ return [];
+ }
$appNameSpace = App::buildAppNamespace($app);
}
diff --git a/lib/private/Server.php b/lib/private/Server.php
index b0ccb0f4b4d..c514a4b93ff 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -954,10 +954,10 @@ class Server extends ServerContainer implements IServerContainer {
if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
$config = $c->get(\OCP\IConfig::class);
$appConfig = $c->get(\OCP\IAppConfig::class);
- $appManager = $c->get(IAppManager::class);
} else {
$config = $appConfig = $appManager = null;
}
+ $appManager = $c->get(IAppManager::class);
return new Checker(
new EnvironmentHelper(),
diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php
index f48f4fd0b98..ef84d35d7bc 100644
--- a/lib/private/legacy/OC_App.php
+++ b/lib/private/legacy/OC_App.php
@@ -45,8 +45,7 @@ class OC_App {
* @psalm-taint-escape html
* @psalm-taint-escape has_quotes
*
- * @param string $app AppId that needs to be cleaned
- * @return string
+ * @deprecated 31.0.0 use IAppManager::cleanAppId
*/
public static function cleanAppId(string $app): string {
return str_replace(['<', '>', '"', "'", '\0', '/', '\\', '..'], '', $app);
@@ -469,30 +468,10 @@ class OC_App {
* get a list of all apps in the apps folder
*
* @return string[] an array of app names (string IDs)
- * @todo: change the name of this method to getInstalledApps, which is more accurate
+ * @deprecated 31.0.0 Use IAppManager::getAllAppsInAppsFolders instead
*/
public static function getAllApps(): array {
- $apps = [];
-
- foreach (OC::$APPSROOTS as $apps_dir) {
- if (!is_readable($apps_dir['path'])) {
- \OCP\Server::get(LoggerInterface::class)->warning('unable to read app folder : ' . $apps_dir['path'], ['app' => 'core']);
- continue;
- }
- $dh = opendir($apps_dir['path']);
-
- if (is_resource($dh)) {
- while (($file = readdir($dh)) !== false) {
- if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) {
- $apps[] = $file;
- }
- }
- }
- }
-
- $apps = array_unique($apps);
-
- return $apps;
+ return \OCP\Server::get(IAppManager::class)->getAllAppsInAppsFolders();
}
/**
@@ -513,9 +492,9 @@ class OC_App {
* @return array
*/
public function listAllApps(): array {
- $installedApps = OC_App::getAllApps();
-
$appManager = \OC::$server->getAppManager();
+
+ $installedApps = $appManager->getAllAppsInAppsFolders();
//we don't want to show configuration for these
$blacklist = $appManager->getAlwaysEnabledApps();
$appList = [];