1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Default scheduled task handler.
|
5
|
*/
|
6
|
class RulesSchedulerDefaultTaskHandler implements RulesSchedulerTaskHandlerInterface {
|
7
|
|
8
|
/**
|
9
|
* The task array.
|
10
|
*
|
11
|
* @var array
|
12
|
*/
|
13
|
protected $task;
|
14
|
|
15
|
/**
|
16
|
* Constructs a repetitive task handler object.
|
17
|
*/
|
18
|
public function __construct(array $task) {
|
19
|
$this->task = $task;
|
20
|
}
|
21
|
|
22
|
/**
|
23
|
* Implements RulesSchedulerTaskHandlerInterface::runTask().
|
24
|
*/
|
25
|
public function runTask() {
|
26
|
if ($component = rules_get_cache('comp_' . $this->task['config'])) {
|
27
|
$replacements = array('%label' => $component->label(), '%plugin' => $component->plugin());
|
28
|
$replacements['%identifier'] = $this->task['identifier'] ? $this->task['identifier'] : t('without identifier');
|
29
|
rules_log('Scheduled evaluation of %plugin %label, task %identifier.', $replacements, RulesLog::INFO, $component, TRUE);
|
30
|
$state = unserialize($this->task['data']);
|
31
|
$state->restoreBlocks();
|
32
|
// Block the config to prevent any future recursion.
|
33
|
$state->block($component);
|
34
|
// Finally evaluate the component with the given state.
|
35
|
$component->evaluate($state);
|
36
|
$state->unblock($component);
|
37
|
rules_log('Finished evaluation of %plugin %label, task %identifier.', $replacements, RulesLog::INFO, $component, FALSE);
|
38
|
$state->cleanUp();
|
39
|
}
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* Implements RulesSchedulerTaskHandlerInterface::afterTaskQueued().
|
44
|
*/
|
45
|
public function afterTaskQueued() {
|
46
|
// Delete the task from the task list.
|
47
|
db_delete('rules_scheduler')
|
48
|
->condition('tid', $this->task['tid'])
|
49
|
->execute();
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Implements RulesSchedulerTaskHandlerInterface::getTask().
|
54
|
*/
|
55
|
public function getTask() {
|
56
|
return $this->task;
|
57
|
}
|
58
|
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* Interface for scheduled task handlers.
|
63
|
*
|
64
|
* Task handlers control the behavior of a task when it's queued or executed.
|
65
|
* Unless specified otherwise, the RulesSchedulerDefaultTaskHandler task handler
|
66
|
* is used.
|
67
|
*
|
68
|
* @see rules_scheduler_run_task()
|
69
|
* @see rules_scheduler_cron()
|
70
|
* @see RulesSchedulerDefaultTaskHandler
|
71
|
*/
|
72
|
interface RulesSchedulerTaskHandlerInterface {
|
73
|
|
74
|
/**
|
75
|
* Processes a queue item.
|
76
|
*
|
77
|
* @throws RulesEvaluationException
|
78
|
* If there are any problems executing the task.
|
79
|
*
|
80
|
* @see rules_scheduler_run_task()
|
81
|
*/
|
82
|
public function runTask();
|
83
|
|
84
|
/**
|
85
|
* Processes a task after it has been queued.
|
86
|
*
|
87
|
* @see rules_scheduler_cron()
|
88
|
*/
|
89
|
public function afterTaskQueued();
|
90
|
|
91
|
/**
|
92
|
* Returns the task associated with the task handler.
|
93
|
*
|
94
|
* @return array
|
95
|
* The task (queue item) array.
|
96
|
*/
|
97
|
public function getTask();
|
98
|
|
99
|
}
|