2017-07-07 02:33:31 -04:00
|
|
|
<?php
|
2024-03-06 05:54:58 -05:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-07-07 02:33:31 -04:00
|
|
|
/**
|
2024-05-24 13:43:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2017-07-07 02:33:31 -04:00
|
|
|
*/
|
2017-07-26 09:24:24 -04:00
|
|
|
namespace OC\Core\Command\App;
|
|
|
|
|
|
2017-07-07 02:33:31 -04:00
|
|
|
use OC\Installer;
|
2025-09-12 05:48:28 -04:00
|
|
|
use OCP\App\AppPathNotFoundException;
|
2023-05-31 15:13:58 -04:00
|
|
|
use OCP\App\IAppManager;
|
2017-07-07 02:33:31 -04:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2019-11-22 14:52:10 -05:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2017-07-07 02:33:31 -04:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class Install extends Command {
|
2024-03-06 05:54:58 -05:00
|
|
|
public function __construct(
|
|
|
|
|
protected IAppManager $appManager,
|
|
|
|
|
private Installer $installer,
|
|
|
|
|
) {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 04:00:27 -04:00
|
|
|
protected function configure(): void {
|
2017-07-07 02:33:31 -04:00
|
|
|
$this
|
|
|
|
|
->setName('app:install')
|
|
|
|
|
->setDescription('install an app')
|
|
|
|
|
->addArgument(
|
|
|
|
|
'app-id',
|
|
|
|
|
InputArgument::REQUIRED,
|
|
|
|
|
'install the specified app'
|
|
|
|
|
)
|
2017-09-13 06:30:03 -04:00
|
|
|
->addOption(
|
2018-02-20 04:54:41 -05:00
|
|
|
'keep-disabled',
|
2017-09-13 06:30:03 -04:00
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
2018-02-20 04:54:41 -05:00
|
|
|
'don\'t enable the app afterwards'
|
2017-09-13 06:30:03 -04:00
|
|
|
)
|
2021-03-22 18:49:13 -04:00
|
|
|
->addOption(
|
|
|
|
|
'force',
|
|
|
|
|
'f',
|
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
|
'install the app regardless of the Nextcloud version requirement'
|
|
|
|
|
)
|
2022-03-10 02:21:31 -05:00
|
|
|
->addOption(
|
|
|
|
|
'allow-unstable',
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
|
'allow installing an unstable releases'
|
|
|
|
|
)
|
2017-07-07 02:33:31 -04:00
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 08:54:51 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2017-07-07 02:33:31 -04:00
|
|
|
$appId = $input->getArgument('app-id');
|
2024-08-23 09:10:27 -04:00
|
|
|
$forceEnable = (bool)$input->getOption('force');
|
2017-07-07 02:33:31 -04:00
|
|
|
|
2025-09-12 05:48:28 -04:00
|
|
|
try {
|
|
|
|
|
$this->appManager->getAppPath($appId);
|
2017-07-07 02:33:31 -04:00
|
|
|
$output->writeln($appId . ' already installed');
|
|
|
|
|
return 1;
|
2025-09-12 05:48:28 -04:00
|
|
|
} catch (AppPathNotFoundException) {
|
2017-07-07 02:33:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2024-03-06 05:54:58 -05:00
|
|
|
$this->installer->downloadApp($appId, $input->getOption('allow-unstable'));
|
|
|
|
|
$result = $this->installer->installApp($appId, $forceEnable);
|
2020-04-10 08:19:56 -04:00
|
|
|
} catch (\Exception $e) {
|
2017-07-07 02:33:31 -04:00
|
|
|
$output->writeln('Error: ' . $e->getMessage());
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-06 05:54:58 -05:00
|
|
|
$appVersion = $this->appManager->getAppVersion($appId);
|
2020-04-30 03:43:33 -04:00
|
|
|
$output->writeln($appId . ' ' . $appVersion . ' installed');
|
2017-07-07 02:33:31 -04:00
|
|
|
|
2018-02-20 04:54:41 -05:00
|
|
|
if (!$input->getOption('keep-disabled')) {
|
2024-03-06 05:54:58 -05:00
|
|
|
$this->appManager->enableApp($appId);
|
2017-09-13 06:30:03 -04:00
|
|
|
$output->writeln($appId . ' enabled');
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 02:33:31 -04:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|