ListApps.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Robin Appelman <icewind@owncloud.com>
  8. * @author Victor Dubiniuk <dubiniuk@owncloud.com>
  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\Core\Command\Base;
  27. use OCP\App\IAppManager;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Input\InputOption;
  30. use Symfony\Component\Console\Output\OutputInterface;
  31. class ListApps extends Base {
  32. /** @var IAppManager */
  33. protected $manager;
  34. /**
  35. * @param IAppManager $manager
  36. */
  37. public function __construct(IAppManager $manager) {
  38. parent::__construct();
  39. $this->manager = $manager;
  40. }
  41. protected function configure() {
  42. parent::configure();
  43. $this
  44. ->setName('app:list')
  45. ->setDescription('List all available apps')
  46. ->addOption(
  47. 'shipped',
  48. null,
  49. InputOption::VALUE_REQUIRED,
  50. 'true - limit to shipped apps only, false - limit to non-shipped apps only'
  51. )
  52. ;
  53. }
  54. protected function execute(InputInterface $input, OutputInterface $output) {
  55. if ($input->getOption('shipped') === 'true' || $input->getOption('shipped') === 'false'){
  56. $shippedFilter = $input->getOption('shipped') === 'true';
  57. } else {
  58. $shippedFilter = null;
  59. }
  60. $apps = \OC_App::getAllApps();
  61. $enabledApps = $disabledApps = [];
  62. $versions = \OC_App::getAppVersions();
  63. //sort enabled apps above disabled apps
  64. foreach ($apps as $app) {
  65. if ($shippedFilter !== null && \OC_App::isShipped($app) !== $shippedFilter){
  66. continue;
  67. }
  68. if ($this->manager->isInstalled($app)) {
  69. $enabledApps[] = $app;
  70. } else {
  71. $disabledApps[] = $app;
  72. }
  73. }
  74. $apps = ['enabled' => [], 'disabled' => []];
  75. sort($enabledApps);
  76. foreach ($enabledApps as $app) {
  77. $apps['enabled'][$app] = (isset($versions[$app])) ? $versions[$app] : true;
  78. }
  79. sort($disabledApps);
  80. foreach ($disabledApps as $app) {
  81. $apps['disabled'][$app] = null;
  82. }
  83. $this->writeAppList($input, $output, $apps);
  84. }
  85. /**
  86. * @param InputInterface $input
  87. * @param OutputInterface $output
  88. * @param array $items
  89. */
  90. protected function writeAppList(InputInterface $input, OutputInterface $output, $items) {
  91. switch ($input->getOption('output')) {
  92. case self::OUTPUT_FORMAT_PLAIN:
  93. $output->writeln('Enabled:');
  94. parent::writeArrayInOutputFormat($input, $output, $items['enabled']);
  95. $output->writeln('Disabled:');
  96. parent::writeArrayInOutputFormat($input, $output, $items['disabled']);
  97. break;
  98. default:
  99. parent::writeArrayInOutputFormat($input, $output, $items);
  100. break;
  101. }
  102. }
  103. }