Skip to content
Prev Previous commit
Next Next commit
fix: Migrate a few more classes away from OC_App::getAppPath
Also fixed AppTest

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Apr 22, 2024
commit 733a81813946d3d00bb403f6f4afaa1f177003a6
2 changes: 1 addition & 1 deletion apps/settings/lib/Controller/AppSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private function getAppsForCategory($requestedCategory = ''): array {
try {
$this->appManager->getAppPath($app['id']);
$existsLocally = true;
} catch (AppPathNotFoundException $e) {
} catch (AppPathNotFoundException) {
$existsLocally = false;
}

Expand Down
7 changes: 4 additions & 3 deletions lib/private/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,12 +560,13 @@ public static function installShippedApp(string $app, ?IOutput $output = null):
if ($output instanceof IOutput) {
$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);

$appPath = $appManager->getAppPath($app);
\OC_App::registerAutoloading($app, $appPath);

$ms = new MigrationService($app, \OCP\Server::get(Connection::class));
if ($output instanceof IOutput) {
$ms->setOutput($output);
Expand Down
48 changes: 15 additions & 33 deletions lib/private/L10N/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@

namespace OC\L10N;

use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
Expand Down Expand Up @@ -88,38 +90,17 @@ class Factory implements IFactory {
'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;

/** @var string */
protected $serverRoot;

/**
* @param IConfig $config
* @param IRequest $request
* @param IUserSession $userSession
* @param string $serverRoot
*/
public function __construct(
IConfig $config,
IRequest $request,
IUserSession $userSession,
protected IConfig $config,
protected IRequest $request,
protected IUserSession $userSession,
ICacheFactory $cacheFactory,
$serverRoot
protected string $serverRoot,
protected IAppManager $appManager,
) {
$this->config = $config;
$this->request = $request;
$this->userSession = $userSession;
$this->cache = $cacheFactory->createLocal('L10NFactory');
$this->serverRoot = $serverRoot;
}

/**
Expand Down Expand Up @@ -562,17 +543,15 @@ private function isSubDirectory($sub, $parent) {
* @param string $lang
* @return string[]
*/
// FIXME This method is only public, until OC_L10N does not need it anymore,
// FIXME This is also the reason, why it is not in the public interface
public function getL10nFilesForApp($app, $lang) {
private function getL10nFilesForApp($app, $lang) {
$languageFiles = [];

$i18nDir = $this->findL10nDir($app);
$transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';

if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/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)
) {
// load the translations file
Expand Down Expand Up @@ -602,9 +581,12 @@ protected function findL10nDir($app = null) {
if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
return $this->serverRoot . '/' . $app . '/l10n/';
}
} elseif ($app && \OC_App::getAppPath($app) !== false) {
// Check if the app is in the app folder
return \OC_App::getAppPath($app) . '/l10n/';
} elseif ($app) {
try {
return $this->appManager->getAppPath($app) . '/l10n/';
} catch (AppPathNotFoundException) {
/* App not found, continue */
}
}
return $this->serverRoot . '/core/l10n/';
}
Expand Down
6 changes: 4 additions & 2 deletions lib/private/Route/CachingRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
namespace OC\Route;

use OCP\App\IAppManager;
use OCP\Diagnostics\IEventLogger;
use OCP\ICache;
use OCP\ICacheFactory;
Expand All @@ -41,10 +42,11 @@ public function __construct(
IRequest $request,
IConfig $config,
IEventLogger $eventLogger,
ContainerInterface $container
ContainerInterface $container,
IAppManager $appManager,
) {
$this->cache = $cacheFactory->createLocal('route');
parent::__construct($logger, $request, $config, $eventLogger, $container);
parent::__construct($logger, $request, $config, $eventLogger, $container, $appManager);
}

/**
Expand Down
25 changes: 11 additions & 14 deletions lib/private/Route/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

use DirectoryIterator;
use OC\AppFramework\Routing\RouteParser;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\App;
use OCP\AppFramework\Http\Attribute\Route as RouteAttribute;
use OCP\Diagnostics\IEventLogger;
Expand Down Expand Up @@ -71,22 +73,17 @@ class Router implements IRouter {
protected $loaded = false;
/** @var array */
protected $loadedApps = [];
protected LoggerInterface $logger;
/** @var RequestContext */
protected $context;
private IEventLogger $eventLogger;
private IConfig $config;
private ContainerInterface $container;

public function __construct(
LoggerInterface $logger,
protected LoggerInterface $logger,
IRequest $request,
IConfig $config,
IEventLogger $eventLogger,
ContainerInterface $container
private IConfig $config,
private IEventLogger $eventLogger,
private ContainerInterface $container,
private IAppManager $appManager,
) {
$this->logger = $logger;
$this->config = $config;
$baseUrl = \OC::$WEBROOT;
if (!($config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true')) {
$baseUrl .= '/index.php';
Expand All @@ -101,8 +98,6 @@ public function __construct(
$this->context = new RequestContext($baseUrl, $method, $host, $schema);
// TODO cache
$this->root = $this->getCollection('root');
$this->eventLogger = $eventLogger;
$this->container = $container;
}

/**
Expand All @@ -114,12 +109,14 @@ public function getRoutingFiles() {
if ($this->routingFiles === null) {
$this->routingFiles = [];
foreach (\OC_APP::getEnabledApps() as $app) {
$appPath = \OC_App::getAppPath($app);
if ($appPath !== false) {
try {
$appPath = $this->appManager->getAppPath($app);
$file = $appPath . '/appinfo/routes.php';
if (file_exists($file)) {
$this->routingFiles[$app] = $file;
}
} catch (AppPathNotFoundException) {
/* ignore */
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,8 @@ public function __construct($webRoot, \OC\Config $config) {
$c->getRequest(),
$c->get(IUserSession::class),
$c->get(ICacheFactory::class),
\OC::$SERVERROOT
\OC::$SERVERROOT,
$c->get(IAppManager::class),
);
});
/** @deprecated 19.0.0 */
Expand Down
1 change: 0 additions & 1 deletion tests/lib/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ private function registerAppConfig(AppConfig $appConfig) {
$this->overwriteService(AppManager::class, new AppManager(
\OC::$server->getUserSession(),
\OC::$server->getConfig(),
$appConfig,
\OC::$server->getGroupManager(),
\OC::$server->getMemCacheFactory(),
\OC::$server->get(IEventDispatcher::class),
Expand Down