Install.php 3.0 KB

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