ILIAS  release_4-4 Revision
ilCronManager Class Reference

Cron management. More...

+ Collaboration diagram for ilCronManager:

Static Public Member Functions

static runActiveJobs ()
 Run all active jobs. More...
 
static runJobManual ($a_job_id)
 Run single job manually. More...
 
static getJobInstanceById ($a_job_id)
 Get job instance (by job id) More...
 
static getJobInstance ($a_id, $a_component, $a_class, $a_path=null)
 Get job instance (by job data) More...
 
static createDefaultEntry (ilCronJob $a_job, $a_component, $a_class, $a_path)
 
static updateFromXML ($a_component, $a_id, $a_class, $a_path=null)
 Process data from module.xml/service.xml. More...
 
static clearFromXML ($a_component, array $a_xml_job_ids)
 Clear job data. More...
 
static getPluginJobs ($a_only_active=false)
 
static getCronJobData ($a_id=null, $a_include_inactive=true)
 Get cron job configuration/execution data. More...
 
static resetJob (ilCronJob $a_job)
 Reset job. More...
 
static activateJob (ilCronJob $a_job, $a_manual=false)
 Activate cron job. More...
 
static deactivateJob (ilCronJob $a_job, $a_manual=false)
 Deactivate cron job. More...
 
static isJobActive ($a_job_id)
 Check if given job is currently active. More...
 
static isJobInactive ($a_job_id)
 Check if given job is currently inactive. More...
 
static updateJobSchedule (ilCronJob $a_job, $a_schedule_type, $a_schedule_value)
 Update job schedule. More...
 
static ping ($a_job_id)
 Keep cron job alive. More...
 

Static Protected Member Functions

static runJob (ilCronJob $a_job, array $a_job_data, $a_manual=false)
 Run single cron job (internal) More...
 
static sendNotification (ilCronJob $a_job, $a_message)
 Send notification to admin about job event(s) More...
 
static updateJobResult (ilCronJob $a_job, ilCronJobResult $a_result, $a_manual=false)
 Save job result. More...
 
static getMicrotime ()
 Get current microtime. More...
 

Detailed Description

Cron management.

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 11 of file class.ilCronManager.php.

Member Function Documentation

◆ activateJob()

static ilCronManager::activateJob ( ilCronJob  $a_job,
  $a_manual = false 
)
static

Activate cron job.

Parameters
ilCronJob$a_job
bool$a_manual

Definition at line 573 of file class.ilCronManager.php.

References $ilUser, ilCronJob\activationWasToggled(), and ilCronJob\getId().

Referenced by ilCronManagerGUI\confirmedActivate().

574  {
575  global $ilDB, $ilUser;
576 
577  $user_id = $a_manual ? $ilUser->getId() : 0;
578 
579  $sql = "UPDATE cron_job SET ".
580  " job_status = ".$ilDB->quote(1, "integer").
581  " , job_status_user_id = ".$ilDB->quote($user_id, "integer").
582  " , job_status_type = ".$ilDB->quote($a_manual, "integer").
583  " , job_status_ts = ".$ilDB->quote(time(), "integer").
584  " WHERE job_id = ".$ilDB->quote($a_job->getId(), "text");
585  $ilDB->manipulate($sql);
586 
587  $a_job->activationWasToggled(true);
588  }
getId()
Get id.
activationWasToggled($a_currently_active)
Cron job status was changed.
global $ilUser
Definition: imgupload.php:15
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clearFromXML()

static ilCronManager::clearFromXML (   $a_component,
array  $a_xml_job_ids 
)
static

Clear job data.

Parameters
string$a_component
array$a_xml_job_ids

Definition at line 413 of file class.ilCronManager.php.

References $ilLog, and $row.

Referenced by ilObjDefReader\handlerEndTag().

414  {
415  global $ilDB, $ilLog;
416 
417  if(!$ilDB->tableExists("cron_job"))
418  {
419  return;
420  }
421 
422  // gather existing jobs
423  $all_jobs = array();
424  $sql = "SELECT job_id FROM cron_job".
425  " WHERE component = ".$ilDB->quote($a_component, "text");
426  $set = $ilDB->query($sql);
427  while($row = $ilDB->fetchAssoc($set))
428  {
429  $all_jobs[] = $row["job_id"];
430  }
431 
432  if(sizeof($all_jobs))
433  {
434  if(sizeof($a_xml_job_ids))
435  {
436  // delete obsolete job data
437  foreach($all_jobs as $job_id)
438  {
439  if(!in_array($job_id, $a_xml_job_ids))
440  {
441  $ilDB->manipulate("DELETE FROM cron_job".
442  " WHERE component = ".$ilDB->quote($a_component, "text").
443  " AND job_id = ".$ilDB->quote($job_id, "text"));
444 
445  $ilLog->write("Cron XML - Job ".$job_id." in class ".$a_component.
446  " deleted.");
447  }
448  }
449  }
450  else
451  {
452  $ilDB->manipulate("DELETE FROM cron_job".
453  " WHERE component = ".$ilDB->quote($a_component, "text"));
454 
455  $ilLog->write("Cron XML - All jobs deleted for ".$a_component." as component is inactive.");
456  }
457  }
458  }
+ Here is the caller graph for this function:

◆ createDefaultEntry()

static ilCronManager::createDefaultEntry ( ilCronJob  $a_job,
  $a_component,
  $a_class,
  $a_path 
)
static

Definition at line 320 of file class.ilCronManager.php.

References $ilLog, $ilSetting, $row, ilCronJob\activationWasToggled(), ilCronJob\getDefaultScheduleType(), ilCronJob\getDefaultScheduleValue(), ilCronJob\getId(), ilCronJob\hasAutoActivation(), and ilCronJob\hasFlexibleSchedule().

Referenced by getJobInstanceById(), and getPluginJobs().

321  {
322  global $ilDB, $ilLog, $ilSetting;
323 
324  // already exists?
325  $sql = "SELECT job_id, schedule_type FROM cron_job".
326  " WHERE component = ".$ilDB->quote($a_component, "text").
327  " AND job_id = ".$ilDB->quote($a_job->getId(), "text");
328  $set = $ilDB->query($sql);
329  $row = $ilDB->fetchAssoc($set);
330  $job_exists = ($row["job_id"] == $a_job->getId());
331  $schedule_type = $row["schedule_type"];
332 
333  // new job
334  if(!$job_exists)
335  {
336  $sql = "INSERT INTO cron_job (job_id, component, class, path)".
337  " VALUES (".$ilDB->quote($a_job->getId(), "text").", ".
338  $ilDB->quote($a_component, "text").", ".
339  $ilDB->quote($a_class, "text").", ".
340  $ilDB->quote($a_path, "text").")";
341  $ilDB->manipulate($sql);
342 
343  $ilLog->write("Cron XML - Job ".$a_job->getId()." in class ".$a_class.
344  " added.");
345 
346  // only if flexible
347  self::updateJobSchedule($a_job,
348  $a_job->getDefaultScheduleType(),
349  $a_job->getDefaultScheduleValue());
350 
351  // #12221
352  if(!is_object($ilSetting))
353  {
354  include_once "Services/Administration/classes/class.ilSetting.php";
355  $ilSetting = new ilSetting();
356  }
357 
358  if($a_job->hasAutoActivation())
359  {
360  self::activateJob($a_job);
361  }
362  else
363  {
364  // to overwrite dependent settings
365  $a_job->activationWasToggled(false);
366  }
367  }
368  // existing job - but schedule is flexible now
369  else if($a_job->hasFlexibleSchedule() && !$schedule_type)
370  {
371  self::updateJobSchedule($a_job,
372  $a_job->getDefaultScheduleType(),
373  $a_job->getDefaultScheduleValue());
374  }
375  // existing job - but schedule is static now
376  else if(!$a_job->hasFlexibleSchedule() && $schedule_type)
377  {
378  self::updateJobSchedule($a_job, null, null);
379  }
380  }
ILIAS Setting Class.
getId()
Get id.
activationWasToggled($a_currently_active)
Cron job status was changed.
hasFlexibleSchedule()
Can the schedule be configured?
getDefaultScheduleType()
Get schedule type.
global $ilSetting
Definition: privfeed.php:40
getDefaultScheduleValue()
Get schedule value.
hasAutoActivation()
Is to be activated on "installation".
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deactivateJob()

static ilCronManager::deactivateJob ( ilCronJob  $a_job,
  $a_manual = false 
)
static

Deactivate cron job.

Parameters
ilCronJob$a_job
bool$a_manual

Definition at line 596 of file class.ilCronManager.php.

References $ilUser, ilCronJob\activationWasToggled(), and ilCronJob\getId().

Referenced by ilCronManagerGUI\confirmedDeactivate().

597  {
598  global $ilDB, $ilUser;
599 
600  $user_id = $a_manual ? $ilUser->getId() : 0;
601 
602  $sql = "UPDATE cron_job SET ".
603  " job_status = ".$ilDB->quote(0, "integer").
604  " , job_status_user_id = ".$ilDB->quote($user_id, "integer").
605  " , job_status_type = ".$ilDB->quote($a_manual, "integer").
606  " , job_status_ts = ".$ilDB->quote(time(), "integer").
607  " WHERE job_id = ".$ilDB->quote($a_job->getId(), "text");
608  $ilDB->manipulate($sql);
609 
610  $a_job->activationWasToggled(false);
611  }
getId()
Get id.
activationWasToggled($a_currently_active)
Cron job status was changed.
global $ilUser
Definition: imgupload.php:15
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getCronJobData()

static ilCronManager::getCronJobData (   $a_id = null,
  $a_include_inactive = true 
)
static

Get cron job configuration/execution data.

Parameters
array | string$a_id
array$a_include_inactive
Returns
array

Definition at line 499 of file class.ilCronManager.php.

References $res, $row, and IL_COMP_PLUGIN.

Referenced by ilCronManagerGUI\addToExternalSettingsForm(), ilCronManagerTableGUI\getItems(), getJobInstanceById(), getPluginJobs(), and ilCronManagerGUI\initEditForm().

500  {
501  global $ilDB;
502 
503  $res = array();
504 
505  if($a_id && !is_array($a_id))
506  {
507  $a_id = array($a_id);
508  }
509 
510  $sql = "SELECT * FROM cron_job";
511 
512  $where = array();
513  if($a_id)
514  {
515  $where[] = $ilDB->in("job_id", $a_id, "", "text");
516  }
517  else
518  {
519  $where[] = "class <> ".$ilDB->quote(IL_COMP_PLUGIN, "text");
520  }
521  if(!$a_include_inactive)
522  {
523  $where[] = "job_status = ".$ilDB->quote(1, "integer");
524  }
525  if(sizeof($where))
526  {
527  $sql .= " WHERE ".implode(" AND ", $where);
528  }
529 
530  // :TODO: discuss job execution order
531  $sql .= " ORDER BY job_id";
532 
533  $set = $ilDB->query($sql);
534  while($row = $ilDB->fetchAssoc($set))
535  {
536  $res[] = $row;
537  }
538 
539  return $res;
540  }
const IL_COMP_PLUGIN
+ Here is the caller graph for this function:

◆ getJobInstance()

static ilCronManager::getJobInstance (   $a_id,
  $a_component,
  $a_class,
  $a_path = null 
)
static

Get job instance (by job data)

Parameters
string$a_component
string$a_class
string$a_path
Returns
ilCronJob

Definition at line 264 of file class.ilCronManager.php.

References $ilLog.

Referenced by ilCronManagerGUI\addToExternalSettingsForm(), and ilCronManagerTableGUI\getItems().

265  {
266  global $ilLog;
267 
268  if(!$a_path)
269  {
270  $a_path = $a_component."/classes/";
271  }
272  $class_file = $a_path."class.".$a_class.".php";
273  if(file_exists($class_file))
274  {
275  include_once $class_file;
276  if(class_exists($a_class))
277  {
278  $job = new $a_class();
279  if($job instanceof ilCronJob)
280  {
281  if($job->getId() == $a_id)
282  {
283  return $job;
284  }
285  else
286  {
287  $mess .= " - job id mismatch";
288  }
289  }
290  else
291  {
292  $mess .= " - does not extend ilCronJob";
293  }
294  }
295  else
296  {
297  $mess = "- class not found in file";
298  }
299  }
300  else
301  {
302  $mess = " - class file not found";
303  }
304 
305  $ilLog->write("Cron XML - Job ".$a_id." in class ".$a_class." (".
306  $class_file.") is invalid.".$mess);
307  }
Cron job application base class.
+ Here is the caller graph for this function:

◆ getJobInstanceById()

static ilCronManager::getJobInstanceById (   $a_job_id)
static

Get job instance (by job id)

Parameters
string$a_job_id
Returns
ilCronJob

Definition at line 213 of file class.ilCronManager.php.

References $ilLog, createDefaultEntry(), getCronJobData(), IL_COMP_PLUGIN, and IL_COMP_SERVICE.

Referenced by ilCronManagerGUI\confirmedReset(), ilCronManagerGUI\getMultiActionData(), ilCronManagerGUI\initEditForm(), and ilCronManagerGUI\update().

214  {
215  global $ilLog, $ilPluginAdmin;
216 
217  // plugin
218  if(substr($a_job_id, 0, 4) == "pl__")
219  {
220  $parts = explode("__", $a_job_id);
221  $pl_name = $parts[1];
222  $job_id = $parts[2];
223  if($ilPluginAdmin->isActive(IL_COMP_SERVICE, "Cron", "crnhk", $pl_name))
224  {
225  $plugin_obj = $ilPluginAdmin->getPluginObject(IL_COMP_SERVICE,
226  "Cron", "crnhk", $pl_name);
227  $job = $plugin_obj->getCronJobInstance($job_id);
228  if($job instanceof ilCronJob)
229  {
230  // should never happen but who knows...
231  if(!sizeof(ilCronManager::getCronJobData($job_id)))
232  {
233  // as job is not "imported" from xml
235  }
236  return $job;
237  }
238  }
239 
240  return null;
241  }
242  // system
243  else
244  {
245  $job_data = array_pop(self::getCronJobData($a_job_id));
246  if($job_data["job_id"] == $a_job_id)
247  {
248  return self::getJobInstance($job_data["job_id"], $job_data["component"],
249  $job_data["class"], $job_data["path"]);
250  }
251  }
252 
253  $ilLog->write("CRON - job ".$a_job_id." seems invalid or is inactive");
254  }
Cron job application base class.
const IL_COMP_PLUGIN
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
static createDefaultEntry(ilCronJob $a_job, $a_component, $a_class, $a_path)
const IL_COMP_SERVICE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getMicrotime()

static ilCronManager::getMicrotime ( )
staticprotected

Get current microtime.

Returns
float

Definition at line 698 of file class.ilCronManager.php.

699  {
700  list($usec, $sec) = explode(" ", microtime());
701  return ((float)$usec + (float)$sec);
702  }

◆ getPluginJobs()

static ilCronManager::getPluginJobs (   $a_only_active = false)
static

Definition at line 460 of file class.ilCronManager.php.

References $res, createDefaultEntry(), getCronJobData(), IL_COMP_PLUGIN, and IL_COMP_SERVICE.

Referenced by ilCronManagerTableGUI\getItems().

461  {
462  global $ilPluginAdmin;
463 
464  $res = array();
465 
466  foreach($ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Cron", "crnhk") as $pl_name)
467  {
468  $plugin_obj = $ilPluginAdmin->getPluginObject(IL_COMP_SERVICE, "Cron", "crnhk", $pl_name);
469 
470  foreach((array)$plugin_obj->getCronJobInstances() as $job)
471  {
472  $item = array_pop(ilCronManager::getCronJobData($job->getId()));
473  if(!sizeof($item))
474  {
475  // as job is not "imported" from xml
477  }
478 
479  $item = array_pop(ilCronManager::getCronJobData($job->getId()));
480  }
481 
482  if(!$a_only_active ||
483  $item["job_status"] == 1)
484  {
485  $res[$job->getId()] = array($job, $item);
486  }
487  }
488 
489  return $res;
490  }
const IL_COMP_PLUGIN
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
static createDefaultEntry(ilCronJob $a_job, $a_component, $a_class, $a_path)
const IL_COMP_SERVICE
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isJobActive()

static ilCronManager::isJobActive (   $a_job_id)
static

Check if given job is currently active.

Parameters
string$a_job_id
Returns
boolean

Definition at line 619 of file class.ilCronManager.php.

Referenced by ilCronManagerGUI\confirmedDeactivate(), ilObjForumAdministrationGUI\editSettings(), ilObjForumAdministrationGUI\getSettingsForm(), and ilObjContentObjectGUI\linkChecker().

620  {
621  $job = self::getCronJobData($a_job_id);
622  if((bool)$job[0]["job_status"])
623  {
624  return true;
625  }
626  return false;
627  }
+ Here is the caller graph for this function:

◆ isJobInactive()

static ilCronManager::isJobInactive (   $a_job_id)
static

Check if given job is currently inactive.

Parameters
string$a_job_id
Returns
boolean

Definition at line 635 of file class.ilCronManager.php.

Referenced by ilCronManagerGUI\confirmedActivate().

636  {
637  $job = self::getCronJobData($a_job_id);
638  if(!(bool)$job[0]["job_status"])
639  {
640  return true;
641  }
642  return false;
643  }
+ Here is the caller graph for this function:

◆ ping()

static ilCronManager::ping (   $a_job_id)
static

Keep cron job alive.

Parameters
string$a_job_id

Definition at line 709 of file class.ilCronManager.php.

710  {
711  global $ilDB;
712 
713  $ilDB->manipulate("UPDATE cron_job SET ".
714  " alive_ts = ".$ilDB->quote(time(), "integer").
715  " WHERE job_id = ".$ilDB->quote($a_job_id, "text"));
716  }

◆ resetJob()

static ilCronManager::resetJob ( ilCronJob  $a_job)
static

Reset job.

Parameters
ilCronJob$a_job

Definition at line 547 of file class.ilCronManager.php.

References $result, ilCronJob\getId(), and ilCronJobResult\STATUS_RESET.

Referenced by ilCronManagerGUI\confirmedActivate(), and ilCronManagerGUI\confirmedReset().

548  {
549  global $ilDB;
550 
551  include_once "Services/Cron/classes/class.ilCronJobResult.php";
552  $result = new ilCronJobResult();
554  $result->setCode("job_manual_reset");
555  $result->setMessage("Cron job re-activated by admin");
556  self::updateJobResult($a_job, $result, true);
557 
558  $ilDB->manipulate("UPDATE cron_job".
559  " SET running_ts = ".$ilDB->quote(0, "integer").
560  " , alive_ts = ".$ilDB->quote(0, "integer").
561  " , job_result_ts = ".$ilDB->quote(0, "integer").
562  " WHERE job_id = ".$ilDB->quote($a_job->getId(), "text"));
563 
564  self::activateJob($a_job, true);
565  }
$result
getId()
Get id.
Cron job result data container.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runActiveJobs()

static ilCronManager::runActiveJobs ( )
static

Run all active jobs.

Definition at line 16 of file class.ilCronManager.php.

References $ilLog, $ilSetting, $row, and ilUtil\_getHttpPath().

17  {
18  global $ilLog, $ilSetting;
19 
20  // separate log for cron
21  // $this->log->setFilename($_COOKIE["ilClientId"]."_cron.txt");
22 
23  $ilLog->write("CRON - batch start");
24 
25  $ilSetting->set("last_cronjob_start_ts", time());
26 
27  // ilLink::_getStaticLink() should work in crons
28  if(!defined("ILIAS_HTTP_PATH"))
29  {
30  define("ILIAS_HTTP_PATH", ilUtil::_getHttpPath());
31  }
32 
33  // system
34  foreach(self::getCronJobData(null, false) as $row)
35  {
36  $job = self::getJobInstanceById($row["job_id"]);
37  if($job)
38  {
39  self::runJob($job, $row);
40  }
41  }
42 
43  // plugins
44  foreach(self::getPluginJobs(true) as $item)
45  {
46  self::runJob($item[0], $item[1]);
47  }
48 
49  $ilLog->write("CRON - batch end");
50  }
static _getHttpPath()
global $ilSetting
Definition: privfeed.php:40
+ Here is the call graph for this function:

◆ runJob()

static ilCronManager::runJob ( ilCronJob  $a_job,
array  $a_job_data,
  $a_manual = false 
)
staticprotected

Run single cron job (internal)

Parameters
ilCronJob$a_job
array$a_job_data
bool$a_manual
Returns
boolean

Definition at line 97 of file class.ilCronManager.php.

References $ilLog, $result, ilCronJob\isActive(), ilCronJob\run(), ilCronJobResult\STATUS_CRASHED, and ilCronJobResult\STATUS_INVALID_CONFIGURATION.

98  {
99  global $ilLog, $ilDB;
100 
101  $did_run = false;
102 
103  if($a_job)
104  {
105  include_once "Services/Cron/classes/class.ilCronJobResult.php";
106 
107  // already running?
108  if($a_job_data["alive_ts"])
109  {
110  $ilLog->write("CRON - job ".$a_job_data["job_id"]." still running");
111 
112  $cut = 60*60*3; // 3h
113 
114  // is running (and has not pinged) for 3 hours straight, we assume it crashed
115  if(time()-$a_job_data["alive_ts"] > $cut)
116  {
117  $ilDB->manipulate("UPDATE cron_job SET".
118  " running_ts = ".$ilDB->quote(0, "integer").
119  " , alive_ts = ".$ilDB->quote(0, "integer").
120  " WHERE job_id = ".$ilDB->quote($a_job_data["job_id"], "text"));
121 
122  self::deactivateJob($a_job); // #13082
123 
124  $result = new ilCronJobResult();
126  $result->setCode("job_auto_deactivation_time_limit");
127  $result->setMessage("Cron job deactivated because it has been inactive for 3 hours");
128 
129  if(!$a_manual)
130  {
131  self::sendNotification($a_job, $result);
132  }
133 
134  self::updateJobResult($a_job, $result, $a_manual);
135 
136  $ilLog->write("CRON - job ".$a_job_data["job_id"]." deactivated (assumed crash)");
137  }
138  }
139  // initiate run?
140  else if($a_job->isActive($a_job_data["job_result_ts"],
141  $a_job_data["schedule_type"], $a_job_data["schedule_value"], $a_manual))
142  {
143  $ilLog->write("CRON - job ".$a_job_data["job_id"]." started");
144 
145  $ilDB->manipulate("UPDATE cron_job SET".
146  " running_ts = ".$ilDB->quote(time(), "integer").
147  " , alive_ts = ".$ilDB->quote(time(), "integer").
148  " WHERE job_id = ".$ilDB->quote($a_job_data["job_id"], "text"));
149 
150  $ts_in = self::getMicrotime();
151  $result = $a_job->run();
152  $ts_dur = self::getMicrotime()-$ts_in;
153 
154  // no proper result
155  if(!$result instanceof ilCronJobResult)
156  {
157  $result = new ilCronJobResult();
159  $result->setCode("job_no_result");
160  $result->setMessage("Cron job did not return a proper result");
161 
162  if(!$a_manual)
163  {
164  self::sendNotification($a_job, $result);
165  }
166 
167  $ilLog->write("CRON - job ".$a_job_data["job_id"]." no result");
168  }
169  // no valid configuration, job won't work
171  {
172  self::deactivateJob($a_job);
173 
174  if(!$a_manual)
175  {
176  self::sendNotification($a_job, $result);
177  }
178 
179  $ilLog->write("CRON - job ".$a_job_data["job_id"]." invalid configuration");
180  }
181  // success!
182  else
183  {
184  $did_run = true;
185  }
186 
187  $result->setDuration($ts_dur);
188 
189  self::updateJobResult($a_job, $result, $a_manual);
190 
191  $ilDB->manipulate("UPDATE cron_job SET".
192  " running_ts = ".$ilDB->quote(0, "integer").
193  " , alive_ts = ".$ilDB->quote(0, "integer").
194  " WHERE job_id = ".$ilDB->quote($a_job_data["job_id"], "text"));
195 
196  $ilLog->write("CRON - job ".$a_job_data["job_id"]." finished");
197  }
198  else
199  {
200  $ilLog->write("CRON - job ".$a_job_data["job_id"]." returned status inactive");
201  }
202  }
203 
204  return $did_run;
205  }
run()
Run job.
$result
isActive($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
Is job currently active?
Cron job result data container.
+ Here is the call graph for this function:

◆ runJobManual()

static ilCronManager::runJobManual (   $a_job_id)
static

Run single job manually.

Parameters
string$a_job_id
Returns
bool

Definition at line 58 of file class.ilCronManager.php.

References $ilLog, and $result.

Referenced by ilCronManagerGUI\confirmedRun().

59  {
60  global $ilLog;
61 
62  $result = false;
63 
64  $ilLog->write("CRON - manual start (".$a_job_id.")");
65 
66  $job = self::getJobInstanceById($a_job_id);
67  if($job)
68  {
69  if($job->isManuallyExecutable())
70  {
71  $job_data = array_pop(self::getCronJobData($job->getId()));
72  $result = self::runJob($job, $job_data, true);
73  }
74  else
75  {
76  $ilLog->write("CRON - job ".$a_job_id." is not intended to be executed manually");
77  }
78  }
79  else
80  {
81  $ilLog->write("CRON - job ".$a_job_id." seems invalid or is inactive");
82  }
83 
84  $ilLog->write("CRON - manual end (".$a_job_id.")");
85 
86  return $result;
87  }
$result
+ Here is the caller graph for this function:

◆ sendNotification()

static ilCronManager::sendNotification ( ilCronJob  $a_job,
  $a_message 
)
staticprotected

Send notification to admin about job event(s)

Parameters
ilCronJob$a_job
string$a_message

Definition at line 315 of file class.ilCronManager.php.

316  {
317  // :TODO:
318  }

◆ updateFromXML()

static ilCronManager::updateFromXML (   $a_component,
  $a_id,
  $a_class,
  $a_path = null 
)
static

Process data from module.xml/service.xml.

Parameters
string$a_component
string$a_id
string$a_class
string$_path

Definition at line 390 of file class.ilCronManager.php.

Referenced by ilObjDefReader\handlerBeginTag().

391  {
392  global $ilDB;
393 
394  if(!$ilDB->tableExists("cron_job"))
395  {
396  return;
397  }
398 
399  // only if job seems valid
400  $job = self::getJobInstance($a_id, $a_component, $a_class, $a_path);
401  if($job)
402  {
403  self::createDefaultEntry($job, $a_component, $a_class, $a_path);
404  }
405  }
+ Here is the caller graph for this function:

◆ updateJobResult()

static ilCronManager::updateJobResult ( ilCronJob  $a_job,
ilCronJobResult  $a_result,
  $a_manual = false 
)
staticprotected

Save job result.

Parameters
ilCronJob$a_job
ilCronJobResult$a_result
bool$a_manual

Definition at line 652 of file class.ilCronManager.php.

References $ilUser, ilCronJobResult\getCode(), ilCronJobResult\getDuration(), ilCronJob\getId(), ilCronJobResult\getMessage(), and ilCronJobResult\getStatus().

653  {
654  global $ilDB, $ilUser;
655 
656  $user_id = $a_manual ? $ilUser->getId() : 0;
657 
658  $sql = "UPDATE cron_job SET ".
659  " job_result_status = ".$ilDB->quote($a_result->getStatus(), "integer").
660  " , job_result_user_id = ".$ilDB->quote($user_id, "integer").
661  " , job_result_code = ".$ilDB->quote($a_result->getCode(), "text").
662  " , job_result_message = ".$ilDB->quote($a_result->getMessage(), "text").
663  " , job_result_type = ".$ilDB->quote($a_manual, "integer").
664  " , job_result_ts = ".$ilDB->quote(time(), "integer").
665  " , job_result_dur = ".$ilDB->quote($a_result->getDuration()*1000, "integer").
666  " WHERE job_id = ".$ilDB->quote($a_job->getId(), "text");
667  $ilDB->manipulate($sql);
668  }
getId()
Get id.
global $ilUser
Definition: imgupload.php:15
+ Here is the call graph for this function:

◆ updateJobSchedule()

static ilCronManager::updateJobSchedule ( ilCronJob  $a_job,
  $a_schedule_type,
  $a_schedule_value 
)
static

Update job schedule.

Parameters
ilCronJob$a_job
int$a_schedule_type
int$a_schedule_value

Definition at line 677 of file class.ilCronManager.php.

References ilCronJob\getId(), ilCronJob\getValidScheduleTypes(), and ilCronJob\hasFlexibleSchedule().

Referenced by ilCronManagerTableGUI\parseJobToData(), and ilCronManagerGUI\update().

678  {
679  global $ilDB;
680 
681  if($a_schedule_type === null ||
682  ($a_job->hasFlexibleSchedule() &&
683  in_array($a_schedule_type, $a_job->getValidScheduleTypes())))
684  {
685  $sql = "UPDATE cron_job SET ".
686  " schedule_type = ".$ilDB->quote($a_schedule_type, "integer").
687  " , schedule_value = ".$ilDB->quote($a_schedule_value, "integer").
688  " WHERE job_id = ".$ilDB->quote($a_job->getId(), "text");
689  $ilDB->manipulate($sql);
690  }
691  }
getValidScheduleTypes()
Get all available schedule types.
getId()
Get id.
hasFlexibleSchedule()
Can the schedule be configured?
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: