aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command
diff options
context:
space:
mode:
authorCôme Chilliet <come.chilliet@nextcloud.com>2024-03-06 11:54:58 +0100
committerCôme Chilliet <come.chilliet@nextcloud.com>2024-04-22 12:14:58 +0200
commit644036ab4e3d1d6f175a485ed7ae4883c668ff48 (patch)
treec11aba914ce246805c420270d0e5bb828c58ee1a /core/Command
parent683dc07f06018e72e46f067a306dc14408ce91f9 (diff)
downloadnextcloud-server-644036ab4e3d1d6f175a485ed7ae4883c668ff48.tar.gz
nextcloud-server-644036ab4e3d1d6f175a485ed7ae4883c668ff48.zip
fix: Migrate away from OC_App toward the IAppManager
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Diffstat (limited to 'core/Command')
-rw-r--r--core/Command/App/Enable.php3
-rw-r--r--core/Command/App/GetPath.php27
-rw-r--r--core/Command/App/Install.php28
-rw-r--r--core/Command/App/Remove.php7
-rw-r--r--core/Command/App/Update.php7
-rw-r--r--core/Command/L10n/CreateJs.php16
6 files changed, 58 insertions, 30 deletions
diff --git a/core/Command/App/Enable.php b/core/Command/App/Enable.php
index ed29f2fed92..579432a1dd0 100644
--- a/core/Command/App/Enable.php
+++ b/core/Command/App/Enable.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
diff --git a/core/Command/App/GetPath.php b/core/Command/App/GetPath.php
index ea614070e7d..844e14ffdde 100644
--- a/core/Command/App/GetPath.php
+++ b/core/Command/App/GetPath.php
@@ -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 [];
}
diff --git a/core/Command/App/Install.php b/core/Command/App/Install.php
index 2d02fff4dbf..a5657e8397d 100644
--- a/core/Command/App/Install.php
+++ b/core/Command/App/Install.php
@@ -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');
}
diff --git a/core/Command/App/Remove.php b/core/Command/App/Remove.php
index 5fa05079bd8..d017a95c681 100644
--- a/core/Command/App/Remove.php
+++ b/core/Command/App/Remove.php
@@ -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 [];
}
diff --git a/core/Command/App/Update.php b/core/Command/App/Update.php
index c8e62cb5b71..6047ac6b843 100644
--- a/core/Command/App/Update.php
+++ b/core/Command/App/Update.php
@@ -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');
}
}
diff --git a/core/Command/L10n/CreateJs.php b/core/Command/L10n/CreateJs.php
index 6472e7aec1c..724e94f28d5 100644
--- a/core/Command/L10n/CreateJs.php
+++ b/core/Command/L10n/CreateJs.php
@@ -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);