Install.php 2.4 KB

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