ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCronJob.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11abstract class ilCronJob
12{
21
22 //
23 // SCHEDULE
24 //
25
35 public function isActive($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual = false)
36 {
37 if($a_manual)
38 {
39 return true;
40 }
41 if(!$this->hasFlexibleSchedule())
42 {
43 $a_schedule_type = $this->getDefaultScheduleType();
44 $a_schedule_value = $this->getDefaultScheduleValue();
45 }
46 return $this->checkSchedule($a_ts_last_run, $a_schedule_type, $a_schedule_value);
47 }
48
54 public function getScheduleType()
55 {
56 if($this->hasFlexibleSchedule() && $this->schedule_type)
57 {
58 return $this->schedule_type;
59 }
60 }
61
67 public function getScheduleValue()
68 {
69 if($this->hasFlexibleSchedule() && $this->schedule_value)
70 {
71 return $this->schedule_value;
72 }
73 }
74
82 public function setSchedule($a_type, $a_value)
83 {
84 if($this->hasFlexibleSchedule() &&
85 in_array($a_type, $this->getValidScheduleTypes()) &&
86 $a_value)
87 {
88 $this->schedule_type = $a_type;
89 $this->schedule_value = $a_value;
90 }
91 }
92
98 public function getValidScheduleTypes()
99 {
100 return array(self::SCHEDULE_TYPE_DAILY, self::SCHEDULE_TYPE_IN_MINUTES,
101 self::SCHEDULE_TYPE_IN_HOURS, self::SCHEDULE_TYPE_IN_DAYS,
102 self::SCHEDULE_TYPE_WEEKLY, self::SCHEDULE_TYPE_MONTHLY,
103 self::SCHEDULE_TYPE_QUARTERLY, self::SCHEDULE_TYPE_YEARLY);
104 }
105
106 /*
107 * Check if next run is due
108 *
109 * @param timestamp $a_ts_last_run
110 * @param integer $a_schedule_type
111 * @param integer $a_schedule_value
112 * @return boolean
113 */
114 protected function checkSchedule($a_ts_last_run, $a_schedule_type, $a_schedule_value)
115 {
116 if(!$a_schedule_type)
117 {
118 return false;
119 }
120 if(!$a_ts_last_run)
121 {
122 return true;
123 }
124
125 $now = time();
126
127 switch($a_schedule_type)
128 {
130 $last = date("Y-m-d", $a_ts_last_run);
131 $ref = date("Y-m-d", $now);
132 return ($last != $ref);
133
135 $last = date("Y-W", $a_ts_last_run);
136 $ref = date("Y-W", $now);
137 return ($last != $ref);
138
140 $last = date("Y-n", $a_ts_last_run);
141 $ref = date("Y-n", $now);
142 return ($last != $ref);
143
145 $last = date("Y", $a_ts_last_run)."-".ceil(date("n", $a_ts_last_run)/3);
146 $ref = date("Y", $now)."-".ceil(date("n", $now)/3);
147 return ($last != $ref);
148
150 $last = date("Y", $a_ts_last_run);
151 $ref = date("Y", $now);
152 return ($last != $ref);
153
155 $diff = floor(($now-$a_ts_last_run)/60);
156 return ($diff >= $a_schedule_value);
157
159 $diff = floor(($now-$a_ts_last_run)/(60*60));
160 return ($diff >= $a_schedule_value);
161
163 $diff = floor(($now-$a_ts_last_run)/(60*60*24));
164 return ($diff >= $a_schedule_value);
165 }
166 }
167
168
169 //
170 // TITLE / DESCRIPTION
171 //
172
178 public function getTitle()
179 {
180
181 }
182
188 public function getDescription()
189 {
190
191 }
192
197 public function isManuallyExecutable()
198 {
199 return true;
200 }
201
202 //
203 // SETTINGS
204 //
205
211 public function hasCustomSettings()
212 {
213 return false;
214 }
215
222 {
223
224 }
225
232 public function saveCustomSettings(ilPropertyFormGUI $a_form)
233 {
234 return true;
235 }
236
244 public function addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
245 {
246
247 }
248
249
250 //
251 // HOOKS
252 //
253
259 public function activationWasToggled($a_currently_active)
260 {
261 // we cannot use ilObject or any higher level construct here
262 // this may be called from setup, so it is limited to handling ilSetting/ilDB mostly
263 }
264
265
266 //
267 // ABSTRACT
268 //
269
275 abstract public function getId();
276
282 abstract public function hasAutoActivation();
283
289 abstract public function hasFlexibleSchedule();
290
296 abstract public function getDefaultScheduleType();
297
303 abstract function getDefaultScheduleValue();
304
310 abstract public function run();
311}
312
313?>
Cron job application base class.
getScheduleType()
Get current schedule type (if flexible)
const SCHEDULE_TYPE_IN_DAYS
setSchedule($a_type, $a_value)
Update current schedule (if flexible)
getDefaultScheduleType()
Get schedule type.
getDescription()
Get description.
activationWasToggled($a_currently_active)
Cron job status was changed.
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
Add external settings to form.
run()
Run job.
const SCHEDULE_TYPE_IN_HOURS
getDefaultScheduleValue()
Get schedule value.
hasCustomSettings()
Has cron job any custom setting which can be edited?
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
Add custom settings to form.
saveCustomSettings(ilPropertyFormGUI $a_form)
Save custom settings.
checkSchedule($a_ts_last_run, $a_schedule_type, $a_schedule_value)
const SCHEDULE_TYPE_IN_MINUTES
isManuallyExecutable()
Defines whether or not a cron job can be started manually.
getScheduleValue()
Get current schedule value (if flexible)
getId()
Get id.
const SCHEDULE_TYPE_WEEKLY
const SCHEDULE_TYPE_YEARLY
isActive($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
Is job currently active?
hasAutoActivation()
Is to be activated on "installation".
const SCHEDULE_TYPE_DAILY
hasFlexibleSchedule()
Can the schedule be configured?
const SCHEDULE_TYPE_QUARTERLY
const SCHEDULE_TYPE_MONTHLY
getValidScheduleTypes()
Get all available schedule types.
getTitle()
Get title.
This class represents a property form user interface.