Status.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  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;
  26. use OC_Util;
  27. use OCP\Defaults;
  28. use OCP\IConfig;
  29. use OCP\Util;
  30. use Symfony\Component\Console\Input\InputInterface;
  31. use Symfony\Component\Console\Input\InputOption;
  32. use Symfony\Component\Console\Output\OutputInterface;
  33. class Status extends Base {
  34. public function __construct(
  35. private IConfig $config,
  36. private Defaults $themingDefaults,
  37. ) {
  38. parent::__construct('status');
  39. }
  40. protected function configure() {
  41. parent::configure();
  42. $this
  43. ->setDescription('show some status information')
  44. ->addOption(
  45. 'exit-code',
  46. 'e',
  47. InputOption::VALUE_NONE,
  48. 'exit with 0 if running in normal mode, 1 when in maintenance mode, 2 when `./occ upgrade` is needed. Does not write any output to STDOUT.'
  49. );
  50. }
  51. protected function execute(InputInterface $input, OutputInterface $output): int {
  52. $maintenanceMode = $this->config->getSystemValueBool('maintenance', false);
  53. $needUpgrade = Util::needUpgrade();
  54. $values = [
  55. 'installed' => $this->config->getSystemValueBool('installed', false),
  56. 'version' => implode('.', Util::getVersion()),
  57. 'versionstring' => OC_Util::getVersionString(),
  58. 'edition' => '',
  59. 'maintenance' => $maintenanceMode,
  60. 'needsDbUpgrade' => $needUpgrade,
  61. 'productname' => $this->themingDefaults->getProductName(),
  62. 'extendedSupport' => Util::hasExtendedSupport()
  63. ];
  64. if ($input->getOption('verbose') || !$input->getOption('exit-code')) {
  65. $this->writeArrayInOutputFormat($input, $output, $values);
  66. }
  67. if ($input->getOption('exit-code')) {
  68. if ($maintenanceMode === true) {
  69. return 1;
  70. }
  71. if ($needUpgrade === true) {
  72. return 2;
  73. }
  74. }
  75. return 0;
  76. }
  77. }