23                $ilLog->write(
"CRON - batch start");
 
   25                $ilSetting->set(
"last_cronjob_start_ts", time());
 
   28                if(!defined(
"ILIAS_HTTP_PATH"))
 
   34                foreach(self::getCronJobData(
null, 
false) as 
$row)
 
   45                foreach(self::getPluginJobs(
true) as $item)
 
   50                $ilLog->write(
"CRON - batch end");
 
   65                $ilLog->write(
"CRON - manual start (".$a_job_id.
")");
 
   70                        if($job->isManuallyExecutable())
 
   76                                $ilLog->write(
"CRON - job ".$a_job_id.
" is not intended to be executed manually");
 
   81                        $ilLog->write(
"CRON - job ".$a_job_id.
" seems invalid or is inactive");
 
   84                $ilLog->write(
"CRON - manual end (".$a_job_id.
")");
 
   97        protected static function runJob(
ilCronJob $a_job, array $a_job_data = 
null, $a_manual = 
false)
 
  103                if($a_job_data === 
null)
 
  106                        $a_job_data = array_pop(self::getCronJobData($a_job->
getId()));
 
  111                        include_once 
"Services/Cron/classes/class.ilCronJobResult.php";         
 
  114                        if($a_job_data[
"alive_ts"])
 
  116                                $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" still running");
 
  121                                if(time()-$a_job_data[
"alive_ts"] > $cut)
 
  123                                        $ilDB->manipulate(
"UPDATE cron_job SET".
 
  124                                                " running_ts = ".
$ilDB->quote(0, 
"integer").
 
  125                                                " , alive_ts = ".$ilDB->quote(0, 
"integer").                                                    
 
  126                                                " WHERE job_id = ".$ilDB->quote($a_job_data[
"job_id"], 
"text"));
 
  132                                        $result->setCode(
"job_auto_deactivation_time_limit");
 
  133                                        $result->setMessage(
"Cron job deactivated because it has been inactive for 3 hours");
 
  142                                        $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" deactivated (assumed crash)");
 
  146                        else if($a_job->
isActive($a_job_data[
"job_result_ts"], 
 
  147                                $a_job_data[
"schedule_type"], $a_job_data[
"schedule_value"], $a_manual))
 
  149                                $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" started");
 
  151                                $ilDB->manipulate(
"UPDATE cron_job SET".
 
  152                                        " running_ts = ".
$ilDB->quote(time(), 
"integer").
 
  153                                        " , alive_ts = ".
$ilDB->quote(time(), 
"integer").
 
  154                                        " WHERE job_id = ".
$ilDB->quote($a_job_data[
"job_id"], 
"text"));
 
  165                                        $result->setCode(
"job_no_result");
 
  166                                        $result->setMessage(
"Cron job did not return a proper result");
 
  173                                        $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" no result");
 
  185                                        $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" invalid configuration");
 
  197                                $ilDB->manipulate(
"UPDATE cron_job SET".
 
  198                                        " running_ts = ".
$ilDB->quote(0, 
"integer").
 
  199                                        " , alive_ts = ".$ilDB->quote(0, 
"integer").
 
  200                                        " WHERE job_id = ".$ilDB->quote($a_job_data[
"job_id"], 
"text"));                
 
  202                                $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" finished");
 
  206                                $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" returned status inactive");
 
  221                global 
$ilLog, $ilPluginAdmin;
 
  224                if(substr($a_job_id, 0, 4) == 
"pl__")
 
  226                        $parts = explode(
"__", $a_job_id);
 
  227                        $pl_name = $parts[1];
 
  229                        if($ilPluginAdmin->isActive(
IL_COMP_SERVICE, 
"Cron", 
"crnhk", $pl_name))
 
  232                                        "Cron", 
"crnhk", $pl_name);                     
 
  233                                $job = $plugin_obj->getCronJobInstance($job_id);
 
  251                        $job_data = array_pop(self::getCronJobData($a_job_id));
 
  252                        if($job_data[
"job_id"] == $a_job_id)
 
  255                                        $job_data[
"class"], $job_data[
"path"]);                         
 
  259                $ilLog->write(
"CRON - job ".$a_job_id.
" seems invalid or is inactive");         
 
  270        public static function getJobInstance($a_id, $a_component, $a_class, $a_path = 
null)
 
  276                        $a_path = $a_component.
"/classes/";
 
  278                $class_file = $a_path.
"class.".$a_class.
".php";                                                 
 
  279                if(file_exists($class_file))
 
  281                        include_once $class_file;
 
  282                        if(class_exists($a_class))
 
  284                                $job = 
new $a_class();                          
 
  287                                        if($job->getId() == $a_id)
 
  293                                                $mess .= 
" - job id mismatch";
 
  298                                        $mess .= 
" - does not extend ilCronJob";
 
  303                                $mess = 
"- class not found in file";
 
  308                        $mess = 
" - class file not found";
 
  311                $ilLog->write(
"Cron XML - Job ".$a_id.
" in class ".$a_class.
" (".
 
  312                        $class_file.
") is invalid.".$mess);
 
  331                $sql = 
"SELECT job_id, schedule_type FROM cron_job".
 
  332                        " WHERE component = ".$ilDB->quote($a_component, 
"text").
 
  333                        " AND job_id = ".$ilDB->quote($a_job->
getId(), 
"text");
 
  334                $set = 
$ilDB->query($sql);
 
  336                $job_exists = (
$row[
"job_id"] == $a_job->
getId());
 
  337                $schedule_type = 
$row[
"schedule_type"];
 
  342                        $sql = 
"INSERT INTO cron_job (job_id, component, class, path)".
 
  343                                " VALUES (".$ilDB->quote($a_job->
getId(), 
"text").
", ".
 
  344                                $ilDB->quote($a_component, 
"text").
", ".
 
  345                                $ilDB->quote($a_class, 
"text").
", ".
 
  346                                $ilDB->quote($a_path, 
"text").
")";
 
  347                        $ilDB->manipulate($sql);
 
  349                        $ilLog->write(
"Cron XML - Job ".$a_job->
getId().
" in class ".$a_class.
 
  360                                include_once 
"Services/Administration/classes/class.ilSetting.php";
 
  396        public static function updateFromXML($a_component, $a_id, $a_class, $a_path = 
null)
 
  400                if(!
$ilDB->tableExists(
"cron_job"))
 
  419        public static function clearFromXML($a_component, array $a_xml_job_ids)
 
  423                if(!
$ilDB->tableExists(
"cron_job"))
 
  430                $sql = 
"SELECT job_id FROM cron_job".
 
  431                        " WHERE component = ".$ilDB->quote($a_component, 
"text");
 
  432                $set = 
$ilDB->query($sql);
 
  435                        $all_jobs[] = 
$row[
"job_id"];
 
  438                if(
sizeof($all_jobs))
 
  440                        if(
sizeof($a_xml_job_ids))
 
  443                                foreach($all_jobs as $job_id)
 
  445                                        if(!in_array($job_id, $a_xml_job_ids))
 
  447                                                $ilDB->manipulate(
"DELETE FROM cron_job".
 
  448                                                        " WHERE component = ".
$ilDB->quote($a_component, 
"text").
 
  449                                                        " AND job_id = ".$ilDB->quote($job_id, 
"text"));        
 
  451                                                $ilLog->write(
"Cron XML - Job ".$job_id.
" in class ".$a_component.
 
  458                                $ilDB->manipulate(
"DELETE FROM cron_job".
 
  459                                        " WHERE component = ".
$ilDB->quote($a_component, 
"text"));                      
 
  461                                $ilLog->write(
"Cron XML - All jobs deleted for ".$a_component.
" as component is inactive.");
 
  468                global $ilPluginAdmin;
 
  472                foreach($ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_SERVICE, 
"Cron", 
"crnhk") as $pl_name)
 
  474                        $plugin_obj = $ilPluginAdmin->getPluginObject(
IL_COMP_SERVICE, 
"Cron", 
"crnhk", $pl_name);
 
  476                        foreach((array)$plugin_obj->getCronJobInstances() as $job)
 
  488                                if(!$a_only_active ||
 
  489                                        $item[
"job_status"] == 1)
 
  491                                        $res[$job->getId()] = array($job, $item);       
 
  512                if($a_id && !is_array($a_id))
 
  514                        $a_id = array($a_id);
 
  517                $sql = 
"SELECT * FROM cron_job";
 
  522                        $where[] = 
$ilDB->in(
"job_id", $a_id, 
"", 
"text");
 
  528                if(!$a_include_inactive)
 
  530                        $where[] = 
"job_status = ".$ilDB->quote(1, 
"integer");
 
  534                        $sql .= 
" WHERE ".implode(
" AND ", $where);                     
 
  538                $sql .= 
" ORDER BY job_id";
 
  540                $set = 
$ilDB->query($sql);
 
  558                include_once 
"Services/Cron/classes/class.ilCronJobResult.php";
 
  561                $result->setCode(
"job_manual_reset");
 
  562                $result->setMessage(
"Cron job re-activated by admin");          
 
  565                $ilDB->manipulate(
"UPDATE cron_job".
 
  566                        " SET running_ts = ".
$ilDB->quote(0, 
"integer").
 
  567                        " , alive_ts = ".$ilDB->quote(0, 
"integer").
 
  568                        " , job_result_ts = ".$ilDB->quote(0, 
"integer").
 
  569                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text"));              
 
  584                $user_id = $a_manual ? 
$ilUser->getId() : 0;
 
  586                $sql = 
"UPDATE cron_job SET ".
 
  587                        " job_status = ".$ilDB->quote(1, 
"integer").
 
  588                        " , job_status_user_id = ".$ilDB->quote($user_id, 
"integer").
 
  589                        " , job_status_type = ".$ilDB->quote($a_manual, 
"integer").
 
  590                        " , job_status_ts = ".$ilDB->quote(time(), 
"integer"). 
 
  591                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");               
 
  592                $ilDB->manipulate($sql);
 
  607                $user_id = $a_manual ? 
$ilUser->getId() : 0;
 
  609                $sql = 
"UPDATE cron_job SET ".
 
  610                        " job_status = ".$ilDB->quote(0, 
"integer").
 
  611                        " , job_status_user_id = ".$ilDB->quote($user_id, 
"integer").
 
  612                        " , job_status_type = ".$ilDB->quote($a_manual, 
"integer").
 
  613                        " , job_status_ts = ".$ilDB->quote(time(), 
"integer"). 
 
  614                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");
 
  615                $ilDB->manipulate($sql);
 
  629                if((
bool)$job[0][
"job_status"])
 
  645                if(!(
bool)$job[0][
"job_status"])
 
  663                $user_id = $a_manual ? 
$ilUser->getId() : 0;
 
  665                $sql = 
"UPDATE cron_job SET ".
 
  666                        " job_result_status = ".$ilDB->quote($a_result->
getStatus(), 
"integer").
 
  667                        " , job_result_user_id = ".$ilDB->quote($user_id, 
"integer").
 
  668                        " , job_result_code = ".$ilDB->quote($a_result->
getCode(), 
"text").
 
  669                        " , job_result_message = ".$ilDB->quote($a_result->
getMessage(), 
"text"). 
 
  670                        " , job_result_type = ".$ilDB->quote($a_manual, 
"integer"). 
 
  671                        " , job_result_ts = ".$ilDB->quote(time(), 
"integer"). 
 
  672                        " , job_result_dur = ".$ilDB->quote($a_result->
getDuration()*1000, 
"integer").
 
  673                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");               
 
  674                $ilDB->manipulate($sql);
 
  688                if($a_schedule_type === 
null ||
 
  692                        $sql = 
"UPDATE cron_job SET ".
 
  693                                " schedule_type = ".$ilDB->quote($a_schedule_type, 
"integer").
 
  694                                " , schedule_value = ".$ilDB->quote($a_schedule_value, 
"integer").
 
  695                                " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");
 
  696                        $ilDB->manipulate($sql);
 
  707                list($usec, $sec) = explode(
" ", microtime());
 
  708                return ((
float)$usec + (
float)$sec);
 
  716        public static function ping($a_job_id)
 
  720                $ilDB->manipulate(
"UPDATE cron_job SET ".
 
  721                        " alive_ts = ".
$ilDB->quote(time(), 
"integer").
 
  722                        " WHERE job_id = ".
$ilDB->quote($a_job_id, 
"text"));
 
Cron job result data container.
const STATUS_INVALID_CONFIGURATION
Cron job application base class.
getDefaultScheduleType()
Get schedule type.
activationWasToggled($a_currently_active)
Cron job status was changed.
getDefaultScheduleValue()
Get schedule value.
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".
hasFlexibleSchedule()
Can the schedule be configured?
getValidScheduleTypes()
Get all available schedule types.
static getCronJobData($a_id=null, $a_include_inactive=true)
Get cron job configuration/execution data.
static sendNotification(ilCronJob $a_job, $a_message)
Send notification to admin about job event(s)
static updateFromXML($a_component, $a_id, $a_class, $a_path=null)
Process data from module.xml/service.xml.
static createDefaultEntry(ilCronJob $a_job, $a_component, $a_class, $a_path)
static isJobInactive($a_job_id)
Check if given job is currently inactive.
static getJobInstanceById($a_job_id)
Get job instance (by job id)
static runJobManual($a_job_id)
Run single job manually.
static activateJob(ilCronJob $a_job, $a_manual=false)
Activate cron job.
static getJobInstance($a_id, $a_component, $a_class, $a_path=null)
Get job instance (by job data)
static isJobActive($a_job_id)
Check if given job is currently active.
static deactivateJob(ilCronJob $a_job, $a_manual=false)
Deactivate cron job.
static updateJobResult(ilCronJob $a_job, ilCronJobResult $a_result, $a_manual=false)
Save job result.
static clearFromXML($a_component, array $a_xml_job_ids)
Clear job data.
static resetJob(ilCronJob $a_job)
Reset job.
static ping($a_job_id)
Keep cron job alive.
static updateJobSchedule(ilCronJob $a_job, $a_schedule_type, $a_schedule_value)
Update job schedule.
static runJob(ilCronJob $a_job, array $a_job_data=null, $a_manual=false)
Run single cron job (internal)
static runActiveJobs()
Run all active jobs.
static getMicrotime()
Get current microtime.
static getPluginJobs($a_only_active=false)