function fireSelf($id)
 {
     require_once 'modules/Schedulers/Scheduler.php';
     $sched = new Scheduler();
     $sched->retrieve($id);
     $exJob = explode('::', $sched->job);
     if (is_array($exJob)) {
         $this->scheduler_id = $sched->id;
         $this->scheduler = $sched;
         $this->execute_time = $this->handleDateFormat('now');
         $this->save();
         if ($exJob[0] == 'function') {
             $GLOBALS['log']->debug('----->Scheduler found a job of type FUNCTION');
             require_once 'modules/Schedulers/_AddJobsHere.php';
             $this->setJobFlag(1);
             $func = $exJob[1];
             $GLOBALS['log']->debug('----->SchedulersJob firing ' . $func);
             $res = call_user_func($func);
             if ($res) {
                 $this->setJobFlag(2);
                 $this->finishJob();
                 return true;
             } else {
                 $this->setJobFlag(3);
                 return false;
             }
         } elseif ($exJob[0] == 'url') {
             if (function_exists('curl_init')) {
                 $GLOBALS['log']->debug('----->SchedulersJob found a job of type URL');
                 $this->setJobFlag(1);
                 $GLOBALS['log']->debug('----->SchedulersJob firing URL job: ' . $exJob[1]);
                 if ($this->fireUrl($exJob[1])) {
                     $this->setJobFlag(2);
                     $this->finishJob();
                     return true;
                 } else {
                     $this->setJobFlag(3);
                     return false;
                 }
             } else {
                 $this->setJobFlag(4);
                 return false;
             }
         }
     }
     return false;
 }
示例#2
0
 *    (ii) the SugarCRM copyright notice
 * in the same form as they appear in the distribution.  See full license for
 * requirements.
 *
 * The Original Code is: SugarCRM Open Source
 * The Initial Developer of the Original Code is SugarCRM, Inc.
 * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.;
 * All Rights Reserved.
 * Contributor(s): ______________________________________.
 ********************************************************************************/
/*********************************************************************************
 * Description:  
 ********************************************************************************/
require_once 'modules/Schedulers/Scheduler.php';
$focus = new Scheduler();
$focus->retrieve($_REQUEST['record']);
// deal with empty values
if (!empty($_REQUEST['date_end']) && !empty($_REQUEST['time_hour_end']) && !empty($_REQUEST['time_minute_end'])) {
    $date_time_end = $_REQUEST['date_end'] . " " . str_pad($_REQUEST['time_hour_end'], 2, '0', STR_PAD_LEFT) . ":" . str_pad($_REQUEST['time_minute_end'], 2, '0', STR_PAD_LEFT) . $_REQUEST['time_end_meridiem'];
} else {
    $date_time_end = '';
}
if ((!empty($_REQUEST['time_hour_from']) || $_REQUEST['time_hour_from'] == '0') && (!empty($_REQUEST['time_minute_from']) || $_REQUEST['time_minute_from'] == '0')) {
    $time_from = str_pad($_REQUEST['time_hour_from'], 2, '0', STR_PAD_LEFT) . ":" . str_pad($_REQUEST['time_minute_from'], 2, '0', STR_PAD_LEFT);
    if (!empty($_REQUEST['time_from_meridiem'])) {
        $time_from .= $_REQUEST['time_from_meridiem'];
    }
} else {
    $time_from = '';
}
if ((!empty($_REQUEST['time_hour_to']) || $_REQUEST['time_hour_to'] == '0') && (!empty($_REQUEST['time_minute_to']) || $_REQUEST['time_minute_to'] == '0')) {
 /**
  * This function retrieves valid jobs, parses the cron format, then returns
  * an array of [JOB_ID][EXEC_TIME][JOB]
  * 
  * @return	$executeJobs	multi-dimensional array 
  * 							[job_id][execute_time]
  */
 function retrieveSchedulers()
 {
     $GLOBALS['log']->info('Gathering Schedulers');
     $executeJobs = array();
     $query = "SELECT id " . "FROM schedulers " . "WHERE deleted=0 " . "AND status = 'Active' " . "AND date_time_start < " . db_convert("'" . gmdate('Y-m-d H:i:s') . "'", 'datetime') . " " . "AND (date_time_end > " . db_convert("'" . gmdate('Y-m-d H:i:s') . "'", 'datetime') . " OR date_time_end IS NULL)";
     $result = $this->db->query($query);
     $rows = 0;
     $executeTimes = array();
     $executeIds = array();
     $executeJobTimes = array();
     while (($arr = $this->db->fetchByAssoc($result)) != null) {
         $focus = new Scheduler();
         $focus->retrieve($arr['id']);
         $executeTimes[$rows] = $this->deriveDBDateTimes($focus);
         if (count($executeTimes) > 0) {
             foreach ($executeTimes as $k => $time) {
                 $executeIds[$rows] = $focus->id;
                 $executeJobTimes[$rows] = $time;
             }
         }
         $rows++;
     }
     $executeJobs['ids'] = $executeIds;
     $executeJobs['times'] = $executeJobTimes;
     return $executeJobs;
 }