23                $ilLog->write(
"CRON - batch start");
 
   25                $ilSetting->set(
"last_cronjob_start_ts", time());
 
   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                include_once 
"Services/Cron/classes/class.ilCronJobResult.php";         
 
  105                if($a_job_data === 
null)
 
  108                        $a_job_data = array_pop(self::getCronJobData($a_job->
getId()));
 
  112                if($a_job_data[
"alive_ts"])
 
  114                        $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" still running");
 
  119                        if(time()-$a_job_data[
"alive_ts"] > $cut)
 
  121                                $ilDB->manipulate(
"UPDATE cron_job SET".
 
  122                                        " running_ts = ".
$ilDB->quote(0, 
"integer").
 
  123                                        " , alive_ts = ".$ilDB->quote(0, 
"integer").                                                    
 
  124                                        " WHERE job_id = ".$ilDB->quote($a_job_data[
"job_id"], 
"text"));
 
  131                                $result->setMessage(
"Cron job deactivated because it has been inactive for 3 hours");
 
  140                                $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" deactivated (assumed crash)");
 
  144                else if($a_job->
isActive($a_job_data[
"job_result_ts"], 
 
  145                        $a_job_data[
"schedule_type"], $a_job_data[
"schedule_value"], $a_manual))
 
  147                        $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" started");
 
  149                        $ilDB->manipulate(
"UPDATE cron_job SET".
 
  150                                " running_ts = ".
$ilDB->quote(time(), 
"integer").
 
  151                                " , alive_ts = ".
$ilDB->quote(time(), 
"integer").
 
  152                                " WHERE job_id = ".
$ilDB->quote($a_job_data[
"job_id"], 
"text"));
 
  164                                $result->setMessage(
"Cron job did not return a proper result");
 
  171                                $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" no result");
 
  183                                $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" invalid configuration");
 
  195                        $ilDB->manipulate(
"UPDATE cron_job SET".
 
  196                                " running_ts = ".
$ilDB->quote(0, 
"integer").
 
  197                                " , alive_ts = ".$ilDB->quote(0, 
"integer").
 
  198                                " WHERE job_id = ".$ilDB->quote($a_job_data[
"job_id"], 
"text"));                
 
  200                        $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" finished");
 
  204                        $ilLog->write(
"CRON - job ".$a_job_data[
"job_id"].
" returned status inactive");
 
  218                global 
$ilLog, $ilPluginAdmin;
 
  221                if(substr($a_job_id, 0, 4) == 
"pl__")
 
  223                        $parts = explode(
"__", $a_job_id);
 
  224                        $pl_name = $parts[1];
 
  226                        if($ilPluginAdmin->isActive(
IL_COMP_SERVICE, 
"Cron", 
"crnhk", $pl_name))
 
  229                                        "Cron", 
"crnhk", $pl_name);                     
 
  230                                $job = $plugin_obj->getCronJobInstance($job_id);
 
  248                        $job_data = array_pop(self::getCronJobData($a_job_id));
 
  249                        if($job_data[
"job_id"] == $a_job_id)
 
  252                                        $job_data[
"class"], $job_data[
"path"]);                         
 
  256                $ilLog->write(
"CRON - job ".$a_job_id.
" seems invalid or is inactive");         
 
  267        public static function getJobInstance($a_id, $a_component, $a_class, $a_path = 
null)
 
  273                        $a_path = $a_component.
"/classes/";
 
  275                $class_file = $a_path.
"class.".$a_class.
".php";                                                 
 
  276                if(file_exists($class_file))
 
  278                        include_once $class_file;
 
  279                        if(class_exists($a_class))
 
  281                                $job = 
new $a_class();                          
 
  284                                        if($job->getId() == $a_id)
 
  290                                                $mess .= 
" - job id mismatch";
 
  295                                        $mess .= 
" - does not extend ilCronJob";
 
  300                                $mess = 
"- class not found in file";
 
  305                        $mess = 
" - class file not found";
 
  308                $ilLog->write(
"Cron XML - Job ".$a_id.
" in class ".$a_class.
" (".
 
  309                        $class_file.
") is invalid.".$mess);
 
  328                $sql = 
"SELECT job_id, schedule_type FROM cron_job".
 
  329                        " WHERE component = ".$ilDB->quote($a_component, 
"text").
 
  330                        " AND job_id = ".$ilDB->quote($a_job->
getId(), 
"text");
 
  331                $set = 
$ilDB->query($sql);
 
  333                $job_exists = (
$row[
"job_id"] == $a_job->
getId());
 
  334                $schedule_type = 
$row[
"schedule_type"];
 
  339                        $sql = 
"INSERT INTO cron_job (job_id, component, class, path)".
 
  340                                " VALUES (".$ilDB->quote($a_job->
getId(), 
"text").
", ".
 
  341                                $ilDB->quote($a_component, 
"text").
", ".
 
  342                                $ilDB->quote($a_class, 
"text").
", ".
 
  343                                $ilDB->quote($a_path, 
"text").
")";
 
  344                        $ilDB->manipulate($sql);
 
  346                        $ilLog->write(
"Cron XML - Job ".$a_job->
getId().
" in class ".$a_class.
 
  357                                include_once 
"Services/Administration/classes/class.ilSetting.php";
 
  393        public static function updateFromXML($a_component, $a_id, $a_class, $a_path = 
null)
 
  397                if(!
$ilDB->tableExists(
"cron_job"))
 
  416        public static function clearFromXML($a_component, array $a_xml_job_ids)
 
  420                if(!
$ilDB->tableExists(
"cron_job"))
 
  427                $sql = 
"SELECT job_id FROM cron_job".
 
  428                        " WHERE component = ".$ilDB->quote($a_component, 
"text");
 
  429                $set = 
$ilDB->query($sql);
 
  432                        $all_jobs[] = 
$row[
"job_id"];
 
  435                if(
sizeof($all_jobs))
 
  437                        if(
sizeof($a_xml_job_ids))
 
  440                                foreach($all_jobs as $job_id)
 
  442                                        if(!in_array($job_id, $a_xml_job_ids))
 
  444                                                $ilDB->manipulate(
"DELETE FROM cron_job".
 
  445                                                        " WHERE component = ".
$ilDB->quote($a_component, 
"text").
 
  446                                                        " AND job_id = ".$ilDB->quote($job_id, 
"text"));        
 
  448                                                $ilLog->write(
"Cron XML - Job ".$job_id.
" in class ".$a_component.
 
  455                                $ilDB->manipulate(
"DELETE FROM cron_job".
 
  456                                        " WHERE component = ".
$ilDB->quote($a_component, 
"text"));                      
 
  458                                $ilLog->write(
"Cron XML - All jobs deleted for ".$a_component.
" as component is inactive.");
 
  465                global $ilPluginAdmin;
 
  469                foreach($ilPluginAdmin->getActivePluginsForSlot(
IL_COMP_SERVICE, 
"Cron", 
"crnhk") as $pl_name)
 
  471                        $plugin_obj = $ilPluginAdmin->getPluginObject(
IL_COMP_SERVICE, 
"Cron", 
"crnhk", $pl_name);
 
  473                        foreach((array)$plugin_obj->getCronJobInstances() as $job)
 
  485                                if(!$a_only_active ||
 
  486                                        $item[
"job_status"] == 1)
 
  488                                        $res[$job->getId()] = array($job, $item);       
 
  509                if($a_id && !is_array($a_id))
 
  511                        $a_id = array($a_id);
 
  514                $sql = 
"SELECT * FROM cron_job";
 
  519                        $where[] = 
$ilDB->in(
"job_id", $a_id, 
"", 
"text");
 
  525                if(!$a_include_inactive)
 
  527                        $where[] = 
"job_status = ".$ilDB->quote(1, 
"integer");
 
  531                        $sql .= 
" WHERE ".implode(
" AND ", $where);                     
 
  535                $sql .= 
" ORDER BY job_id";
 
  537                $set = 
$ilDB->query($sql);
 
  555                include_once 
"Services/Cron/classes/class.ilCronJobResult.php";
 
  559                $result->setMessage(
"Cron job re-activated by admin");          
 
  562                $ilDB->manipulate(
"UPDATE cron_job".
 
  563                        " SET running_ts = ".
$ilDB->quote(0, 
"integer").
 
  564                        " , alive_ts = ".$ilDB->quote(0, 
"integer").
 
  565                        " , job_result_ts = ".$ilDB->quote(0, 
"integer").
 
  566                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text"));              
 
  581                $user_id = $a_manual ? 
$ilUser->getId() : 0;
 
  583                $sql = 
"UPDATE cron_job SET ".
 
  584                        " job_status = ".$ilDB->quote(1, 
"integer").
 
  585                        " , job_status_user_id = ".$ilDB->quote($user_id, 
"integer").
 
  586                        " , job_status_type = ".$ilDB->quote($a_manual, 
"integer").
 
  587                        " , job_status_ts = ".$ilDB->quote(time(), 
"integer"). 
 
  588                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");               
 
  589                $ilDB->manipulate($sql);
 
  604                $user_id = $a_manual ? 
$ilUser->getId() : 0;
 
  606                $sql = 
"UPDATE cron_job SET ".
 
  607                        " job_status = ".$ilDB->quote(0, 
"integer").
 
  608                        " , job_status_user_id = ".$ilDB->quote($user_id, 
"integer").
 
  609                        " , job_status_type = ".$ilDB->quote($a_manual, 
"integer").
 
  610                        " , job_status_ts = ".$ilDB->quote(time(), 
"integer"). 
 
  611                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");
 
  612                $ilDB->manipulate($sql);
 
  626                if((
bool)$job[0][
"job_status"])
 
  642                if(!(
bool)$job[0][
"job_status"])
 
  660                $user_id = $a_manual ? 
$ilUser->getId() : 0;
 
  662                $sql = 
"UPDATE cron_job SET ".
 
  663                        " job_result_status = ".$ilDB->quote($a_result->
getStatus(), 
"integer").
 
  664                        " , job_result_user_id = ".$ilDB->quote($user_id, 
"integer").
 
  665                        " , job_result_code = ".$ilDB->quote($a_result->
getCode(), 
"text").
 
  666                        " , job_result_message = ".$ilDB->quote($a_result->
getMessage(), 
"text"). 
 
  667                        " , job_result_type = ".$ilDB->quote($a_manual, 
"integer"). 
 
  668                        " , job_result_ts = ".$ilDB->quote(time(), 
"integer"). 
 
  669                        " , job_result_dur = ".$ilDB->quote($a_result->
getDuration()*1000, 
"integer").
 
  670                        " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");               
 
  671                $ilDB->manipulate($sql);
 
  685                if($a_schedule_type === 
null ||
 
  689                        $sql = 
"UPDATE cron_job SET ".
 
  690                                " schedule_type = ".$ilDB->quote($a_schedule_type, 
"integer").
 
  691                                " , schedule_value = ".$ilDB->quote($a_schedule_value, 
"integer").
 
  692                                " WHERE job_id = ".$ilDB->quote($a_job->
getId(), 
"text");
 
  693                        $ilDB->manipulate($sql);
 
  704                list($usec, $sec) = explode(
" ", microtime());
 
  705                return ((
float)$usec + (
float)$sec);
 
  713        public static function ping($a_job_id)
 
  717                $ilDB->manipulate(
"UPDATE cron_job SET ".
 
  718                        " alive_ts = ".
$ilDB->quote(time(), 
"integer").
 
  719                        " WHERE job_id = ".
$ilDB->quote($a_job_id, 
"text"));
 
An exception for terminatinating execution or to throw for unit testing.
Cron job result data container.
const CODE_SUPPOSED_CRASH
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)
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'