Blame view

sources/lib/private/connector/sabre/maintenanceplugin.php 1.25 KB
03e52840d   Kload   Init
1
2
3
4
5
6
7
8
9
10
  <?php
  
  /**
   * ownCloud
   *
   * @author Thomas Müller
   * @copyright 2013 Thomas Müller <thomas.mueller@tmit.eu>
   *
   * @license AGPL3
   */
6d9380f96   Cédric Dupont   Update sources OC...
11
  class OC_Connector_Sabre_MaintenancePlugin extends \Sabre\DAV\ServerPlugin
03e52840d   Kload   Init
12
13
14
15
16
  {
  
  	/**
  	 * Reference to main server object
  	 *
6d9380f96   Cédric Dupont   Update sources OC...
17
  	 * @var \Sabre\DAV\Server
03e52840d   Kload   Init
18
19
20
21
22
23
  	 */
  	private $server;
  
  	/**
  	 * This initializes the plugin.
  	 *
6d9380f96   Cédric Dupont   Update sources OC...
24
  	 * This function is called by \Sabre\DAV\Server, after
03e52840d   Kload   Init
25
26
27
28
  	 * addPlugin is called.
  	 *
  	 * This method should set up the required event subscriptions.
  	 *
6d9380f96   Cédric Dupont   Update sources OC...
29
  	 * @param \Sabre\DAV\Server $server
03e52840d   Kload   Init
30
31
  	 * @return void
  	 */
6d9380f96   Cédric Dupont   Update sources OC...
32
  	public function initialize(\Sabre\DAV\Server $server) {
03e52840d   Kload   Init
33
34
35
36
37
38
39
40
41
  
  		$this->server = $server;
  		$this->server->subscribeEvent('beforeMethod', array($this, 'checkMaintenanceMode'), 10);
  	}
  
  	/**
  	 * This method is called before any HTTP method and returns http status code 503
  	 * in case the system is in maintenance mode.
  	 *
6d9380f96   Cédric Dupont   Update sources OC...
42
  	 * @throws \Sabre\DAV\Exception\ServiceUnavailable
03e52840d   Kload   Init
43
44
45
46
47
  	 * @internal param string $method
  	 * @return bool
  	 */
  	public function checkMaintenanceMode() {
  		if (OC_Config::getValue('maintenance', false)) {
6d9380f96   Cédric Dupont   Update sources OC...
48
  			throw new \Sabre\DAV\Exception\ServiceUnavailable();
03e52840d   Kload   Init
49
50
  		}
  		if (OC::checkUpgrade(false)) {
6d9380f96   Cédric Dupont   Update sources OC...
51
  			throw new \Sabre\DAV\Exception\ServiceUnavailable('Upgrade needed');
03e52840d   Kload   Init
52
53
54
55
56
  		}
  
  		return true;
  	}
  }