fix: Migrate away from OC_App toward the IAppManager

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/44025/head
Côme Chilliet 2 months ago
parent 683dc07f06
commit 644036ab4e
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A

@ -107,7 +107,8 @@ try {
\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class), \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
\OC::$server->getRequest(), \OC::$server->getRequest(),
\OC::$server->get(\Psr\Log\LoggerInterface::class), \OC::$server->get(\Psr\Log\LoggerInterface::class),
\OC::$server->query(\OC\MemoryInfo::class) \OC::$server->query(\OC\MemoryInfo::class),
\OCP\Server::get(\OCP\App\IAppManager::class),
); );
$application->loadCommands(new ArgvInput(), new ConsoleOutput()); $application->loadCommands(new ArgvInput(), new ConsoleOutput());
$application->run(); $application->run();

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016, ownCloud, Inc.
* *

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016, ownCloud, Inc.
* *
@ -23,12 +26,20 @@
namespace OC\Core\Command\App; namespace OC\Core\Command\App;
use OC\Core\Command\Base; use OC\Core\Command\Base;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class GetPath extends Base { class GetPath extends Base {
public function __construct(
protected IAppManager $appManager,
) {
parent::__construct();
}
protected function configure(): void { protected function configure(): void {
parent::configure(); parent::configure();
@ -52,14 +63,14 @@ class GetPath extends Base {
*/ */
protected function execute(InputInterface $input, OutputInterface $output): int { protected function execute(InputInterface $input, OutputInterface $output): int {
$appName = $input->getArgument('app'); $appName = $input->getArgument('app');
$path = \OC_App::getAppPath($appName); try {
if ($path !== false) { $path = $this->appManager->getAppPath($appName);
$output->writeln($path); } catch (AppPathNotFoundException) {
return 0; // App not found, exit with non-zero
return self::FAILURE;
} }
$output->writeln($path);
// App not found, exit with non-zero return self::SUCCESS;
return 1;
} }
/** /**
@ -69,7 +80,7 @@ class GetPath extends Base {
*/ */
public function completeArgumentValues($argumentName, CompletionContext $context): array { public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app') { if ($argumentName === 'app') {
return \OC_App::getAllApps(); return $this->appManager->getInstalledApps();
} }
return []; return [];
} }

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016, ownCloud, Inc.
* *
@ -36,6 +39,13 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class Install extends Command { class Install extends Command {
public function __construct(
protected IAppManager $appManager,
private Installer $installer,
) {
parent::__construct();
}
protected function configure(): void { protected function configure(): void {
$this $this
->setName('app:install') ->setName('app:install')
@ -70,32 +80,24 @@ class Install extends Command {
$appId = $input->getArgument('app-id'); $appId = $input->getArgument('app-id');
$forceEnable = (bool) $input->getOption('force'); $forceEnable = (bool) $input->getOption('force');
if (\OC_App::getAppPath($appId)) { if ($this->appManager->isInstalled($appId)) {
$output->writeln($appId . ' already installed'); $output->writeln($appId . ' already installed');
return 1; return 1;
} }
try { try {
/** @var Installer $installer */ $this->installer->downloadApp($appId, $input->getOption('allow-unstable'));
$installer = \OC::$server->query(Installer::class); $result = $this->installer->installApp($appId, $forceEnable);
$installer->downloadApp($appId, $input->getOption('allow-unstable'));
$result = $installer->installApp($appId, $forceEnable);
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln('Error: ' . $e->getMessage()); $output->writeln('Error: ' . $e->getMessage());
return 1; return 1;
} }
if ($result === false) { $appVersion = $this->appManager->getAppVersion($appId);
$output->writeln($appId . ' couldn\'t be installed');
return 1;
}
$appVersion = \OCP\Server::get(IAppManager::class)->getAppVersion($appId);
$output->writeln($appId . ' ' . $appVersion . ' installed'); $output->writeln($appId . ' ' . $appVersion . ' installed');
if (!$input->getOption('keep-disabled')) { if (!$input->getOption('keep-disabled')) {
$appClass = new \OC_App(); $this->appManager->enableApp($appId);
$appClass->enable($appId);
$output->writeln($appId . ' enabled'); $output->writeln($appId . ' enabled');
} }

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2018, Patrik Kernstock <info@pkern.at> * @copyright Copyright (c) 2018, Patrik Kernstock <info@pkern.at>
* *
@ -68,7 +71,7 @@ class Remove extends Command implements CompletionAwareInterface {
$appId = $input->getArgument('app-id'); $appId = $input->getArgument('app-id');
// Check if the app is installed // Check if the app is installed
if (!\OC_App::getAppPath($appId)) { if (!$this->manager->isInstalled($appId)) {
$output->writeln($appId . ' is not installed'); $output->writeln($appId . ' is not installed');
return 1; return 1;
} }
@ -135,7 +138,7 @@ class Remove extends Command implements CompletionAwareInterface {
*/ */
public function completeArgumentValues($argumentName, CompletionContext $context): array { public function completeArgumentValues($argumentName, CompletionContext $context): array {
if ($argumentName === 'app-id') { if ($argumentName === 'app-id') {
return \OC_App::getAllApps(); return $this->appManager->getInstalledApps();
} }
return []; return [];
} }

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2018, michag86 (michag86@arcor.de) * @copyright Copyright (c) 2018, michag86 (michag86@arcor.de)
* *
@ -88,7 +91,7 @@ class Update extends Command {
return 1; return 1;
} }
} elseif ($input->getOption('all') || $input->getOption('showonly')) { } elseif ($input->getOption('all') || $input->getOption('showonly')) {
$apps = \OC_App::getAllApps(); $apps = $this->manager->getInstalledApps();
} else { } else {
$output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>"); $output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>");
return 1; return 1;
@ -117,7 +120,7 @@ class Update extends Command {
if ($result === false) { if ($result === false) {
$output->writeln($appId . ' couldn\'t be updated'); $output->writeln($appId . ' couldn\'t be updated');
$return = 1; $return = 1;
} elseif ($result === true) { } else {
$output->writeln($appId . ' updated'); $output->writeln($appId . ' updated');
} }
} }

@ -1,4 +1,7 @@
<?php <?php
declare(strict_types=1);
/** /**
* @copyright Copyright (c) 2016, ownCloud, Inc. * @copyright Copyright (c) 2016, ownCloud, Inc.
* *
@ -26,6 +29,7 @@ namespace OC\Core\Command\L10n;
use DirectoryIterator; use DirectoryIterator;
use OCP\App\IAppManager;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface; use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
@ -35,6 +39,12 @@ use Symfony\Component\Console\Output\OutputInterface;
use UnexpectedValueException; use UnexpectedValueException;
class CreateJs extends Command implements CompletionAwareInterface { class CreateJs extends Command implements CompletionAwareInterface {
public function __construct(
protected IAppManager $appManager,
) {
parent::__construct();
}
protected function configure() { protected function configure() {
$this $this
->setName('l10n:createjs') ->setName('l10n:createjs')
@ -55,11 +65,7 @@ class CreateJs extends Command implements CompletionAwareInterface {
$app = $input->getArgument('app'); $app = $input->getArgument('app');
$lang = $input->getArgument('lang'); $lang = $input->getArgument('lang');
$path = \OC_App::getAppPath($app); $path = $this->appManager->getAppPath($app);
if ($path === false) {
$output->writeln("The app <$app> is unknown.");
return 1;
}
$languages = $lang; $languages = $lang;
if (empty($lang)) { if (empty($lang)) {
$languages = $this->getAllLanguages($path); $languages = $this->getAllLanguages($path);

@ -36,6 +36,8 @@ declare(strict_types=1);
*/ */
namespace OC; namespace OC;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AutoloadNotAllowedException; use OCP\AutoloadNotAllowedException;
use OCP\ICache; use OCP\ICache;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -113,11 +115,15 @@ class Autoloader {
} elseif (strpos($class, 'OCA\\') === 0) { } elseif (strpos($class, 'OCA\\') === 0) {
[, $app, $rest] = explode('\\', $class, 3); [, $app, $rest] = explode('\\', $class, 3);
$app = strtolower($app); $app = strtolower($app);
$appPath = \OC_App::getAppPath($app); try {
if ($appPath && stream_resolve_include_path($appPath)) { $appPath = \OCP\Server::get(IAppManager::class)->getAppPath($app);
$paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php'); if (stream_resolve_include_path($appPath)) {
// If not found in the root of the app directory, insert '/lib' after app id and try again. $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php');
$paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php'); // If not found in the root of the app directory, insert '/lib' after app id and try again.
$paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php');
}
} catch (AppPathNotFoundException) {
// App not found, ignore
} }
} elseif ($class === 'Test\\TestCase') { } elseif ($class === 'Test\\TestCase') {
// This File is considered public API, so we make sure that the class // This File is considered public API, so we make sure that the class

@ -32,6 +32,8 @@ namespace OC\AppFramework\Bootstrap;
use OC\Support\CrashReport\Registry; use OC\Support\CrashReport\Registry;
use OC_App; use OC_App;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
use OCP\AppFramework\App; use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\QueryException; use OCP\AppFramework\QueryException;
@ -46,24 +48,6 @@ use function class_implements;
use function in_array; use function in_array;
class Coordinator { class Coordinator {
/** @var IServerContainer */
private $serverContainer;
/** @var Registry */
private $registry;
/** @var IManager */
private $dashboardManager;
/** @var IEventDispatcher */
private $eventDispatcher;
/** @var IEventLogger */
private $eventLogger;
/** @var LoggerInterface */
private $logger;
/** @var RegistrationContext|null */ /** @var RegistrationContext|null */
private $registrationContext; private $registrationContext;
@ -71,19 +55,14 @@ class Coordinator {
private $bootedApps = []; private $bootedApps = [];
public function __construct( public function __construct(
IServerContainer $container, private IServerContainer $serverContainer,
Registry $registry, private Registry $registry,
IManager $dashboardManager, private IManager $dashboardManager,
IEventDispatcher $eventListener, private IEventDispatcher $eventDispatcher,
IEventLogger $eventLogger, private IEventLogger $eventLogger,
LoggerInterface $logger private IAppManager $appManager,
private LoggerInterface $logger,
) { ) {
$this->serverContainer = $container;
$this->registry = $registry;
$this->dashboardManager = $dashboardManager;
$this->eventDispatcher = $eventListener;
$this->eventLogger = $eventLogger;
$this->logger = $logger;
} }
public function runInitialRegistration(): void { public function runInitialRegistration(): void {
@ -108,11 +87,10 @@ class Coordinator {
$this->eventLogger->start("bootstrap:register_app:$appId:autoloader", "Setup autoloader for $appId"); $this->eventLogger->start("bootstrap:register_app:$appId:autoloader", "Setup autoloader for $appId");
/* /*
* First, we have to enable the app's autoloader * First, we have to enable the app's autoloader
*
* @todo use $this->appManager->getAppPath($appId) here
*/ */
$path = OC_App::getAppPath($appId); try {
if ($path === false) { $path = $this->appManager->getAppPath($appId);
} catch (AppPathNotFoundException) {
// Ignore // Ignore
continue; continue;
} }

@ -32,7 +32,7 @@ namespace OC\Console;
use OC\MemoryInfo; use OC\MemoryInfo;
use OC\NeedsUpdateException; use OC\NeedsUpdateException;
use OC_App; use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager; use OCP\App\IAppManager;
use OCP\Console\ConsoleEvent; use OCP\Console\ConsoleEvent;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
@ -47,25 +47,18 @@ use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class Application { class Application {
private IConfig $config;
private SymfonyApplication $application; private SymfonyApplication $application;
private IEventDispatcher $dispatcher;
private IRequest $request;
private LoggerInterface $logger;
private MemoryInfo $memoryInfo;
public function __construct(IConfig $config, public function __construct(
IEventDispatcher $dispatcher, private IConfig $config,
IRequest $request, private IEventDispatcher $dispatcher,
LoggerInterface $logger, private IRequest $request,
MemoryInfo $memoryInfo) { private LoggerInterface $logger,
private MemoryInfo $memoryInfo,
private IAppManager $appManager,
) {
$defaults = \OC::$server->get('ThemingDefaults'); $defaults = \OC::$server->get('ThemingDefaults');
$this->config = $config;
$this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString());
$this->dispatcher = $dispatcher;
$this->request = $request;
$this->logger = $logger;
$this->memoryInfo = $memoryInfo;
} }
/** /**
@ -111,15 +104,15 @@ class Application {
} elseif ($this->config->getSystemValueBool('maintenance')) { } elseif ($this->config->getSystemValueBool('maintenance')) {
$this->writeMaintenanceModeInfo($input, $output); $this->writeMaintenanceModeInfo($input, $output);
} else { } else {
OC_App::loadApps(); $this->appManager->loadApps();
$appManager = \OCP\Server::get(IAppManager::class); foreach ($this->appManager->getInstalledApps() as $app) {
foreach ($appManager->getInstalledApps() as $app) { try {
$appPath = \OC_App::getAppPath($app); $appPath = $this->appManager->getAppPath($app);
if ($appPath === false) { } catch (AppPathNotFoundException) {
continue; continue;
} }
// load commands using info.xml // load commands using info.xml
$info = $appManager->getAppInfo($app); $info = $this->appManager->getAppInfo($app);
if (isset($info['commands'])) { if (isset($info['commands'])) {
try { try {
$this->loadCommandsFromInfoXml($info['commands']); $this->loadCommandsFromInfoXml($info['commands']);

@ -354,7 +354,7 @@ class OC_App {
* @param string $appId * @param string $appId
* @param bool $refreshAppPath should be set to true only during install/upgrade * @param bool $refreshAppPath should be set to true only during install/upgrade
* @return string|false * @return string|false
* @deprecated 11.0.0 use \OC::$server->getAppManager()->getAppPath() * @deprecated 11.0.0 use \OCP\Server::get(IAppManager)->getAppPath()
*/ */
public static function getAppPath(string $appId, bool $refreshAppPath = false) { public static function getAppPath(string $appId, bool $refreshAppPath = false) {
if ($appId === null || trim($appId) === '') { if ($appId === null || trim($appId) === '') {

Loading…
Cancel
Save