Install.php 2.2 KB

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