Install.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $installer = \OC::$server->query(Installer::class);
  55. $installer->downloadApp($appId);
  56. $result = $installer->installApp($appId);
  57. } catch(\Exception $e) {
  58. $output->writeln('Error: ' . $e->getMessage());
  59. return 1;
  60. }
  61. if($result === false) {
  62. $output->writeln($appId . ' couldn\'t be installed');
  63. return 1;
  64. }
  65. $output->writeln($appId . ' installed');
  66. if (!$input->getOption('keep-disabled')) {
  67. $appClass = new \OC_App();
  68. $appClass->enable($appId);
  69. $output->writeln($appId . ' enabled');
  70. }
  71. return 0;
  72. }
  73. }