fix: Migrate a few more classes away from OC_App::getAppPath

Also fixed AppTest

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/44025/head
Côme Chilliet 2024-03-06 15:58:19 +07:00
parent 0e7bac72ae
commit 733a818139
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
7 changed files with 37 additions and 55 deletions

@ -402,7 +402,7 @@ class AppSettingsController extends Controller {
try { try {
$this->appManager->getAppPath($app['id']); $this->appManager->getAppPath($app['id']);
$existsLocally = true; $existsLocally = true;
} catch (AppPathNotFoundException $e) { } catch (AppPathNotFoundException) {
$existsLocally = false; $existsLocally = false;
} }

@ -560,12 +560,13 @@ class Installer {
if ($output instanceof IOutput) { if ($output instanceof IOutput) {
$output->debug('Installing ' . $app); $output->debug('Installing ' . $app);
} }
//install the database
$appPath = OC_App::getAppPath($app);
\OC_App::registerAutoloading($app, $appPath);
$appManager = \OCP\Server::get(IAppManager::class);
$config = \OCP\Server::get(IConfig::class); $config = \OCP\Server::get(IConfig::class);
$appPath = $appManager->getAppPath($app);
\OC_App::registerAutoloading($app, $appPath);
$ms = new MigrationService($app, \OCP\Server::get(Connection::class)); $ms = new MigrationService($app, \OCP\Server::get(Connection::class));
if ($output instanceof IOutput) { if ($output instanceof IOutput) {
$ms->setOutput($output); $ms->setOutput($output);

@ -40,6 +40,8 @@ declare(strict_types=1);
namespace OC\L10N; namespace OC\L10N;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\ICache; use OCP\ICache;
use OCP\ICacheFactory; use OCP\ICacheFactory;
use OCP\IConfig; use OCP\IConfig;
@ -88,38 +90,17 @@ class Factory implements IFactory {
'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
]; ];
/** @var IConfig */
protected $config;
/** @var IRequest */
protected $request;
/** @var IUserSession */
protected IUserSession $userSession;
private ICache $cache; private ICache $cache;
/** @var string */
protected $serverRoot;
/**
* @param IConfig $config
* @param IRequest $request
* @param IUserSession $userSession
* @param string $serverRoot
*/
public function __construct( public function __construct(
IConfig $config, protected IConfig $config,
IRequest $request, protected IRequest $request,
IUserSession $userSession, protected IUserSession $userSession,
ICacheFactory $cacheFactory, ICacheFactory $cacheFactory,
$serverRoot protected string $serverRoot,
protected IAppManager $appManager,
) { ) {
$this->config = $config;
$this->request = $request;
$this->userSession = $userSession;
$this->cache = $cacheFactory->createLocal('L10NFactory'); $this->cache = $cacheFactory->createLocal('L10NFactory');
$this->serverRoot = $serverRoot;
} }
/** /**
@ -562,9 +543,7 @@ class Factory implements IFactory {
* @param string $lang * @param string $lang
* @return string[] * @return string[]
*/ */
// FIXME This method is only public, until OC_L10N does not need it anymore, private function getL10nFilesForApp($app, $lang) {
// FIXME This is also the reason, why it is not in the public interface
public function getL10nFilesForApp($app, $lang) {
$languageFiles = []; $languageFiles = [];
$i18nDir = $this->findL10nDir($app); $i18nDir = $this->findL10nDir($app);
@ -572,7 +551,7 @@ class Factory implements IFactory {
if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
|| $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
|| $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')) || $this->isSubDirectory($transFile, $this->appManager->getAppPath($app) . '/l10n/'))
&& file_exists($transFile) && file_exists($transFile)
) { ) {
// load the translations file // load the translations file
@ -602,9 +581,12 @@ class Factory implements IFactory {
if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
return $this->serverRoot . '/' . $app . '/l10n/'; return $this->serverRoot . '/' . $app . '/l10n/';
} }
} elseif ($app && \OC_App::getAppPath($app) !== false) { } elseif ($app) {
// Check if the app is in the app folder try {
return \OC_App::getAppPath($app) . '/l10n/'; return $this->appManager->getAppPath($app) . '/l10n/';
} catch (AppPathNotFoundException) {
/* App not found, continue */
}
} }
return $this->serverRoot . '/core/l10n/'; return $this->serverRoot . '/core/l10n/';
} }

@ -24,6 +24,7 @@
*/ */
namespace OC\Route; namespace OC\Route;
use OCP\App\IAppManager;
use OCP\Diagnostics\IEventLogger; use OCP\Diagnostics\IEventLogger;
use OCP\ICache; use OCP\ICache;
use OCP\ICacheFactory; use OCP\ICacheFactory;
@ -41,10 +42,11 @@ class CachingRouter extends Router {
IRequest $request, IRequest $request,
IConfig $config, IConfig $config,
IEventLogger $eventLogger, IEventLogger $eventLogger,
ContainerInterface $container ContainerInterface $container,
IAppManager $appManager,
) { ) {
$this->cache = $cacheFactory->createLocal('route'); $this->cache = $cacheFactory->createLocal('route');
parent::__construct($logger, $request, $config, $eventLogger, $container); parent::__construct($logger, $request, $config, $eventLogger, $container, $appManager);
} }
/** /**

@ -35,6 +35,8 @@ namespace OC\Route;
use DirectoryIterator; use DirectoryIterator;
use OC\AppFramework\Routing\RouteParser; use OC\AppFramework\Routing\RouteParser;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\AppFramework\Http\Attribute\Route as RouteAttribute; use OCP\AppFramework\Http\Attribute\Route as RouteAttribute;
use OCP\Diagnostics\IEventLogger; use OCP\Diagnostics\IEventLogger;
@ -71,22 +73,17 @@ class Router implements IRouter {
protected $loaded = false; protected $loaded = false;
/** @var array */ /** @var array */
protected $loadedApps = []; protected $loadedApps = [];
protected LoggerInterface $logger;
/** @var RequestContext */ /** @var RequestContext */
protected $context; protected $context;
private IEventLogger $eventLogger;
private IConfig $config;
private ContainerInterface $container;
public function __construct( public function __construct(
LoggerInterface $logger, protected LoggerInterface $logger,
IRequest $request, IRequest $request,
IConfig $config, private IConfig $config,
IEventLogger $eventLogger, private IEventLogger $eventLogger,
ContainerInterface $container private ContainerInterface $container,
private IAppManager $appManager,
) { ) {
$this->logger = $logger;
$this->config = $config;
$baseUrl = \OC::$WEBROOT; $baseUrl = \OC::$WEBROOT;
if (!($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) { if (!($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
$baseUrl .= '/index.php'; $baseUrl .= '/index.php';
@ -101,8 +98,6 @@ class Router implements IRouter {
$this->context = new RequestContext($baseUrl, $method, $host, $schema); $this->context = new RequestContext($baseUrl, $method, $host, $schema);
// TODO cache // TODO cache
$this->root = $this->getCollection('root'); $this->root = $this->getCollection('root');
$this->eventLogger = $eventLogger;
$this->container = $container;
} }
/** /**
@ -114,12 +109,14 @@ class Router implements IRouter {
if ($this->routingFiles === null) { if ($this->routingFiles === null) {
$this->routingFiles = []; $this->routingFiles = [];
foreach (\OC_APP::getEnabledApps() as $app) { foreach (\OC_APP::getEnabledApps() as $app) {
$appPath = \OC_App::getAppPath($app); try {
if ($appPath !== false) { $appPath = $this->appManager->getAppPath($app);
$file = $appPath . '/appinfo/routes.php'; $file = $appPath . '/appinfo/routes.php';
if (file_exists($file)) { if (file_exists($file)) {
$this->routingFiles[$app] = $file; $this->routingFiles[$app] = $file;
} }
} catch (AppPathNotFoundException) {
/* ignore */
} }
} }
} }

@ -653,7 +653,8 @@ class Server extends ServerContainer implements IServerContainer {
$c->getRequest(), $c->getRequest(),
$c->get(IUserSession::class), $c->get(IUserSession::class),
$c->get(ICacheFactory::class), $c->get(ICacheFactory::class),
\OC::$SERVERROOT \OC::$SERVERROOT,
$c->get(IAppManager::class),
); );
}); });
/** @deprecated 19.0.0 */ /** @deprecated 19.0.0 */

@ -560,7 +560,6 @@ class AppTest extends \Test\TestCase {
$this->overwriteService(AppManager::class, new AppManager( $this->overwriteService(AppManager::class, new AppManager(
\OC::$server->getUserSession(), \OC::$server->getUserSession(),
\OC::$server->getConfig(), \OC::$server->getConfig(),
$appConfig,
\OC::$server->getGroupManager(), \OC::$server->getGroupManager(),
\OC::$server->getMemCacheFactory(), \OC::$server->getMemCacheFactory(),
\OC::$server->get(IEventDispatcher::class), \OC::$server->get(IEventDispatcher::class),