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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <pvince81@owncloud.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\Util;
  30. use Sabre\DAV\Exception\ServiceUnavailable;
  31. use Sabre\DAV\ServerPlugin;
  32. class MaintenancePlugin extends ServerPlugin {
  33. /** @var IConfig */
  34. private $config;
  35. /**
  36. * Reference to main server object
  37. *
  38. * @var Server
  39. */
  40. private $server;
  41. /**
  42. * @param IConfig $config
  43. */
  44. public function __construct(IConfig $config = null) {
  45. $this->config = $config;
  46. if (is_null($config)) {
  47. $this->config = \OC::$server->getConfig();
  48. }
  49. }
  50. /**
  51. * This initializes the plugin.
  52. *
  53. * This function is called by \Sabre\DAV\Server, after
  54. * addPlugin is called.
  55. *
  56. * This method should set up the required event subscriptions.
  57. *
  58. * @param \Sabre\DAV\Server $server
  59. * @return void
  60. */
  61. public function initialize(\Sabre\DAV\Server $server) {
  62. $this->server = $server;
  63. $this->server->on('beforeMethod:*', [$this, 'checkMaintenanceMode'], 1);
  64. }
  65. /**
  66. * This method is called before any HTTP method and returns http status code 503
  67. * in case the system is in maintenance mode.
  68. *
  69. * @throws ServiceUnavailable
  70. * @return bool
  71. */
  72. public function checkMaintenanceMode() {
  73. if ($this->config->getSystemValueBool('maintenance')) {
  74. throw new ServiceUnavailable('System in maintenance mode.');
  75. }
  76. if (Util::needUpgrade()) {
  77. throw new ServiceUnavailable('Upgrade needed');
  78. }
  79. return true;
  80. }
  81. }