2015-07-31 06:07:18 +02:00
|
|
|
<?php
|
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
if (!class_exists("AbstractQueuedJob")) {
|
|
|
|
return;
|
2015-07-31 06:07:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-02 00:27:42 +01:00
|
|
|
* Allows the content review module to use the optional queued jobs module to automatically
|
|
|
|
* process content review emails. If the module isn't installed, nothing is done - SilverStripe
|
|
|
|
* will never include this class declaration.
|
2015-07-31 06:07:18 +02:00
|
|
|
*
|
|
|
|
* If the module is installed, it will create a new job to be processed once every day by default.
|
|
|
|
*
|
|
|
|
* @see https://github.com/silverstripe-australia/silverstripe-queuedjobs
|
|
|
|
*/
|
2015-11-02 00:27:42 +01:00
|
|
|
class ContentReviewNotificationJob extends AbstractQueuedJob implements QueuedJob
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The hour that the first job will be created at (for the next day). All other jobs should
|
|
|
|
* be triggered around this time too, as the next generation is queued when this job is run.
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
*/
|
|
|
|
private static $first_run_hour = 9;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The hour at which to run these jobs.
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
*/
|
|
|
|
private static $next_run_hour = 9;
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* The minutes past the hour (see above) at which to run these jobs.
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
*/
|
|
|
|
private static $next_run_minute = 0;
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* The number of days to skip between job runs (1 means run this job every day,
|
|
|
|
* 2 means run it every second day etc).
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*
|
|
|
|
* @config
|
|
|
|
*/
|
|
|
|
private static $next_run_in_days = 1;
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTitle()
|
|
|
|
{
|
|
|
|
return "Content Review Notification Job";
|
|
|
|
}
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getJobType()
|
|
|
|
{
|
|
|
|
$this->totalSteps = 1;
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
return QueuedJob::QUEUED;
|
|
|
|
}
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
public function process()
|
|
|
|
{
|
|
|
|
$this->queueNextRun();
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
$task = new ContentReviewEmails();
|
|
|
|
$task->run(new SS_HTTPRequest("GET", "/dev/tasks/ContentReviewEmails"));
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
$this->currentStep = 1;
|
|
|
|
$this->isComplete = true;
|
|
|
|
}
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
/**
|
|
|
|
* Queue up the next job to run.
|
|
|
|
*/
|
|
|
|
protected function queueNextRun()
|
|
|
|
{
|
|
|
|
$nextRun = new ContentReviewNotificationJob();
|
2015-07-31 06:07:18 +02:00
|
|
|
|
2015-11-02 00:27:42 +01:00
|
|
|
$nextRunTime = mktime(
|
2016-04-11 08:44:26 +02:00
|
|
|
Config::inst()->get(__CLASS__, 'next_run_hour'),
|
|
|
|
Config::inst()->get(__CLASS__, 'next_run_minute'),
|
2015-11-02 00:27:42 +01:00
|
|
|
0,
|
|
|
|
date("m"),
|
2016-04-11 08:44:26 +02:00
|
|
|
date("d") + Config::inst()->get(__CLASS__, 'next_run_in_days'),
|
2015-11-02 00:27:42 +01:00
|
|
|
date("Y")
|
|
|
|
);
|
|
|
|
|
|
|
|
singleton("QueuedJobService")->queueJob(
|
|
|
|
$nextRun,
|
|
|
|
date("Y-m-d H:i:s", $nextRunTime)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|