Install.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 Symfony\Component\Console\Command\Command;
  31. use Symfony\Component\Console\Input\InputArgument;
  32. use Symfony\Component\Console\Input\InputInterface;
  33. use Symfony\Component\Console\Input\InputOption;
  34. use Symfony\Component\Console\Output\OutputInterface;
  35. class Install extends Command {
  36. protected function configure() {
  37. $this
  38. ->setName('app:install')
  39. ->setDescription('install an app')
  40. ->addArgument(
  41. 'app-id',
  42. InputArgument::REQUIRED,
  43. 'install the specified app'
  44. )
  45. ->addOption(
  46. 'keep-disabled',
  47. null,
  48. InputOption::VALUE_NONE,
  49. 'don\'t enable the app afterwards'
  50. )
  51. ->addOption(
  52. 'force',
  53. 'f',
  54. InputOption::VALUE_NONE,
  55. 'install the app regardless of the Nextcloud version requirement'
  56. )
  57. ->addOption(
  58. 'allow-unstable',
  59. null,
  60. InputOption::VALUE_NONE,
  61. 'allow installing an unstable releases'
  62. )
  63. ;
  64. }
  65. protected function execute(InputInterface $input, OutputInterface $output): int {
  66. $appId = $input->getArgument('app-id');
  67. $forceEnable = (bool) $input->getOption('force');
  68. if (\OC_App::getAppPath($appId)) {
  69. $output->writeln($appId . ' already installed');
  70. return 1;
  71. }
  72. try {
  73. /** @var Installer $installer */
  74. $installer = \OC::$server->query(Installer::class);
  75. $installer->downloadApp($appId, $input->getOption('allow-unstable'));
  76. $result = $installer->installApp($appId, $forceEnable);
  77. } catch (\Exception $e) {
  78. $output->writeln('Error: ' . $e->getMessage());
  79. return 1;
  80. }
  81. if ($result === false) {
  82. $output->writeln($appId . ' couldn\'t be installed');
  83. return 1;
  84. }
  85. $appVersion = \OC_App::getAppVersion($appId);
  86. $output->writeln($appId . ' ' . $appVersion . ' installed');
  87. if (!$input->getOption('keep-disabled')) {
  88. $appClass = new \OC_App();
  89. $appClass->enable($appId);
  90. $output->writeln($appId . ' enabled');
  91. }
  92. return 0;
  93. }
  94. }