ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
11 abstract 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  return true;
39  }
40  if (!$this->hasFlexibleSchedule()) {
41  $a_schedule_type = $this->getDefaultScheduleType();
42  $a_schedule_value = $this->getDefaultScheduleValue();
43  }
44  return $this->checkSchedule($a_ts_last_run, $a_schedule_type, $a_schedule_value);
45  }
46 
52  public function getScheduleType()
53  {
54  if ($this->hasFlexibleSchedule() && $this->schedule_type) {
55  return $this->schedule_type;
56  }
57  }
58 
64  public function getScheduleValue()
65  {
66  if ($this->hasFlexibleSchedule() && $this->schedule_value) {
67  return $this->schedule_value;
68  }
69  }
70 
78  public function setSchedule($a_type, $a_value)
79  {
80  if ($this->hasFlexibleSchedule() &&
81  in_array($a_type, $this->getValidScheduleTypes()) &&
82  $a_value) {
83  $this->schedule_type = $a_type;
84  $this->schedule_value = $a_value;
85  }
86  }
87 
93  public function getValidScheduleTypes()
94  {
95  return array(self::SCHEDULE_TYPE_DAILY, self::SCHEDULE_TYPE_IN_MINUTES,
96  self::SCHEDULE_TYPE_IN_HOURS, self::SCHEDULE_TYPE_IN_DAYS,
97  self::SCHEDULE_TYPE_WEEKLY, self::SCHEDULE_TYPE_MONTHLY,
98  self::SCHEDULE_TYPE_QUARTERLY, self::SCHEDULE_TYPE_YEARLY);
99  }
100 
101  /*
102  * Check if next run is due
103  *
104  * @param timestamp $a_ts_last_run
105  * @param integer $a_schedule_type
106  * @param integer $a_schedule_value
107  * @return boolean
108  */
109  protected function checkSchedule($a_ts_last_run, $a_schedule_type, $a_schedule_value)
110  {
111  if (!$a_schedule_type) {
112  return false;
113  }
114  if (!$a_ts_last_run) {
115  return true;
116  }
117 
118  $now = time();
119 
120  switch ($a_schedule_type) {
121  case self::SCHEDULE_TYPE_DAILY:
122  $last = date("Y-m-d", $a_ts_last_run);
123  $ref = date("Y-m-d", $now);
124  return ($last != $ref);
125 
126  case self::SCHEDULE_TYPE_WEEKLY:
127  $last = date("Y-W", $a_ts_last_run);
128  $ref = date("Y-W", $now);
129  return ($last != $ref);
130 
131  case self::SCHEDULE_TYPE_MONTHLY:
132  $last = date("Y-n", $a_ts_last_run);
133  $ref = date("Y-n", $now);
134  return ($last != $ref);
135 
136  case self::SCHEDULE_TYPE_QUARTERLY:
137  $last = date("Y", $a_ts_last_run) . "-" . ceil(date("n", $a_ts_last_run)/3);
138  $ref = date("Y", $now) . "-" . ceil(date("n", $now)/3);
139  return ($last != $ref);
140 
141  case self::SCHEDULE_TYPE_YEARLY:
142  $last = date("Y", $a_ts_last_run);
143  $ref = date("Y", $now);
144  return ($last != $ref);
145 
146  case self::SCHEDULE_TYPE_IN_MINUTES:
147  $diff = floor(($now-$a_ts_last_run)/60);
148  return ($diff >= $a_schedule_value);
149 
150  case self::SCHEDULE_TYPE_IN_HOURS:
151  $diff = floor(($now-$a_ts_last_run)/(60*60));
152  return ($diff >= $a_schedule_value);
153 
154  case self::SCHEDULE_TYPE_IN_DAYS:
155  $diff = floor(($now-$a_ts_last_run)/(60*60*24));
156  return ($diff >= $a_schedule_value);
157  }
158  }
159 
160 
161  //
162  // TITLE / DESCRIPTION
163  //
164 
170  public function getTitle()
171  {
172  }
173 
179  public function getDescription()
180  {
181  }
182 
187  public function isManuallyExecutable()
188  {
189  return true;
190  }
191 
192  //
193  // SETTINGS
194  //
195 
201  public function hasCustomSettings()
202  {
203  return false;
204  }
205 
212  {
213  }
214 
221  public function saveCustomSettings(ilPropertyFormGUI $a_form)
222  {
223  return true;
224  }
225 
233  public function addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
234  {
235  }
236 
237 
238  //
239  // HOOKS
240  //
241 
247  public function activationWasToggled($a_currently_active)
248  {
249  // we cannot use ilObject or any higher level construct here
250  // this may be called from setup, so it is limited to handling ilSetting/ilDB mostly
251  }
252 
253 
254  //
255  // ABSTRACT
256  //
257 
263  abstract public function getId();
264 
270  abstract public function hasAutoActivation();
271 
277  abstract public function hasFlexibleSchedule();
278 
284  abstract public function getDefaultScheduleType();
285 
291  abstract public function getDefaultScheduleValue();
292 
298  abstract public function run();
299 }
setSchedule($a_type, $a_value)
Update current schedule (if flexible)
run()
Run job.
getValidScheduleTypes()
Get all available schedule types.
checkSchedule($a_ts_last_run, $a_schedule_type, $a_schedule_value)
This class represents a property form user interface.
addToExternalSettingsForm($a_form_id, array &$a_fields, $a_is_active)
Add external settings to form.
getId()
Get id.
Cron job application base class.
const SCHEDULE_TYPE_IN_MINUTES
getDescription()
Get description.
activationWasToggled($a_currently_active)
Cron job status was changed.
const SCHEDULE_TYPE_MONTHLY
const SCHEDULE_TYPE_WEEKLY
$a_type
Definition: workflow.php:92
getTitle()
Get title.
addCustomSettingsToForm(ilPropertyFormGUI $a_form)
Add custom settings to form.
hasFlexibleSchedule()
Can the schedule be configured?
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
isActive($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
Is job currently active?
const SCHEDULE_TYPE_IN_DAYS
hasCustomSettings()
Has cron job any custom setting which can be edited?
Create styles array
The data for the language used.
const SCHEDULE_TYPE_YEARLY
getDefaultScheduleType()
Get schedule type.
const SCHEDULE_TYPE_DAILY
getDefaultScheduleValue()
Get schedule value.
saveCustomSettings(ilPropertyFormGUI $a_form)
Save custom settings.
const SCHEDULE_TYPE_QUARTERLY
getScheduleValue()
Get current schedule value (if flexible)
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
const SCHEDULE_TYPE_IN_HOURS
hasAutoActivation()
Is to be activated on "installation".
isManuallyExecutable()
Defines whether or not a cron job can be started manually.
getScheduleType()
Get current schedule type (if flexible)