Completed
Push — development ( 8d1477...1cf5b2 )
by Thomas
11:53 queued 05:53
created

Cronjobs::enabled()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 10
nc 4
nop 0
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
1
<?php
2
/***************************************************************************
3
 *  For license information see doc/license.txt
4
 *
5
 ***************************************************************************/
6
7
/**
8
 * Class Cronjobs
9
 *
10
 * Cronjobs are disabled if the website is down (for maintenance).
11
 */
12
class Cronjobs
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * @return bool
16
     */
17
    public static function enabled()
18
    {
19
        global $argv, $http_response_header, $opt;
20
21
        // maintenance page is active so no cronjob should be executed
22
        if (file_exists(__DIR__ . '/../maintenance.enable')) {
23
            return false;
24
        } elseif (!in_array('--auto', $argv)) {
25
            // Cronjob is run manually (testing). We do it this way round
26
            // (not defaulting to 'auto' when no '--test' param is given),
27
            // because the effect of forgetting a --test parameter can be worse
28
            // than forgetting the --auto option in crontab.
29
            return true;
30
        } elseif (@file_get_contents($opt['page']['absolute_http_url'] . 'api/ping.php') !== false) {
31
            // website is up and running
32
            return true;
33
        } else {
34
            // === null: website is down, or DNS configuration error
35
            // !== null: website is access protected or page is redirected or whatever
36
            return $http_response_header !== null;
37
        }
38
    }
39
}
40