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