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.

MaintenancePlugin.php 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Bart Visscher <bartv@thisnet.nl>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Vincent Petry <vincent@nextcloud.com>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\DAV\Connector\Sabre;
  28. use OCP\IConfig;
  29. use OCP\IL10N;
  30. use OCP\Util;
  31. use Sabre\DAV\Exception\ServiceUnavailable;
  32. use Sabre\DAV\ServerPlugin;
  33. class MaintenancePlugin extends ServerPlugin {
  34. /** @var IConfig */
  35. private $config;
  36. /** @var \OCP\IL10N */
  37. private $l10n;
  38. /**
  39. * Reference to main server object
  40. *
  41. * @var Server
  42. */
  43. private $server;
  44. /**
  45. * @param IConfig $config
  46. */
  47. public function __construct(IConfig $config, IL10N $l10n) {
  48. $this->config = $config;
  49. $this->l10n = \OC::$server->getL10N('dav');
  50. }
  51. /**
  52. * This initializes the plugin.
  53. *
  54. * This function is called by \Sabre\DAV\Server, after
  55. * addPlugin is called.
  56. *
  57. * This method should set up the required event subscriptions.
  58. *
  59. * @param \Sabre\DAV\Server $server
  60. * @return void
  61. */
  62. public function initialize(\Sabre\DAV\Server $server) {
  63. $this->server = $server;
  64. $this->server->on('beforeMethod:*', [$this, 'checkMaintenanceMode'], 1);
  65. }
  66. /**
  67. * This method is called before any HTTP method and returns http status code 503
  68. * in case the system is in maintenance mode.
  69. *
  70. * @throws ServiceUnavailable
  71. * @return bool
  72. */
  73. public function checkMaintenanceMode() {
  74. if ($this->config->getSystemValueBool('maintenance')) {
  75. throw new ServiceUnavailable($this->l10n->t('System in maintenance mode.'));
  76. }
  77. if (Util::needUpgrade()) {
  78. throw new ServiceUnavailable($this->l10n->t('Upgrade needed'));
  79. }
  80. return true;
  81. }
  82. }