mirror of https://github.com/nextcloud/server
fix: Migrate away from OC_App toward the IAppManager
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
683dc07f06
commit
644036ab4e
|
@ -107,7 +107,8 @@ try {
|
|||
\OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class),
|
||||
\OC::$server->getRequest(),
|
||||
\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->run();
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -23,12 +26,20 @@
|
|||
namespace OC\Core\Command\App;
|
||||
|
||||
use OC\Core\Command\Base;
|
||||
use OCP\App\AppPathNotFoundException;
|
||||
use OCP\App\IAppManager;
|
||||
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class GetPath extends Base {
|
||||
public function __construct(
|
||||
protected IAppManager $appManager,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void {
|
||||
parent::configure();
|
||||
|
||||
|
@ -52,14 +63,14 @@ class GetPath extends Base {
|
|||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$appName = $input->getArgument('app');
|
||||
$path = \OC_App::getAppPath($appName);
|
||||
if ($path !== false) {
|
||||
$output->writeln($path);
|
||||
return 0;
|
||||
try {
|
||||
$path = $this->appManager->getAppPath($appName);
|
||||
} catch (AppPathNotFoundException) {
|
||||
// App not found, exit with non-zero
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
// App not found, exit with non-zero
|
||||
return 1;
|
||||
$output->writeln($path);
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +80,7 @@ class GetPath extends Base {
|
|||
*/
|
||||
public function completeArgumentValues($argumentName, CompletionContext $context): array {
|
||||
if ($argumentName === 'app') {
|
||||
return \OC_App::getAllApps();
|
||||
return $this->appManager->getInstalledApps();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -36,6 +39,13 @@ use Symfony\Component\Console\Input\InputOption;
|
|||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Install extends Command {
|
||||
public function __construct(
|
||||
protected IAppManager $appManager,
|
||||
private Installer $installer,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('app:install')
|
||||
|
@ -70,32 +80,24 @@ class Install extends Command {
|
|||
$appId = $input->getArgument('app-id');
|
||||
$forceEnable = (bool) $input->getOption('force');
|
||||
|
||||
if (\OC_App::getAppPath($appId)) {
|
||||
if ($this->appManager->isInstalled($appId)) {
|
||||
$output->writeln($appId . ' already installed');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
/** @var Installer $installer */
|
||||
$installer = \OC::$server->query(Installer::class);
|
||||
$installer->downloadApp($appId, $input->getOption('allow-unstable'));
|
||||
$result = $installer->installApp($appId, $forceEnable);
|
||||
$this->installer->downloadApp($appId, $input->getOption('allow-unstable'));
|
||||
$result = $this->installer->installApp($appId, $forceEnable);
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln('Error: ' . $e->getMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ($result === false) {
|
||||
$output->writeln($appId . ' couldn\'t be installed');
|
||||
return 1;
|
||||
}
|
||||
|
||||
$appVersion = \OCP\Server::get(IAppManager::class)->getAppVersion($appId);
|
||||
$appVersion = $this->appManager->getAppVersion($appId);
|
||||
$output->writeln($appId . ' ' . $appVersion . ' installed');
|
||||
|
||||
if (!$input->getOption('keep-disabled')) {
|
||||
$appClass = new \OC_App();
|
||||
$appClass->enable($appId);
|
||||
$this->appManager->enableApp($appId);
|
||||
$output->writeln($appId . ' enabled');
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2018, Patrik Kernstock <info@pkern.at>
|
||||
*
|
||||
|
@ -68,7 +71,7 @@ class Remove extends Command implements CompletionAwareInterface {
|
|||
$appId = $input->getArgument('app-id');
|
||||
|
||||
// Check if the app is installed
|
||||
if (!\OC_App::getAppPath($appId)) {
|
||||
if (!$this->manager->isInstalled($appId)) {
|
||||
$output->writeln($appId . ' is not installed');
|
||||
return 1;
|
||||
}
|
||||
|
@ -135,7 +138,7 @@ class Remove extends Command implements CompletionAwareInterface {
|
|||
*/
|
||||
public function completeArgumentValues($argumentName, CompletionContext $context): array {
|
||||
if ($argumentName === 'app-id') {
|
||||
return \OC_App::getAllApps();
|
||||
return $this->appManager->getInstalledApps();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2018, michag86 (michag86@arcor.de)
|
||||
*
|
||||
|
@ -88,7 +91,7 @@ class Update extends Command {
|
|||
return 1;
|
||||
}
|
||||
} elseif ($input->getOption('all') || $input->getOption('showonly')) {
|
||||
$apps = \OC_App::getAllApps();
|
||||
$apps = $this->manager->getInstalledApps();
|
||||
} else {
|
||||
$output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>");
|
||||
return 1;
|
||||
|
@ -117,7 +120,7 @@ class Update extends Command {
|
|||
if ($result === false) {
|
||||
$output->writeln($appId . ' couldn\'t be updated');
|
||||
$return = 1;
|
||||
} elseif ($result === true) {
|
||||
} else {
|
||||
$output->writeln($appId . ' updated');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
*
|
||||
|
@ -26,6 +29,7 @@ namespace OC\Core\Command\L10n;
|
|||
|
||||
use DirectoryIterator;
|
||||
|
||||
use OCP\App\IAppManager;
|
||||
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
|
||||
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
@ -35,6 +39,12 @@ use Symfony\Component\Console\Output\OutputInterface;
|
|||
use UnexpectedValueException;
|
||||
|
||||
class CreateJs extends Command implements CompletionAwareInterface {
|
||||
public function __construct(
|
||||
protected IAppManager $appManager,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function configure() {
|
||||
$this
|
||||
->setName('l10n:createjs')
|
||||
|
@ -55,11 +65,7 @@ class CreateJs extends Command implements CompletionAwareInterface {
|
|||
$app = $input->getArgument('app');
|
||||
$lang = $input->getArgument('lang');
|
||||
|
||||
$path = \OC_App::getAppPath($app);
|
||||
if ($path === false) {
|
||||
$output->writeln("The app <$app> is unknown.");
|
||||
return 1;
|
||||
}
|
||||
$path = $this->appManager->getAppPath($app);
|
||||
$languages = $lang;
|
||||
if (empty($lang)) {
|
||||
$languages = $this->getAllLanguages($path);
|
||||
|
|
|
@ -36,6 +36,8 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OC;
|
||||
|
||||
use OCP\App\AppPathNotFoundException;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AutoloadNotAllowedException;
|
||||
use OCP\ICache;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
@ -113,11 +115,15 @@ class Autoloader {
|
|||
} elseif (strpos($class, 'OCA\\') === 0) {
|
||||
[, $app, $rest] = explode('\\', $class, 3);
|
||||
$app = strtolower($app);
|
||||
$appPath = \OC_App::getAppPath($app);
|
||||
if ($appPath && stream_resolve_include_path($appPath)) {
|
||||
$paths[] = $appPath . '/' . 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');
|
||||
try {
|
||||
$appPath = \OCP\Server::get(IAppManager::class)->getAppPath($app);
|
||||
if (stream_resolve_include_path($appPath)) {
|
||||
$paths[] = $appPath . '/' . 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') {
|
||||
// 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_App;
|
||||
use OCP\App\AppPathNotFoundException;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\QueryException;
|
||||
|
@ -46,24 +48,6 @@ use function class_implements;
|
|||
use function in_array;
|
||||
|
||||
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 */
|
||||
private $registrationContext;
|
||||
|
||||
|
@ -71,19 +55,14 @@ class Coordinator {
|
|||
private $bootedApps = [];
|
||||
|
||||
public function __construct(
|
||||
IServerContainer $container,
|
||||
Registry $registry,
|
||||
IManager $dashboardManager,
|
||||
IEventDispatcher $eventListener,
|
||||
IEventLogger $eventLogger,
|
||||
LoggerInterface $logger
|
||||
private IServerContainer $serverContainer,
|
||||
private Registry $registry,
|
||||
private IManager $dashboardManager,
|
||||
private IEventDispatcher $eventDispatcher,
|
||||
private IEventLogger $eventLogger,
|
||||
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 {
|
||||
|
@ -108,11 +87,10 @@ class Coordinator {
|
|||
$this->eventLogger->start("bootstrap:register_app:$appId:autoloader", "Setup autoloader for $appId");
|
||||
/*
|
||||
* First, we have to enable the app's autoloader
|
||||
*
|
||||
* @todo use $this->appManager->getAppPath($appId) here
|
||||
*/
|
||||
$path = OC_App::getAppPath($appId);
|
||||
if ($path === false) {
|
||||
try {
|
||||
$path = $this->appManager->getAppPath($appId);
|
||||
} catch (AppPathNotFoundException) {
|
||||
// Ignore
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace OC\Console;
|
|||
|
||||
use OC\MemoryInfo;
|
||||
use OC\NeedsUpdateException;
|
||||
use OC_App;
|
||||
use OCP\App\AppPathNotFoundException;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\Console\ConsoleEvent;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
|
@ -47,25 +47,18 @@ use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
|||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Application {
|
||||
private IConfig $config;
|
||||
private SymfonyApplication $application;
|
||||
private IEventDispatcher $dispatcher;
|
||||
private IRequest $request;
|
||||
private LoggerInterface $logger;
|
||||
private MemoryInfo $memoryInfo;
|
||||
|
||||
public function __construct(IConfig $config,
|
||||
IEventDispatcher $dispatcher,
|
||||
IRequest $request,
|
||||
LoggerInterface $logger,
|
||||
MemoryInfo $memoryInfo) {
|
||||
public function __construct(
|
||||
private IConfig $config,
|
||||
private IEventDispatcher $dispatcher,
|
||||
private IRequest $request,
|
||||
private LoggerInterface $logger,
|
||||
private MemoryInfo $memoryInfo,
|
||||
private IAppManager $appManager,
|
||||
) {
|
||||
$defaults = \OC::$server->get('ThemingDefaults');
|
||||
$this->config = $config;
|
||||
$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')) {
|
||||
$this->writeMaintenanceModeInfo($input, $output);
|
||||
} else {
|
||||
OC_App::loadApps();
|
||||
$appManager = \OCP\Server::get(IAppManager::class);
|
||||
foreach ($appManager->getInstalledApps() as $app) {
|
||||
$appPath = \OC_App::getAppPath($app);
|
||||
if ($appPath === false) {
|
||||
$this->appManager->loadApps();
|
||||
foreach ($this->appManager->getInstalledApps() as $app) {
|
||||
try {
|
||||
$appPath = $this->appManager->getAppPath($app);
|
||||
} catch (AppPathNotFoundException) {
|
||||
continue;
|
||||
}
|
||||
// load commands using info.xml
|
||||
$info = $appManager->getAppInfo($app);
|
||||
$info = $this->appManager->getAppInfo($app);
|
||||
if (isset($info['commands'])) {
|
||||
try {
|
||||
$this->loadCommandsFromInfoXml($info['commands']);
|
||||
|
|
|
@ -354,7 +354,7 @@ class OC_App {
|
|||
* @param string $appId
|
||||
* @param bool $refreshAppPath should be set to true only during install/upgrade
|
||||
* @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) {
|
||||
if ($appId === null || trim($appId) === '') {
|
||||
|
|
Loading…
Reference in New Issue