Completed
Push — master ( 4a6357...521c8c )
by Franco
10s
created

code/jobs/ContentReviewNotificationJob.php (6 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
if (!class_exists("AbstractQueuedJob")) {
4
    return;
5
}
6
7
/**
8
 * Allows the content review module to use the optional queued jobs module to automatically
9
 * process content review emails. If the module isn't installed, nothing is done - SilverStripe
10
 * will never include this class declaration.
11
 *
12
 * If the module is installed, it will create a new job to be processed once every day by default.
13
 *
14
 * @see https://github.com/silverstripe-australia/silverstripe-queuedjobs
15
 */
16
class ContentReviewNotificationJob extends AbstractQueuedJob implements QueuedJob
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...
17
{
18
    /**
19
     * The hour that the first job will be created at (for the next day). All other jobs should
20
     * be triggered around this time too, as the next generation is queued when this job is run.
21
     *
22
     * @var int
23
     *
24
     * @config
25
     */
26
    private static $first_run_hour = 9;
0 ignored issues
show
The property $first_run_hour is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
27
28
    /**
29
     * The hour at which to run these jobs.
30
     *
31
     * @var int
32
     *
33
     * @config
34
     */
35
    private static $next_run_hour = 9;
0 ignored issues
show
The property $next_run_hour is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
36
37
    /**
38
     * The minutes past the hour (see above) at which to run these jobs.
39
     *
40
     * @var int
41
     *
42
     * @config
43
     */
44
    private static $next_run_minute = 0;
0 ignored issues
show
The property $next_run_minute is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
45
46
    /**
47
     * The number of days to skip between job runs (1 means run this job every day,
48
     * 2 means run it every second day etc).
49
     *
50
     * @var int
51
     *
52
     * @config
53
     */
54
    private static $next_run_in_days = 1;
0 ignored issues
show
The property $next_run_in_days is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
55
56
    /**
57
     * @return string
58
     */
59
    public function getTitle()
60
    {
61
        return "Content Review Notification Job";
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getJobType()
68
    {
69
        $this->totalSteps = 1;
70
71
        return QueuedJob::QUEUED;
72
    }
73
74
    public function process()
75
    {
76
        $this->queueNextRun();
77
78
        $task = new ContentReviewEmails();
79
        $task->run(new SS_HTTPRequest("GET", "/dev/tasks/ContentReviewEmails"));
80
81
        $this->currentStep = 1;
82
        $this->isComplete = true;
83
    }
84
85
    /**
86
     * Queue up the next job to run.
87
     */
88
    protected function queueNextRun()
89
    {
90
        $nextRun = new ContentReviewNotificationJob();
91
92
        $nextRunTime = mktime(
93
            Config::inst()->get(__CLASS__, 'next_run_hour'),
94
            Config::inst()->get(__CLASS__, 'next_run_minute'),
95
            0,
96
            date("m"),
97
            date("d") + Config::inst()->get(__CLASS__, 'next_run_in_days'),
98
            date("Y")
99
        );
100
101
        singleton("QueuedJobService")->queueJob(
102
            $nextRun,
103
            date("Y-m-d H:i:s", $nextRunTime)
104
        );
105
    }
106
}
107