Install.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command\App;
  8. use OC\Installer;
  9. use OCP\App\IAppManager;
  10. use Symfony\Component\Console\Command\Command;
  11. use Symfony\Component\Console\Input\InputArgument;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class Install extends Command {
  16. public function __construct(
  17. protected IAppManager $appManager,
  18. private Installer $installer,
  19. ) {
  20. parent::__construct();
  21. }
  22. protected function configure(): void {
  23. $this
  24. ->setName('app:install')
  25. ->setDescription('install an app')
  26. ->addArgument(
  27. 'app-id',
  28. InputArgument::REQUIRED,
  29. 'install the specified app'
  30. )
  31. ->addOption(
  32. 'keep-disabled',
  33. null,
  34. InputOption::VALUE_NONE,
  35. 'don\'t enable the app afterwards'
  36. )
  37. ->addOption(
  38. 'force',
  39. 'f',
  40. InputOption::VALUE_NONE,
  41. 'install the app regardless of the Nextcloud version requirement'
  42. )
  43. ->addOption(
  44. 'allow-unstable',
  45. null,
  46. InputOption::VALUE_NONE,
  47. 'allow installing an unstable releases'
  48. )
  49. ;
  50. }
  51. protected function execute(InputInterface $input, OutputInterface $output): int {
  52. $appId = $input->getArgument('app-id');
  53. $forceEnable = (bool) $input->getOption('force');
  54. if ($this->appManager->isInstalled($appId)) {
  55. $output->writeln($appId . ' already installed');
  56. return 1;
  57. }
  58. try {
  59. $this->installer->downloadApp($appId, $input->getOption('allow-unstable'));
  60. $result = $this->installer->installApp($appId, $forceEnable);
  61. } catch (\Exception $e) {
  62. $output->writeln('Error: ' . $e->getMessage());
  63. return 1;
  64. }
  65. $appVersion = $this->appManager->getAppVersion($appId);
  66. $output->writeln($appId . ' ' . $appVersion . ' installed');
  67. if (!$input->getOption('keep-disabled')) {
  68. $this->appManager->enableApp($appId);
  69. $output->writeln($appId . ' enabled');
  70. }
  71. return 0;
  72. }
  73. }