Install.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. * @author Maxopoly <max@dermax.org>
  10. * @author Morris Jobke <hey@morrisjobke.de>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author sualko <klaus@jsxc.org>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Core\Command\App;
  30. use OC\Installer;
  31. use OCP\App\IAppManager;
  32. use Symfony\Component\Console\Command\Command;
  33. use Symfony\Component\Console\Input\InputArgument;
  34. use Symfony\Component\Console\Input\InputInterface;
  35. use Symfony\Component\Console\Input\InputOption;
  36. use Symfony\Component\Console\Output\OutputInterface;
  37. class Install extends Command {
  38. public function __construct(
  39. protected IAppManager $appManager,
  40. private Installer $installer,
  41. ) {
  42. parent::__construct();
  43. }
  44. protected function configure(): void {
  45. $this
  46. ->setName('app:install')
  47. ->setDescription('install an app')
  48. ->addArgument(
  49. 'app-id',
  50. InputArgument::REQUIRED,
  51. 'install the specified app'
  52. )
  53. ->addOption(
  54. 'keep-disabled',
  55. null,
  56. InputOption::VALUE_NONE,
  57. 'don\'t enable the app afterwards'
  58. )
  59. ->addOption(
  60. 'force',
  61. 'f',
  62. InputOption::VALUE_NONE,
  63. 'install the app regardless of the Nextcloud version requirement'
  64. )
  65. ->addOption(
  66. 'allow-unstable',
  67. null,
  68. InputOption::VALUE_NONE,
  69. 'allow installing an unstable releases'
  70. )
  71. ;
  72. }
  73. protected function execute(InputInterface $input, OutputInterface $output): int {
  74. $appId = $input->getArgument('app-id');
  75. $forceEnable = (bool) $input->getOption('force');
  76. if ($this->appManager->isInstalled($appId)) {
  77. $output->writeln($appId . ' already installed');
  78. return 1;
  79. }
  80. try {
  81. $this->installer->downloadApp($appId, $input->getOption('allow-unstable'));
  82. $result = $this->installer->installApp($appId, $forceEnable);
  83. } catch (\Exception $e) {
  84. $output->writeln('Error: ' . $e->getMessage());
  85. return 1;
  86. }
  87. $appVersion = $this->appManager->getAppVersion($appId);
  88. $output->writeln($appId . ' ' . $appVersion . ' installed');
  89. if (!$input->getOption('keep-disabled')) {
  90. $this->appManager->enableApp($appId);
  91. $output->writeln($appId . ' enabled');
  92. }
  93. return 0;
  94. }
  95. }