You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Status.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. private IConfig $config;
  35. private Defaults $themingDefaults;
  36. public function __construct(IConfig $config, Defaults $themingDefaults) {
  37. parent::__construct('status');
  38. $this->config = $config;
  39. $this->themingDefaults = $themingDefaults;
  40. }
  41. protected function configure() {
  42. parent::configure();
  43. $this
  44. ->setDescription('show some status information')
  45. ->addOption(
  46. 'exit-code',
  47. 'e',
  48. InputOption::VALUE_NONE,
  49. '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.'
  50. );
  51. }
  52. protected function execute(InputInterface $input, OutputInterface $output): int {
  53. $maintenanceMode = $this->config->getSystemValueBool('maintenance', false);
  54. $needUpgrade = Util::needUpgrade();
  55. $values = [
  56. 'installed' => $this->config->getSystemValueBool('installed', false),
  57. 'version' => implode('.', Util::getVersion()),
  58. 'versionstring' => OC_Util::getVersionString(),
  59. 'edition' => '',
  60. 'maintenance' => $maintenanceMode,
  61. 'needsDbUpgrade' => $needUpgrade,
  62. 'productname' => $this->themingDefaults->getProductName(),
  63. 'extendedSupport' => Util::hasExtendedSupport()
  64. ];
  65. if ($input->getOption('verbose') || !$input->getOption('exit-code')) {
  66. $this->writeArrayInOutputFormat($input, $output, $values);
  67. }
  68. if ($input->getOption('exit-code')) {
  69. if ($maintenanceMode === true) {
  70. return 1;
  71. }
  72. if ($needUpgrade === true) {
  73. return 2;
  74. }
  75. }
  76. return 0;
  77. }
  78. }