Status.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 OCP\Defaults;
  9. use OCP\IConfig;
  10. use OCP\ServerVersion;
  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. private ServerVersion $serverVersion,
  20. ) {
  21. parent::__construct('status');
  22. }
  23. protected function configure() {
  24. parent::configure();
  25. $this
  26. ->setDescription('show some status information')
  27. ->addOption(
  28. 'exit-code',
  29. 'e',
  30. InputOption::VALUE_NONE,
  31. '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.'
  32. );
  33. }
  34. protected function execute(InputInterface $input, OutputInterface $output): int {
  35. $maintenanceMode = $this->config->getSystemValueBool('maintenance', false);
  36. $needUpgrade = Util::needUpgrade();
  37. $values = [
  38. 'installed' => $this->config->getSystemValueBool('installed', false),
  39. 'version' => implode('.', $this->serverVersion->getVersion()),
  40. 'versionstring' => $this->serverVersion->getVersionString(),
  41. 'edition' => '',
  42. 'maintenance' => $maintenanceMode,
  43. 'needsDbUpgrade' => $needUpgrade,
  44. 'productname' => $this->themingDefaults->getProductName(),
  45. 'extendedSupport' => Util::hasExtendedSupport()
  46. ];
  47. if ($input->getOption('verbose') || !$input->getOption('exit-code')) {
  48. $this->writeArrayInOutputFormat($input, $output, $values);
  49. }
  50. if ($input->getOption('exit-code')) {
  51. if ($maintenanceMode === true) {
  52. return 1;
  53. }
  54. if ($needUpgrade === true) {
  55. return 2;
  56. }
  57. }
  58. return 0;
  59. }
  60. }