1
0

Status.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OC\Core\Command;
  8. use OC_Util;
  9. use OCP\Defaults;
  10. use OCP\IConfig;
  11. use OCP\Util;
  12. use Symfony\Component\Console\Input\InputInterface;
  13. use Symfony\Component\Console\Input\InputOption;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. class Status extends Base {
  16. public function __construct(
  17. private IConfig $config,
  18. private Defaults $themingDefaults,
  19. ) {
  20. parent::__construct('status');
  21. }
  22. protected function configure() {
  23. parent::configure();
  24. $this
  25. ->setDescription('show some status information')
  26. ->addOption(
  27. 'exit-code',
  28. 'e',
  29. InputOption::VALUE_NONE,
  30. '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.'
  31. );
  32. }
  33. protected function execute(InputInterface $input, OutputInterface $output): int {
  34. $maintenanceMode = $this->config->getSystemValueBool('maintenance', false);
  35. $needUpgrade = Util::needUpgrade();
  36. $values = [
  37. 'installed' => $this->config->getSystemValueBool('installed', false),
  38. 'version' => implode('.', Util::getVersion()),
  39. 'versionstring' => OC_Util::getVersionString(),
  40. 'edition' => '',
  41. 'maintenance' => $maintenanceMode,
  42. 'needsDbUpgrade' => $needUpgrade,
  43. 'productname' => $this->themingDefaults->getProductName(),
  44. 'extendedSupport' => Util::hasExtendedSupport()
  45. ];
  46. if ($input->getOption('verbose') || !$input->getOption('exit-code')) {
  47. $this->writeArrayInOutputFormat($input, $output, $values);
  48. }
  49. if ($input->getOption('exit-code')) {
  50. if ($maintenanceMode === true) {
  51. return 1;
  52. }
  53. if ($needUpgrade === true) {
  54. return 2;
  55. }
  56. }
  57. return 0;
  58. }
  59. }