File size: 1,851 Bytes
07c3cdd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php

namespace ProcessMaker\Policies;

use \Luracast\Restler\iAuthenticate;
use \Luracast\Restler\RestException;

/**
 * ControlUnderUpdating sends an error signal 503 to report that the application 
 * is in update.
 */
class ControlUnderUpdating implements iAuthenticate
{

    /**
     * Access verification method.
     *
     * API access will be denied when this method returns false
     *
     * @return boolean true when api access is allowed false otherwise
     * @throws RestException
     */
    public function __isAllowed()
    {
        $response = true;
        self::verifyUnderUpgrading();
        return $response;
    }

    /**
     * Required by interface iAuthenticate 
     * @return string string to be used with WWW-Authenticate header
     * @example Basic
     * @example Digest
     * @example OAuth
     * @return string
     */
    public function __getWWWAuthenticateString()
    {
        return '';
    }

    /**
     * Verify under upgrading, if the state is under update an exception is 
     * thrown of type RestException.
     * @throws RestException
     */
    public static function verifyUnderUpgrading()
    {
        $underUpdating = \Bootstrap::isPMUnderUpdating();
        if ($underUpdating['action']) {
            $sysTemp = true;
            if (defined('SYS_TEMP')) {
                $sysTemp = $underUpdating['workspace'] == SYS_TEMP;
            }
            if ($underUpdating['workspace'] == 'true' || $sysTemp) {
                $message = 'The server is currently unable to handle the request '
                        . 'due to temporary overloading or server maintenance ('
                        . 'an application update has probably been performed on '
                        . 'the server)';
                throw new RestException(503, $message);
            }
        }
    }

}