GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 3735d0...fb66dc )
by Anton
02:17
created

contrib/crontab.php (1 issue)

Labels
Severity
1
<?php
2
/* (c) Asafov Sergey <[email protected]>
3
 * Recipe for crontab jobs deploy
4
 * Configuration:
5
    You need no specify only crontab:jobs, which must be array of strings
6
 */
7
namespace Deployer;
8
9
// Get path to bin
10
set('bin/crontab', function () {
11
    return run('which crontab');
12
});
13
14
desc('Load crontab');
15
task('crontab:load', function () {
16
    set('crontab:all', []);
17
18
    // Crontab is empty
19
    if (!test ("[ -f '/var/spool/cron/{{user}}' ]")) {
20
        return;
21
    }
22
23
    $cronData = run ("{{bin/crontab}} -l");
24
    $cronLines = explode (PHP_EOL, $cronData);
25
26
    $currentTasks = [];
27
    foreach ($cronLines as $cronLine) {
28
        $jobData = parseJob($cronLine);
29
        if (is_null ($jobData)) {
30
            continue;
31
        }
32
33
        $currentTasks[$jobData['ckey']] = $jobData;
34
    }
35
36
    set ('crontab:all', $currentTasks);
37
});
38
39
desc('Sync crontab jobs');
40
task('crontab:sync', function () {
41
    $syncJobs = get('crontab:jobs', []);
42
43
    if (count ($syncJobs) == 0) {
0 ignored issues
show
It seems like $syncJobs can also be of type string; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
    if (count (/** @scrutinizer ignore-type */ $syncJobs) == 0) {
Loading history...
44
        writeln("Nothing to sync - configure crontab:jobs");
45
        return;
46
    }
47
48
    // Load current jobs
49
    invoke('crontab:load');
50
    $cronJobs = get('crontab:all');
51
52
    foreach ($syncJobs as $syncJob) {
53
        $syncJobData = parseJob($syncJob);
54
55
        if (is_null ($syncJobData)) {
56
            continue;
57
        }
58
59
        $cronJobData = $cronJobs[$syncJobData['ckey']] ?? NULL;
60
61
        if (!is_null ($cronJobData) && $cronJobData['skey'] == $syncJobData['skey']) {
62
            // Job is exists and correct
63
            writeLn($syncJobData['cmd'] . ': <fg=green;options=bold>OK</>');
64
        }
65
        else {
66
            if (is_null ($cronJobData)) {
67
                writeLn($syncJobData['cmd'] . ': <fg=yellow;options=bold>NEW</>');
68
            }
69
            else {
70
                writeLn($syncJobData['cmd'] . ': <fg=red;options=bold>FIX</>');
71
            }
72
73
            $cronJobs[$syncJobData['ckey']] = $syncJobData;
74
        }
75
    }
76
77
    if (test ("[ -f '/tmp/crontab_save' ]")) {
78
        run ("unlink '/tmp/crontab_save'");
79
    }
80
81
    foreach ($cronJobs as $cronJob) {
82
        $jobString = $cronJob['minute'] . ' ' . $cronJob['hour'] . ' ' . $cronJob['day'] . ' ' . $cronJob['month'] . ' ' . $cronJob['weekday'] . ' ' . $cronJob['cmd'];
83
        run ("echo '" . $jobString . "' >> '/tmp/crontab_save'");
84
    }
85
86
    run ("{{bin/crontab}} /tmp/crontab_save");
87
    run ('unlink /tmp/crontab_save');
88
});
89
90
91
function parseJob ($job) {
92
    if (!is_string($job)) {
93
        return NULL;
94
    }
95
96
    if (substr ($job, 0, 1) == '#') {
97
        return NULL;
98
    }
99
100
    $jobData = explode (' ', $job, 6);
101
102
    if (count ($jobData) != 6) {
103
        return NULL;
104
    }
105
106
    return [
107
        'skey' => md5 ($job),
108
        'ckey' => md5 ($jobData['5']),
109
        'minute' => $jobData['0'],
110
        'hour' => $jobData['1'],
111
        'day' => $jobData['2'],
112
        'month' => $jobData['3'],
113
        'weekday' => $jobData['4'],
114
        'cmd' => $jobData['5'],
115
    ];
116
}
117
118