ILIAS  release_7 Revision v7.30-3-g800a261c036
ilCronManager Class Reference

Cron management. More...

+ Inheritance diagram for ilCronManager:
+ Collaboration diagram for ilCronManager:

Public Member Functions

 __construct (\ilSetting $settings, \ilLogger $logger)
 ilCronManager constructor. More...
 
 runActiveJobs ()
 Run all active jobs. More...
 
 runActiveJobs ()
 Run all active jobs. More...
 

Static Public Member Functions

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=null, $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...
 

Protected Attributes

 $settings
 
 $logger
 

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 10 of file class.ilCronManager.php.

Constructor & Destructor Documentation

◆ __construct()

ilCronManager::__construct ( \ilSetting  $settings,
\ilLogger  $logger 
)

ilCronManager constructor.

Parameters
\ilSetting$settings
\ilLogger$logger

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

28 {
29 $this->settings = $settings;
30 $this->logger = $logger;
31 }
settings()
Definition: settings.php:2

References $logger, $settings, and settings().

+ Here is the call graph for this function:

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 619 of file class.ilCronManager.php.

620 {
621 global $DIC;
622 $ilDB = $DIC->database();
623
624 $user_id = 0;
625 if ($DIC->isDependencyAvailable('user')) {
626 $user = $DIC->user();
627 $user_id = $a_manual ? $user->getId() : 0;
628 }
629
630 $sql = "UPDATE cron_job SET " .
631 " job_status = " . $ilDB->quote(1, "integer") .
632 " , job_status_user_id = " . $ilDB->quote($user_id, "integer") .
633 " , job_status_type = " . $ilDB->quote($a_manual, "integer") .
634 " , job_status_ts = " . $ilDB->quote(time(), "integer") .
635 " WHERE job_id = " . $ilDB->quote($a_job->getId(), "text");
636 $ilDB->manipulate($sql);
637
638 $a_job->activationWasToggled(true);
639 }
activationWasToggled($a_currently_active)
Cron job status was changed.
getId()
Get id.
global $DIC
Definition: goto.php:24
global $ilDB

References $DIC, $ilDB, ilCronJob\activationWasToggled(), and ilCronJob\getId().

Referenced by ilCronManagerGUI\confirmedActivate(), createDefaultEntry(), and resetJob().

+ 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 468 of file class.ilCronManager.php.

469 {
470 global $DIC;
471
472 $ilDB = $DIC->database();
473 $ilLog = $DIC->logger()->root();
474
475 if (!$ilDB->tableExists("cron_job")) {
476 return;
477 }
478
479 // gather existing jobs
480 $all_jobs = array();
481 $sql = "SELECT job_id FROM cron_job" .
482 " WHERE component = " . $ilDB->quote($a_component, "text");
483 $set = $ilDB->query($sql);
484 while ($row = $ilDB->fetchAssoc($set)) {
485 $all_jobs[] = $row["job_id"];
486 }
487
488 if (sizeof($all_jobs)) {
489 if (sizeof($a_xml_job_ids)) {
490 // delete obsolete job data
491 foreach ($all_jobs as $job_id) {
492 if (!in_array($job_id, $a_xml_job_ids)) {
493 $ilDB->manipulate("DELETE FROM cron_job" .
494 " WHERE component = " . $ilDB->quote($a_component, "text") .
495 " AND job_id = " . $ilDB->quote($job_id, "text"));
496
497 $ilLog->write("Cron XML - Job " . $job_id . " in class " . $a_component .
498 " deleted.");
499 }
500 }
501 } else {
502 $ilDB->manipulate("DELETE FROM cron_job" .
503 " WHERE component = " . $ilDB->quote($a_component, "text"));
504
505 $ilLog->write("Cron XML - All jobs deleted for " . $a_component . " as component is inactive.");
506 }
507 }
508 }

References $DIC, and $ilDB.

Referenced by ilObjDefReader\handlerEndTag().

+ 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 355 of file class.ilCronManager.php.

356 {
357 global $DIC;
358
359 $ilLog = $DIC->logger()->root();
360 $ilDB = $DIC->database();
361
362 if (!isset($DIC["ilSetting"])) {
363 $DIC["ilSetting"] = function ($c) {
364 return new ilSetting();
365 };
366 }
367
368 $ilSetting = $DIC->settings();
369
370 // already exists?
371 $sql = "SELECT job_id, schedule_type, component, class, path FROM cron_job" .
372 " WHERE job_id = " . $ilDB->quote($a_job->getId(), "text");
373 $set = $ilDB->query($sql);
374 $row = $ilDB->fetchAssoc($set);
375 $job_id = $row['job_id'] ?? null;
376 $job_exists = ($job_id == $a_job->getId());
377 $schedule_type = $row["schedule_type"] ?? null;
378
379 if ($job_exists && (
380 $row['component'] != $a_component ||
381 $row['class'] != $a_class ||
382 $row['path'] != $a_path
383 )) {
384 $ilDB->manipulateF(
385 'UPDATE cron_job SET component = %s, class = %s, path = %s WHERE job_id = %s',
386 ['text', 'text', 'text', 'text'],
387 [$a_component, $a_class, $a_path, $a_job->getId()]
388 );
389 }
390
391 // new job
392 if (!$job_exists) {
393 $sql = "INSERT INTO cron_job (job_id, component, class, path)" .
394 " VALUES (" . $ilDB->quote($a_job->getId(), "text") . ", " .
395 $ilDB->quote($a_component, "text") . ", " .
396 $ilDB->quote($a_class, "text") . ", " .
397 $ilDB->quote($a_path, "text") . ")";
398 $ilDB->manipulate($sql);
399
400 $ilLog->write("Cron XML - Job " . $a_job->getId() . " in class " . $a_class .
401 " added.");
402
403 // only if flexible
405 $a_job,
406 $a_job->getDefaultScheduleType(),
408 );
409
410 // #12221
411 if (!is_object($ilSetting)) {
412 include_once "Services/Administration/classes/class.ilSetting.php";
413 $ilSetting = new ilSetting();
414 }
415
416 if ($a_job->hasAutoActivation()) {
417 self::activateJob($a_job);
418 } else {
419 // to overwrite dependent settings
420 $a_job->activationWasToggled(false);
421 }
422 }
423 // existing job - but schedule is flexible now
424 elseif ($a_job->hasFlexibleSchedule() && !$schedule_type) {
426 $a_job,
427 $a_job->getDefaultScheduleType(),
429 );
430 }
431 // existing job - but schedule is static now
432 elseif (!$a_job->hasFlexibleSchedule() && $schedule_type) {
433 self::updateJobSchedule($a_job, null, null);
434 }
435 }
getDefaultScheduleType()
Get schedule type.
getDefaultScheduleValue()
Get schedule value.
hasAutoActivation()
Is to be activated on "installation".
hasFlexibleSchedule()
Can the schedule be configured?
static activateJob(ilCronJob $a_job, $a_manual=false)
Activate cron job.
static updateJobSchedule(ilCronJob $a_job, $a_schedule_type, $a_schedule_value)
Update job schedule.
ILIAS Setting Class.
$c
Definition: cli.php:37
global $ilSetting
Definition: privfeed.php:17

References $c, $DIC, $ilDB, $ilSetting, activateJob(), ilCronJob\activationWasToggled(), ilCronJob\getDefaultScheduleType(), ilCronJob\getDefaultScheduleValue(), ilCronJob\getId(), ilCronJob\hasAutoActivation(), ilCronJob\hasFlexibleSchedule(), and updateJobSchedule().

Referenced by getJobInstanceById(), getPluginJobs(), and updateFromXML().

+ 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 647 of file class.ilCronManager.php.

648 {
649 global $DIC;
650 $ilDB = $DIC->database();
651 $ilUser = $DIC->user();
652
653 $user_id = $a_manual ? $ilUser->getId() : 0;
654
655 $sql = "UPDATE cron_job SET " .
656 " job_status = " . $ilDB->quote(0, "integer") .
657 " , job_status_user_id = " . $ilDB->quote($user_id, "integer") .
658 " , job_status_type = " . $ilDB->quote($a_manual, "integer") .
659 " , job_status_ts = " . $ilDB->quote(time(), "integer") .
660 " WHERE job_id = " . $ilDB->quote($a_job->getId(), "text");
661 $ilDB->manipulate($sql);
662
663 $a_job->activationWasToggled(false);
664 }
$ilUser
Definition: imgupload.php:18

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

Referenced by ilCronManagerGUI\confirmedDeactivate(), and runJob().

+ 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 550 of file class.ilCronManager.php.

551 {
552 global $DIC;
553 $ilDB = $DIC->database();
554
555 $res = array();
556
557 if ($a_id && !is_array($a_id)) {
558 $a_id = array($a_id);
559 }
560
561 $sql = "SELECT * FROM cron_job";
562
563 $where = array();
564 if ($a_id) {
565 $where[] = $ilDB->in("job_id", $a_id, "", "text");
566 } else {
567 $where[] = "class <> " . $ilDB->quote(IL_COMP_PLUGIN, "text");
568 }
569 if (!$a_include_inactive) {
570 $where[] = "job_status = " . $ilDB->quote(1, "integer");
571 }
572 if (sizeof($where)) {
573 $sql .= " WHERE " . implode(" AND ", $where);
574 }
575
576 // :TODO: discuss job execution order
577 $sql .= " ORDER BY job_id";
578
579 $set = $ilDB->query($sql);
580 while ($row = $ilDB->fetchAssoc($set)) {
581 $res[] = $row;
582 }
583
584 return $res;
585 }
const IL_COMP_PLUGIN
foreach($_POST as $key=> $value) $res

References $DIC, $ilDB, $res, and IL_COMP_PLUGIN.

Referenced by ilCronManagerGUI\addToExternalSettingsForm(), ilCronDeleteInactiveUserAccounts\calculateDeletionData(), ilCronJobRepositoryImpl\findAll(), getJobInstanceById(), getPluginJobs(), ilCronManagerGUI\initEditForm(), isJobActive(), isJobInactive(), ilLTICronOutcomeService\run(), and runJob().

+ 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 305 of file class.ilCronManager.php.

306 {
307 global $DIC;
308
309 $ilLog = $DIC->logger()->root();
310
311 if (!$a_path) {
312 $a_path = $a_component . "/classes/";
313 }
314 $class_file = $a_path . "class." . $a_class . ".php";
315 if (file_exists($class_file)) {
316 include_once $class_file;
317 if (class_exists($a_class)) {
318 $refl = new \ReflectionClass($a_class);
319 $job = $refl->newInstanceWithoutConstructor();
320 if ($refl->isSubclassOf(\ilCronJob::class)) {
321 if (0 === strlen($job->getId()) || !isset($_SERVER['PHP_SELF']) || basename($_SERVER['PHP_SELF']) !== 'setup.php') {
322 $job = new $a_class;
323 }
324
325 if ($job->getId() === $a_id) {
326 return $job;
327 } else {
328 $mess .= " - job id mismatch";
329 }
330 } else {
331 $mess .= " - does not extend ilCronJob";
332 }
333 } else {
334 $mess = "- class not found in file";
335 }
336 } else {
337 $mess = " - class file not found";
338 }
339
340 $ilLog->write("Cron XML - Job " . $a_id . " in class " . $a_class . " (" .
341 $class_file . ") is invalid." . $mess);
342 }
$_SERVER['HTTP_HOST']
Definition: raiseError.php:10

References $_SERVER, and $DIC.

Referenced by ilCronManagerGUI\addToExternalSettingsForm(), ilCronJobRepositoryImpl\findAll(), getJobInstanceById(), and updateFromXML().

+ 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 248 of file class.ilCronManager.php.

249 {
250 global $DIC;
251
252 $ilLog = $DIC->logger()->root();
253 $ilPluginAdmin = $DIC['ilPluginAdmin'];
254
255 // plugin
256 if (substr($a_job_id, 0, 4) == "pl__") {
257 $parts = explode("__", $a_job_id);
258 $pl_name = $parts[1];
259 $job_id = $parts[2];
260 if ($ilPluginAdmin->isActive(IL_COMP_SERVICE, "Cron", "crnhk", $pl_name)) {
261 $plugin_obj = $ilPluginAdmin->getPluginObject(
263 "Cron",
264 "crnhk",
265 $pl_name
266 );
267 $job = $plugin_obj->getCronJobInstance($job_id);
268 if ($job instanceof ilCronJob) {
269 // should never happen but who knows...
270 if (!sizeof(ilCronManager::getCronJobData($job_id))) {
271 // as job is not "imported" from xml
273 }
274 return $job;
275 }
276 }
277
278 return null;
279 }
280 // system
281 else {
282 $job_data = self::getCronJobData($a_job_id);
283 $job_data = array_pop($job_data);
284 if ($job_data["job_id"] == $a_job_id) {
286 $job_data["job_id"],
287 $job_data["component"],
288 $job_data["class"],
289 $job_data["path"]
290 );
291 }
292 }
293
294 $ilLog->write("CRON - job " . $a_job_id . " seems invalid or is inactive");
295 }
const IL_COMP_SERVICE
Cron job application base class.
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)
static getJobInstance($a_id, $a_component, $a_class, $a_path=null)
Get job instance (by job data)

References $DIC, createDefaultEntry(), getCronJobData(), getJobInstance(), IL_COMP_PLUGIN, and IL_COMP_SERVICE.

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

+ 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 751 of file class.ilCronManager.php.

752 {
753 list($usec, $sec) = explode(" ", microtime());
754 return ((float) $usec + (float) $sec);
755 }

Referenced by runJob().

+ Here is the caller graph for this function:

◆ getPluginJobs()

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

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

511 {
512 global $DIC;
513
514 $ilPluginAdmin = $DIC['ilPluginAdmin'];
515
516 $res = array();
517
518 foreach ($ilPluginAdmin->getActivePluginsForSlot(IL_COMP_SERVICE, "Cron", "crnhk") as $pl_name) {
519 $plugin_obj = $ilPluginAdmin->getPluginObject(IL_COMP_SERVICE, "Cron", "crnhk", $pl_name);
520
521 foreach ((array) $plugin_obj->getCronJobInstances() as $job) {
522 $jobData = ilCronManager::getCronJobData($job->getId());
523 $item = array_pop($jobData);
524 if (!is_array($item) || 0 === count($item)) {
525 // as job is not "imported" from xml
527 }
528
529 $jobData = ilCronManager::getCronJobData($job->getId());
530 $item = array_pop($jobData);
531
532 // #17941
533 if (!$a_only_active ||
534 $item["job_status"] == 1) {
535 $res[$job->getId()] = array($job, $item);
536 }
537 }
538 }
539
540 return $res;
541 }

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

Referenced by ilCronJobRepositoryImpl\findAll().

+ 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 672 of file class.ilCronManager.php.

673 {
674 $job = self::getCronJobData($a_job_id);
675 if ((bool) $job[0]["job_status"]) {
676 return true;
677 }
678 return false;
679 }

References getCronJobData().

Referenced by ilCronManagerGUI\confirmedDeactivate(), ilObjForumAdministrationGUI\getSettingsForm(), ilObjBookingPoolGUI\initEditCustomForm(), ilObjContentObjectGUI\linkChecker(), ilObjForumAdministrationGUI\saveSettings(), and ilLPObjectStatisticsGUI\showCronJobInfo().

+ Here is the call graph for this function:
+ 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 687 of file class.ilCronManager.php.

688 {
689 $job = self::getCronJobData($a_job_id);
690 if (!(bool) $job[0]["job_status"]) {
691 return true;
692 }
693 return false;
694 }

References getCronJobData().

Referenced by ilCronManagerGUI\confirmedActivate().

+ Here is the call graph for this function:
+ 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 762 of file class.ilCronManager.php.

763 {
764 global $DIC;
765 $ilDB = $DIC->database();
766
767 $ilDB->manipulate("UPDATE cron_job SET " .
768 " alive_ts = " . $ilDB->quote(time(), "integer") .
769 " WHERE job_id = " . $ilDB->quote($a_job_id, "text"));
770 }

References $DIC, and $ilDB.

Referenced by ilLPCronObjectStatistics\gatherCourseLPData(), ilLPCronObjectStatistics\gatherTypesData(), ilLPCronObjectStatistics\gatherUserData(), ilForumCronNotification\keepAlive(), ilMailCronOrphanedMails\ping(), ilMembershipCronNotificationsData\ping(), ilLDAPCronSynchronization\run(), and ilMembershipCronNotifications\run().

+ Here is the caller graph for this function:

◆ resetJob()

static ilCronManager::resetJob ( ilCronJob  $a_job)
static

Reset job.

Parameters
ilCronJob$a_job

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

593 {
594 global $DIC;
595 $ilDB = $DIC->database();
596
597 include_once "Services/Cron/classes/class.ilCronJobResult.php";
598 $result = new ilCronJobResult();
601 $result->setMessage("Cron job re-activated by admin");
602 self::updateJobResult($a_job, $result, true);
603
604 $ilDB->manipulate("UPDATE cron_job" .
605 " SET running_ts = " . $ilDB->quote(0, "integer") .
606 " , alive_ts = " . $ilDB->quote(0, "integer") .
607 " , job_result_ts = " . $ilDB->quote(0, "integer") .
608 " WHERE job_id = " . $ilDB->quote($a_job->getId(), "text"));
609
610 self::activateJob($a_job, true);
611 }
$result
Cron job result data container.
static updateJobResult(ilCronJob $a_job, ilCronJobResult $a_result, $a_manual=false)
Save job result.

References $DIC, $ilDB, $result, activateJob(), ilCronJobResult\CODE_MANUAL_RESET, ilCronJob\getId(), ilCronJobResult\STATUS_RESET, and updateJobResult().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ runActiveJobs()

ilCronManager::runActiveJobs ( )

Run all active jobs.

Implements ilCronManagerInterface.

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

37 {
38 $this->logger->info("CRON - batch start");
39
40 $ts = time();
41 $this->settings->set("last_cronjob_start_ts", $ts);
42
43 $useRelativeDates = ilDatePresentation::useRelativeDates();
45 $this->logger->info(sprintf('Set last datetime to: %s', ilDatePresentation::formatDate(new ilDateTime($ts, IL_CAL_UNIX))));
46 $this->logger->info(sprintf(
47 'Verification of last run datetime (read from database): %s',
49 new ilDateTime(ilSetting::_lookupValue('common', 'last_cronjob_start_ts'), IL_CAL_UNIX)
50 )
51 ));
52 ilDatePresentation::setUseRelativeDates((bool) $useRelativeDates);
53
54 // ilLink::_getStaticLink() should work in crons
55 if (!defined("ILIAS_HTTP_PATH")) {
56 define("ILIAS_HTTP_PATH", ilUtil::_getHttpPath());
57 }
58
59 // system
60 foreach (self::getCronJobData(null, false) as $row) {
61 $job = self::getJobInstanceById($row["job_id"]);
62 if ($job) {
63 // #18411 - we are NOT using the initial job data as it might be outdated at this point
64 self::runJob($job);
65 }
66 }
67
68 // plugins
69 foreach (self::getPluginJobs(true) as $item) {
70 // #18411 - we are NOT using the initial job data as it might be outdated at this point
71 self::runJob($item[0]);
72 }
73
74 $this->logger->info("CRON - batch end");
75 }
const IL_CAL_UNIX
static getJobInstanceById($a_job_id)
Get job instance (by job id)
static runJob(ilCronJob $a_job, array $a_job_data=null, $a_manual=false)
Run single cron job (internal)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
static setUseRelativeDates($a_status)
set use relative dates
static useRelativeDates()
check if relative dates are used
@classDescription Date and time handling
static _lookupValue($a_module, $a_keyword)
static _getHttpPath()

References ilUtil\_getHttpPath(), ilSetting\_lookupValue(), ilDatePresentation\formatDate(), getJobInstanceById(), IL_CAL_UNIX, runJob(), settings(), ilDatePresentation\setUseRelativeDates(), and ilDatePresentation\useRelativeDates().

+ Here is the call graph for this function:

◆ runJob()

static ilCronManager::runJob ( ilCronJob  $a_job,
array  $a_job_data = null,
  $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 117 of file class.ilCronManager.php.

118 {
119 global $DIC;
120
121 $ilLog = $DIC->logger()->root();
122 $ilDB = $DIC->database();
123
124 $did_run = false;
125
126 include_once "Services/Cron/classes/class.ilCronJobResult.php";
127
128 if ($a_job_data === null) {
129 // aquire "fresh" job (status) data
130 $jobData = self::getCronJobData($a_job->getId());
131 $a_job_data = array_pop($jobData);
132 }
133
134 // already running?
135 if ($a_job_data["alive_ts"]) {
136 $ilLog->write("CRON - job " . $a_job_data["job_id"] . " still running");
137
138 $cut = 60 * 60 * 3; // 3h
139
140 // is running (and has not pinged) for 3 hours straight, we assume it crashed
141 if (time() - $a_job_data["alive_ts"] > $cut) {
142 $ilDB->manipulate("UPDATE cron_job SET" .
143 " running_ts = " . $ilDB->quote(0, "integer") .
144 " , alive_ts = " . $ilDB->quote(0, "integer") .
145 " WHERE job_id = " . $ilDB->quote($a_job_data["job_id"], "text"));
146
147 self::deactivateJob($a_job); // #13082
148
149 $result = new ilCronJobResult();
152 $result->setMessage("Cron job deactivated because it has been inactive for 3 hours");
153
154 if (!$a_manual) {
156 }
157
158 self::updateJobResult($a_job, $result, $a_manual);
159
160 $ilLog->write("CRON - job " . $a_job_data["job_id"] . " deactivated (assumed crash)");
161 }
162 }
163 // initiate run?
164 elseif ($a_job->isActive(
165 $a_job_data["job_result_ts"],
166 $a_job_data["schedule_type"],
167 $a_job_data["schedule_value"],
168 $a_manual
169 )) {
170 $ilLog->write("CRON - job " . $a_job_data["job_id"] . " started");
171
172 $ilDB->manipulate("UPDATE cron_job SET" .
173 " running_ts = " . $ilDB->quote(time(), "integer") .
174 " , alive_ts = " . $ilDB->quote(time(), "integer") .
175 " WHERE job_id = " . $ilDB->quote($a_job_data["job_id"], "text"));
176
177 $ts_in = self::getMicrotime();
178 try {
179 $result = $a_job->run();
180 } catch (\Exception $e) {
181 $result = new \ilCronJobResult();
183 $result->setMessage(sprintf("Exception: %s", $e->getMessage()));
184
185 $ilLog->error($e->getMessage());
186 $ilLog->error($e->getTraceAsString());
187 } catch (\Throwable $e) { // Could be appended to the catch block with a | in PHP 7.1
188 $result = new \ilCronJobResult();
190 $result->setMessage(sprintf("Exception: %s", $e->getMessage()));
191
192 $ilLog->error($e->getMessage());
193 $ilLog->error($e->getTraceAsString());
194 }
195 $ts_dur = self::getMicrotime() - $ts_in;
196
197 // no proper result
198 if (!$result instanceof ilCronJobResult) {
199 $result = new ilCronJobResult();
202 $result->setMessage("Cron job did not return a proper result");
203
204 if (!$a_manual) {
206 }
207
208 $ilLog->write("CRON - job " . $a_job_data["job_id"] . " no result");
209 }
210 // no valid configuration, job won't work
212 self::deactivateJob($a_job);
213
214 if (!$a_manual) {
216 }
217
218 $ilLog->write("CRON - job " . $a_job_data["job_id"] . " invalid configuration");
219 }
220 // success!
221 else {
222 $did_run = true;
223 }
224
225 $result->setDuration($ts_dur);
226
227 self::updateJobResult($a_job, $result, $a_manual);
228
229 $ilDB->manipulate("UPDATE cron_job SET" .
230 " running_ts = " . $ilDB->quote(0, "integer") .
231 " , alive_ts = " . $ilDB->quote(0, "integer") .
232 " WHERE job_id = " . $ilDB->quote($a_job_data["job_id"], "text"));
233
234 $ilLog->write("CRON - job " . $a_job_data["job_id"] . " finished");
235 } else {
236 $ilLog->write("CRON - job " . $a_job_data["job_id"] . " returned status inactive");
237 }
238
239 return $did_run;
240 }
run()
Run job.
isActive($a_ts_last_run, $a_schedule_type, $a_schedule_value, $a_manual=false)
Is job currently active?
static sendNotification(ilCronJob $a_job, $a_message)
Send notification to admin about job event(s)
static deactivateJob(ilCronJob $a_job, $a_manual=false)
Deactivate cron job.
static getMicrotime()
Get current microtime.

References $DIC, Vendor\Package\$e, $ilDB, $result, ilCronJobResult\CODE_NO_RESULT, ilCronJobResult\CODE_SUPPOSED_CRASH, deactivateJob(), getCronJobData(), ilCronJob\getId(), getMicrotime(), ilCronJob\isActive(), ilCronJob\run(), sendNotification(), ilCronJobResult\STATUS_CRASHED, ilCronJobResult\STATUS_INVALID_CONFIGURATION, and updateJobResult().

Referenced by runActiveJobs(), and runJobManual().

+ Here is the call graph for this function:
+ Here is the caller 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 83 of file class.ilCronManager.php.

84 {
85 global $DIC;
86
87 $ilLog = $DIC->logger()->root();
88
89 $result = false;
90
91 $ilLog->write("CRON - manual start (" . $a_job_id . ")");
92
93 $job = self::getJobInstanceById($a_job_id);
94 if ($job) {
95 if ($job->isManuallyExecutable()) {
96 $result = self::runJob($job, null, true);
97 } else {
98 $ilLog->write("CRON - job " . $a_job_id . " is not intended to be executed manually");
99 }
100 } else {
101 $ilLog->write("CRON - job " . $a_job_id . " seems invalid or is inactive");
102 }
103
104 $ilLog->write("CRON - manual end (" . $a_job_id . ")");
105
106 return $result;
107 }

References $DIC, $result, getJobInstanceById(), and runJob().

Referenced by ilCronManagerGUI\confirmedRun().

+ Here is the call graph for this function:
+ 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 350 of file class.ilCronManager.php.

351 {
352 // :TODO:
353 }

Referenced by runJob().

+ Here is the caller graph for this function:

◆ 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 445 of file class.ilCronManager.php.

446 {
447 global $DIC;
448
449 $ilDB = $DIC->database();
450
451 if (!$ilDB->tableExists("cron_job")) {
452 return;
453 }
454
455 // only if job seems valid
456 $job = self::getJobInstance($a_id, $a_component, $a_class, $a_path);
457 if ($job) {
458 self::createDefaultEntry($job, $a_component, $a_class, $a_path);
459 }
460 }

References $DIC, $ilDB, createDefaultEntry(), and getJobInstance().

Referenced by ilObjDefReader\handlerBeginTag().

+ Here is the call graph for this function:
+ 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 703 of file class.ilCronManager.php.

704 {
705 global $DIC;
706 $ilDB = $DIC->database();
707 $ilUser = $DIC->user();
708
709 $user_id = $a_manual ? $ilUser->getId() : 0;
710
711 $sql = "UPDATE cron_job SET " .
712 " job_result_status = " . $ilDB->quote($a_result->getStatus(), "integer") .
713 " , job_result_user_id = " . $ilDB->quote($user_id, "integer") .
714 " , job_result_code = " . $ilDB->quote($a_result->getCode(), "text") .
715 " , job_result_message = " . $ilDB->quote($a_result->getMessage(), "text") .
716 " , job_result_type = " . $ilDB->quote($a_manual, "integer") .
717 " , job_result_ts = " . $ilDB->quote(time(), "integer") .
718 " , job_result_dur = " . $ilDB->quote($a_result->getDuration() * 1000, "integer") .
719 " WHERE job_id = " . $ilDB->quote($a_job->getId(), "text");
720 $ilDB->manipulate($sql);
721 }

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

Referenced by resetJob(), and runJob().

+ Here is the call graph for this function:
+ Here is the caller 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 730 of file class.ilCronManager.php.

731 {
732 global $DIC;
733 $ilDB = $DIC->database();
734
735 if ($a_schedule_type === null ||
736 ($a_job->hasFlexibleSchedule() &&
737 in_array($a_schedule_type, $a_job->getValidScheduleTypes()))) {
738 $sql = "UPDATE cron_job SET " .
739 " schedule_type = " . $ilDB->quote($a_schedule_type, "integer") .
740 " , schedule_value = " . $ilDB->quote($a_schedule_value, "integer") .
741 " WHERE job_id = " . $ilDB->quote($a_job->getId(), "text");
742 $ilDB->manipulate($sql);
743 }
744 }
getValidScheduleTypes()
Returns a collection of all valid schedule types for a specific job.

References $DIC, $ilDB, ilCronJob\getId(), ilCronJob\getValidScheduleTypes(), and ilCronJob\hasFlexibleSchedule().

Referenced by createDefaultEntry(), ilCronManagerTableGUI\populate(), and ilCronManagerGUI\update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $logger

ilCronManager::$logger
protected

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

Referenced by __construct().

◆ $settings

ilCronManager::$settings
protected

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

Referenced by __construct().


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