summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorPatrik Kernstock <info@pkern.at>2018-10-05 19:51:50 +0200
committerPatrik Kernstock <info@pkern.at>2018-10-05 19:51:50 +0200
commitf27ce6b5a0efaf2f7a5f4942cccd6186f439ed42 (patch)
treed2e494ec47f7393a01106cbb3f657ee0aa641894 /core
parentf8771d3d810b521f83f4c955d62b4c2f4b10cdfc (diff)
downloadnextcloud-server-f27ce6b5a0efaf2f7a5f4942cccd6186f439ed42.tar.gz
nextcloud-server-f27ce6b5a0efaf2f7a5f4942cccd6186f439ed42.zip
Inject AppManager and Installer, check for shipped app prior removing
Signed-off-by: Patrik Kernstock <info@pkern.at>
Diffstat (limited to 'core')
-rw-r--r--core/Command/App/Remove.php35
-rw-r--r--core/register_command.php2
2 files changed, 30 insertions, 7 deletions
diff --git a/core/Command/App/Remove.php b/core/Command/App/Remove.php
index 75d3cac6b04..d14a3c6e090 100644
--- a/core/Command/App/Remove.php
+++ b/core/Command/App/Remove.php
@@ -23,6 +23,7 @@
namespace OC\Core\Command\App;
use OC\Installer;
+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;
@@ -33,6 +34,21 @@ use Symfony\Component\Console\Output\OutputInterface;
class Remove extends Command implements CompletionAwareInterface {
+ /** @var IAppManager */
+ protected $manager;
+ /** @var Installer */
+ private $installer;
+
+ /**
+ * @param IAppManager $manager
+ * @param Installer $installer
+ */
+ public function __construct(IAppManager $manager, Installer $installer) {
+ parent::__construct();
+ $this->manager = $manager;
+ $this->installer = $installer;
+ }
+
protected function configure() {
$this
->setName('app:remove')
@@ -53,16 +69,24 @@ class Remove extends Command implements CompletionAwareInterface {
protected function execute(InputInterface $input, OutputInterface $output) {
$appId = $input->getArgument('app-id');
+ // Check if the app is installed
if (!\OC_App::getAppPath($appId)) {
$output->writeln($appId . ' is not installed');
return 1;
}
+ // Removing shipped apps is not possible, therefore we pre-check that
+ // before trying to remove it
+ if ($this->manager->isShipped($appId)) {
+ $output->writeln($appId . ' could not be removed as it is a shipped app');
+ return 1;
+ }
+
+ // If we want to keep the data of the app, we simply don't disable it here.
+ // App uninstall tasks are being executed when disabled. More info: PR #11627.
if (!$input->getOption('keep-data')) {
try {
- /** @var IAppManager $appManager*/
- $appManager = \OC::$server->getAppManager();
- $appManager->disableApp($appId);
+ $this->manager->disableApp($appId);
$output->writeln($appId . ' disabled');
} catch(\Exception $e) {
$output->writeln('Error: ' . $e->getMessage());
@@ -70,10 +94,9 @@ class Remove extends Command implements CompletionAwareInterface {
}
}
+ // Let's try to remove the app...
try {
- /** @var Installer $installer */
- $installer = \OC::$server->query(Installer::class);
- $result = $installer->removeApp($appId);
+ $result = $this->installer->removeApp($appId);
} catch(\Exception $e) {
$output->writeln('Error: ' . $e->getMessage());
return 1;
diff --git a/core/register_command.php b/core/register_command.php
index 0e53cd20df1..02cc450c24f 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -65,7 +65,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\App\Install());
$application->add(new OC\Core\Command\App\GetPath());
$application->add(new OC\Core\Command\App\ListApps(\OC::$server->getAppManager()));
- $application->add(new OC\Core\Command\App\Remove());
+ $application->add(new OC\Core\Command\App\Remove(\OC::$server->getAppManager(), \OC::$server->query(\OC\Installer::class)));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Cleanup::class));
$application->add(\OC::$server->query(\OC\Core\Command\TwoFactorAuth\Enforce::class));