Install.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. ;
  58. }
  59. protected function execute(InputInterface $input, OutputInterface $output): int {
  60. $appId = $input->getArgument('app-id');
  61. $forceEnable = (bool) $input->getOption('force');
  62. if (\OC_App::getAppPath($appId)) {
  63. $output->writeln($appId . ' already installed');
  64. return 1;
  65. }
  66. try {
  67. /** @var Installer $installer */
  68. $installer = \OC::$server->query(Installer::class);
  69. $installer->downloadApp($appId);
  70. $result = $installer->installApp($appId, $forceEnable);
  71. } catch (\Exception $e) {
  72. $output->writeln('Error: ' . $e->getMessage());
  73. return 1;
  74. }
  75. if ($result === false) {
  76. $output->writeln($appId . ' couldn\'t be installed');
  77. return 1;
  78. }
  79. $appVersion = \OC_App::getAppVersion($appId);
  80. $output->writeln($appId . ' ' . $appVersion . ' installed');
  81. if (!$input->getOption('keep-disabled')) {
  82. $appClass = new \OC_App();
  83. $appClass->enable($appId);
  84. $output->writeln($appId . ' enabled');
  85. }
  86. return 0;
  87. }
  88. }