2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 require_once 'modules/SchedulersJobs/SchedulersJob.php';
40 class Scheduler extends SugarBean {
46 var $modified_user_id;
49 var $modified_by_name;
63 var $intervalHumanReadable;
73 var $timeOutMins = 60;
74 // standard SugarBean attrs
75 var $table_name = "schedulers";
76 var $object_name = "Scheduler";
77 var $module_dir = "Schedulers";
78 var $new_schema = true;
79 var $process_save_dates = true;
82 public static $job_strings;
84 public function __construct($init=true)
87 $job = new SchedulersJob();
88 $this->job_queue_table = $job->table_name;
91 protected function getUser()
93 if(empty($this->user)) {
99 protected function initUser()
102 //check is default admin exists
103 $adminId = $this->db->getOne(
104 'SELECT id FROM users WHERE id='.$this->db->quoted('1').' AND is_admin=1 AND deleted=0 AND status='.$this->db->quoted('Active'),
106 'Error retrieving Admin account info'
108 if (false === $adminId) {//retrive another admin
109 $adminId = $this->db->getOne(
110 'SELECT id FROM users WHERE is_admin=1 AND deleted=0 AND status='.$this->db->quoted('Active'),
112 'Error retrieving Admin account info'
115 $user->retrieve($adminId);
117 $GLOBALS['log']->fatal('No Admin account found!');
122 $user->retrieve('1'); // Scheduler jobs run as default Admin
128 ///////////////////////////////////////////////////////////////////////////
129 //// SCHEDULER HELPER FUNCTIONS
132 * calculates if a job is qualified to run
134 public function fireQualified()
136 if(empty($this->id)) { // execute only if we have an instance
137 $GLOBALS['log']->fatal('Scheduler called fireQualified() in a non-instance');
141 $now = TimeDate::getInstance()->getNow();
142 $now = $now->setTime($now->hour, $now->min, "00")->asDb();
143 $validTimes = $this->deriveDBDateTimes($this);
145 if(is_array($validTimes) && in_array($now, $validTimes)) {
146 $GLOBALS['log']->debug('----->Scheduler found valid job ('.$this->name.') for time GMT('.$now.')');
149 $GLOBALS['log']->debug('----->Scheduler did NOT find valid job ('.$this->name.') for time GMT('.$now.')');
155 * Create a job from this scheduler
156 * @return SchedulersJob
158 public function createJob()
160 $job = new SchedulersJob();
161 $job->scheduler_id = $this->id;
162 $job->name = $this->name;
163 $job->execute_time = $GLOBALS['timedate']->nowDb();
164 $job->assigned_user_id = $this->getUser()->id;
165 $job->target = $this->job;
170 * Checks if any jobs qualify to run at this moment
171 * @param SugarJobQueue $queue
173 public function checkPendingJobs($queue)
175 $allSchedulers = $this->get_full_list('', "schedulers.status='Active' AND NOT EXISTS(SELECT id FROM {$this->job_queue_table} WHERE scheduler_id=schedulers.id AND status!='".SchedulersJob::JOB_STATUS_DONE."')");
177 $GLOBALS['log']->info('-----> Scheduler found [ '.count($allSchedulers).' ] ACTIVE jobs');
179 if(!empty($allSchedulers)) {
180 foreach($allSchedulers as $focus) {
181 if($focus->fireQualified()) {
182 $job = $focus->createJob();
183 $queue->submitJob($job, $this->getUser());
187 $GLOBALS['log']->debug('----->No Schedulers found');
192 * This function takes a Scheduler object and uses its job_interval
193 * attribute to derive DB-standard datetime strings, as many as are
194 * qualified by its ranges. The times are from the time of calling the
197 * @param $focus Scheduler object
198 * @return $dateTimes array loaded with DB datetime strings derived from
199 * the job_interval attribute
200 * @return false If we the Scheduler is not in scope, return false.
202 function deriveDBDateTimes($focus)
205 $GLOBALS['log']->debug('----->Schedulers->deriveDBDateTimes() got an object of type: '.$focus->object_name);
206 /* [min][hr][dates][mon][days] */
207 $dateTimes = array();
208 $ints = explode('::', str_replace(' ','',$focus->job_interval));
214 $today = getdate($timedate->getNow()->ts);
218 $GLOBALS['log']->debug('----->got * day');
220 } elseif(strstr($days, '*/')) {
221 // the "*/x" format is nonsensical for this field
222 // do basically nothing.
223 $theDay = str_replace('*/','',$days);
224 $dayName[] = $theDay;
225 } elseif($days != '*') { // got particular day(s)
226 if(strstr($days, ',')) {
227 $exDays = explode(',',$days);
228 foreach($exDays as $k1 => $dayGroup) {
229 if(strstr($dayGroup,'-')) {
230 $exDayGroup = explode('-', $dayGroup); // build up range and iterate through
231 for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) {
234 } else { // individuals
235 $dayName[] = $dayGroup;
238 } elseif(strstr($days, '-')) {
239 $exDayGroup = explode('-', $days); // build up range and iterate through
240 for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) {
247 // check the day to be in scope:
248 if(!in_array($today['wday'], $dayName)) {
256 // derive months part
258 $GLOBALS['log']->debug('----->got * months');
259 } elseif(strstr($mons, '*/')) {
260 $mult = str_replace('*/','',$mons);
261 $startMon = $timedate->fromDb(date_time_start)->month;
262 $startFrom = ($startMon % $mult);
264 for($i=$startFrom;$i<=12;$i+$mult) {
265 $compMons[] = $i+$mult;
268 // this month is not in one of the multiplier months
269 if(!in_array($today['mon'],$compMons)) {
272 } elseif($mons != '*') {
273 if(strstr($mons,',')) { // we have particular (groups) of months
274 $exMons = explode(',',$mons);
275 foreach($exMons as $k1 => $monGroup) {
276 if(strstr($monGroup, '-')) { // we have a range of months
277 $exMonGroup = explode('-',$monGroup);
278 for($i=$exMonGroup[0];$i<=$exMonGroup[1];$i++) {
282 $monName[] = $monGroup;
285 } elseif(strstr($mons, '-')) {
286 $exMonGroup = explode('-', $mons);
287 for($i=$exMonGroup[0];$i<=$exMonGroup[1];$i++) {
290 } else { // one particular month
294 // check that particular months are in scope
295 if(!in_array($today['mon'], $monName)) {
302 $GLOBALS['log']->debug('----->got * dates');
303 } elseif(strstr($dates, '*/')) {
304 $mult = str_replace('*/','',$dates);
305 $startDate = $timedate->fromDb($focus->date_time_start)->day;
306 $startFrom = ($startDate % $mult);
308 for($i=$startFrom; $i<=31; $i+$mult) {
309 $dateName[] = str_pad(($i+$mult),2,'0',STR_PAD_LEFT);
313 if(!in_array($today['mday'], $dateName)) {
316 } elseif($dates != '*') {
317 if(strstr($dates, ',')) {
318 $exDates = explode(',', $dates);
319 foreach($exDates as $k1 => $dateGroup) {
320 if(strstr($dateGroup, '-')) {
321 $exDateGroup = explode('-', $dateGroup);
322 for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) {
326 $dateName[] = $dateGroup;
329 } elseif(strstr($dates, '-')) {
330 $exDateGroup = explode('-', $dates);
331 for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) {
335 $dateName[] = $dates;
338 // check that dates are in scope
339 if(!in_array($today['mday'], $dateName)) {
345 //$currentHour = gmdate('G');
346 //$currentHour = date('G', strtotime('00:00'));
348 $GLOBALS['log']->debug('----->got * hours');
349 for($i=0;$i<24; $i++) {
352 } elseif(strstr($hrs, '*/')) {
353 $mult = str_replace('*/','',$hrs);
354 for($i=0; $i<24; $i) { // weird, i know
358 } elseif($hrs != '*') {
359 if(strstr($hrs, ',')) {
360 $exHrs = explode(',',$hrs);
361 foreach($exHrs as $k1 => $hrGroup) {
362 if(strstr($hrGroup, '-')) {
363 $exHrGroup = explode('-', $hrGroup);
364 for($i=$exHrGroup[0];$i<=$exHrGroup[1];$i++) {
368 $hrName[] = $hrGroup;
371 } elseif(strstr($hrs, '-')) {
372 $exHrs = explode('-', $hrs);
373 for($i=$exHrs[0];$i<=$exHrs[1];$i++) {
382 //$currentMin = date('i');
383 $currentMin = $timedate->getNow()->minute;
384 if(substr($currentMin, 0, 1) == '0') {
385 $currentMin = substr($currentMin, 1, 1);
388 $GLOBALS['log']->debug('----->got * mins');
389 for($i=0; $i<60; $i++) {
390 if(($currentMin + $i) > 59) {
391 $minName[] = ($i + $currentMin - 60);
393 $minName[] = ($i+$currentMin);
396 } elseif(strstr($mins,'*/')) {
397 $mult = str_replace('*/','',$mins);
398 $startMin = $timedate->fromDb($focus->date_time_start)->minute;
399 $startFrom = ($startMin % $mult);
400 for($i=$startFrom; $i<=59; $i) {
401 if(($currentMin + $i) > 59) {
402 $minName[] = ($i + $currentMin - 60);
404 $minName[] = ($i+$currentMin);
409 } elseif($mins != '*') {
410 if(strstr($mins, ',')) {
411 $exMins = explode(',',$mins);
412 foreach($exMins as $k1 => $minGroup) {
413 if(strstr($minGroup, '-')) {
414 $exMinGroup = explode('-', $minGroup);
415 for($i=$exMinGroup[0]; $i<=$exMinGroup[1]; $i++) {
419 $minName[] = $minGroup;
422 } elseif(strstr($mins, '-')) {
423 $exMinGroup = explode('-', $mins);
424 for($i=$exMinGroup[0]; $i<=$exMinGroup[1]; $i++) {
432 // prep some boundaries - these are not in GMT b/c gmt is a 24hour period, possibly bridging 2 local days
433 if(empty($focus->time_from) && empty($focus->time_to) ) {
435 $timeToTs = $timedate->getNow(true)->get('+1 day')->ts;
437 $tfrom = $timedate->fromDbType($focus->time_from, 'time');
438 $timeFromTs = $timedate->getNow(true)->setTime($tfrom->hour, $tfrom->min)->ts;
439 $tto = $timedate->fromDbType($focus->time_to, 'time');
440 $timeToTs = $timedate->getNow(true)->setTime($tto->hour, $tto->min)->ts;
444 if(empty($focus->last_run)) {
447 $lastRunTs = $timedate->fromDb($focus->last_run)->ts;
452 * initialize return array
454 $validJobTime = array();
457 $timeStartTs = $timedate->fromDb($focus->date_time_start)->ts;
458 if(!empty($focus->date_time_end)) { // do the same for date_time_end if not empty
459 $timeEndTs = $timedate->fromDb($focus->date_time_end)->ts;
461 $timeEndTs = $timedate->getNow(true)->get('+1 day')->ts;
462 // $dateTimeEnd = '2020-12-31 23:59:59'; // if empty, set it to something ridiculous
465 /*_pp('hours:'); _pp($hrName);_pp('mins:'); _pp($minName);*/
466 $dateobj = $timedate->getNow();
467 $nowTs = $dateobj->ts;
468 $GLOBALS['log']->debug(sprintf("Constraints: start: %s from: %s end: %s to: %s now: %s",
469 gmdate('Y-m-d H:i:s', $timeStartTs), gmdate('Y-m-d H:i:s', $timeFromTs), gmdate('Y-m-d H:i:s', $timeEndTs),
470 gmdate('Y-m-d H:i:s', $timeToTs), $timedate->nowDb()
472 // _pp('currentHour: '. $currentHour);
473 // _pp('timeStartTs: '.date('r',$timeStartTs));
474 // _pp('timeFromTs: '.date('r',$timeFromTs));
475 // _pp('timeEndTs: '.date('r',$timeEndTs));
476 // _pp('timeToTs: '.date('r',$timeToTs));
477 // _pp('mktime: '.date('r',mktime()));
478 // _pp('timeLastRun: '.date('r',$lastRunTs));
484 foreach($hrName as $kHr=>$hr) {
485 foreach($minName as $kMin=>$min) {
486 $timedate->tzUser($dateobj);
487 $dateobj->setTime($hr, $min, 0);
488 $tsGmt = $dateobj->ts;
490 if( $tsGmt >= $timeStartTs ) { // start is greater than the date specified by admin
491 if( $tsGmt >= $timeFromTs ) { // start is greater than the time_to spec'd by admin
492 if($tsGmt > $lastRunTs) { // start from last run, last run should not be included
493 if( $tsGmt <= $timeEndTs ) { // this is taken care of by the initial query - start is less than the date spec'd by admin
494 if( $tsGmt <= $timeToTs ) { // start is less than the time_to
495 $validJobTime[] = $dateobj->asDb();
497 //_pp('Job Time is NOT smaller that TimeTO: '.$tsGmt .'<='. $timeToTs);
500 //_pp('Job Time is NOT smaller that DateTimeEnd: '.date('Y-m-d H:i:s',$tsGmt) .'<='. $dateTimeEnd); //_pp( $tsGmt .'<='. $timeEndTs );
504 //_pp('Job Time is NOT bigger that TimeFrom: '.$tsGmt .'>='. $timeFromTs);
507 //_pp('Job Time is NOT Bigger than DateTimeStart: '.date('Y-m-d H:i',$tsGmt) .'>='. $dateTimeStart);
511 //_ppd($validJobTime);
512 // need ascending order to compare oldest time to last_run
515 * If "Execute If Missed bit is set
517 $now = TimeDate::getInstance()->getNow();
518 $now = $now->setTime($now->hour, $now->min, "00")->asDb();
520 if($focus->catch_up == 1) {
521 if($focus->last_run == null) {
523 $validJobTime[] = $now;
525 // determine what the interval in min/hours is
526 // see if last_run is in it
528 if(!empty($validJobTime) && ($focus->last_run < $validJobTime[0]) && ($now > $validJobTime[0])) {
529 // cn: empty() bug 5914;
530 // if(!empty) should be checked, becasue if a scheduler is defined to run every day 4pm, then after 4pm, and it runs as 4pm,
531 // the $validJobTime will be empty, and it should not catch up.
532 // If $focus->last_run is the the day before yesterday, it should run yesterday and tomorrow,
533 // but it hadn't run yesterday, then it should catch up today.
534 // But today is already filtered out when doing date check before. The catch up will not work on this occasion.
535 // If the scheduler runs at least one time on each day, I think this bug can be avoided.
536 $validJobTime[] = $now;
540 return $validJobTime;
543 function handleIntervalType($type, $value, $mins, $hours) {
545 /* [0]:min [1]:hour [2]:day of month [3]:month [4]:day of week */
546 $days = array ( 1 => $mod_strings['LBL_MON'],
547 2 => $mod_strings['LBL_TUE'],
548 3 => $mod_strings['LBL_WED'],
549 4 => $mod_strings['LBL_THU'],
550 5 => $mod_strings['LBL_FRI'],
551 6 => $mod_strings['LBL_SAT'],
552 0 => $mod_strings['LBL_SUN'],
553 '*' => $mod_strings['LBL_ALL']);
558 return trim($mod_strings['LBL_ON_THE']).$mod_strings['LBL_HOUR_SING'];
559 } elseif(!preg_match('/[^0-9]/', $hours) && !preg_match('/[^0-9]/', $value)) {
562 } elseif(preg_match('/\*\//', $value)) {
563 $value = str_replace('*/','',$value);
564 return $value.$mod_strings['LBL_MINUTES'];
565 } elseif(!preg_match('[^0-9]', $value)) {
566 return $mod_strings['LBL_ON_THE'].$value.$mod_strings['LBL_MIN_MARK'];
571 global $current_user;
572 if(preg_match('/\*\//', $value)) { // every [SOME INTERVAL] hours
573 $value = str_replace('*/','',$value);
574 return $value.$mod_strings['LBL_HOUR'];
575 } elseif(preg_match('/[^0-9]/', $mins)) { // got a range, or multiple of mins, so we return an 'Hours' label
577 } else { // got a "minutes" setting, so it will be at some o'clock.
578 $datef = $current_user->getUserDateTimePreferences();
579 return date($datef['time'], strtotime($value.':'.str_pad($mins, 2, '0', STR_PAD_LEFT)));
581 case 2: // day of month
582 if(preg_match('/\*/', $value)) {
585 return date('jS', strtotime('December '.$value));
589 return date('F', strtotime('2005-'.$value.'-01'));
590 case 4: // days of week
591 return $days[$value];
593 return 'bad'; // no condition to touch this branch
597 function setIntervalHumanReadable() {
598 global $current_user;
601 /* [0]:min [1]:hour [2]:day of month [3]:month [4]:day of week */
602 $ints = $this->intervalParsed;
603 $intVal = array('-', ',');
604 $intSub = array($mod_strings['LBL_RANGE'], $mod_strings['LBL_AND']);
605 $intInt = array(0 => $mod_strings['LBL_MINS'], 1 => $mod_strings['LBL_HOUR']);
609 foreach($ints['raw'] as $key => $interval) {
610 if($tempInt != $iteration) {
613 $iteration = $tempInt;
615 if($interval != '*' && $interval != '*/1') {
616 if(false !== strpos($interval, ',')) {
617 $exIndiv = explode(',', $interval);
618 foreach($exIndiv as $val) {
619 if(false !== strpos($val, '-')) {
620 $exRange = explode('-', $val);
621 foreach($exRange as $valRange) {
623 $tempInt .= $mod_strings['LBL_AND'];
625 $tempInt .= $this->handleIntervalType($key, $valRange, $ints['raw'][0], $ints['raw'][1]);
627 } elseif($tempInt != $iteration) {
628 $tempInt .= $mod_strings['LBL_AND'];
630 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
632 } elseif(false !== strpos($interval, '-')) {
633 $exRange = explode('-', $interval);
634 $tempInt .= $mod_strings['LBL_FROM'];
637 foreach($exRange as $val) {
638 if($tempInt == $check) {
639 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
640 $tempInt .= $mod_strings['LBL_RANGE'];
643 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
647 } elseif(false !== strpos($interval, '*/')) {
648 $tempInt .= $mod_strings['LBL_EVERY'];
649 $tempInt .= $this->handleIntervalType($key, $interval, $ints['raw'][0], $ints['raw'][1]);
651 $tempInt .= $this->handleIntervalType($key, $interval, $ints['raw'][0], $ints['raw'][1]);
657 $this->intervalHumanReadable = $mod_strings['LBL_OFTEN'];
659 $tempInt = trim($tempInt);
660 if(';' == substr($tempInt, (strlen($tempInt)-1), strlen($tempInt))) {
661 $tempInt = substr($tempInt, 0, (strlen($tempInt)-1));
663 $this->intervalHumanReadable = $tempInt;
668 /* take an integer and return its suffix */
669 function setStandardArraysAttributes() {
671 global $app_list_strings; // using from month _dom list
673 $suffArr = array('','st','nd','rd');
674 for($i=1; $i<32; $i++) {
675 if($i > 3 && $i < 21) {
676 $this->suffixArray[$i] = $i."th";
677 } elseif (substr($i,-1,1) < 4 && substr($i,-1,1) > 0) {
678 $this->suffixArray[$i] = $i.$suffArr[substr($i,-1,1)];
680 $this->suffixArray[$i] = $i."th";
682 $this->datesArray[$i] = $i;
685 $this->dayInt = array('*',1,2,3,4,5,6,0);
686 $this->dayLabel = array('*',$mod_strings['LBL_MON'],$mod_strings['LBL_TUE'],$mod_strings['LBL_WED'],$mod_strings['LBL_THU'],$mod_strings['LBL_FRI'],$mod_strings['LBL_SAT'],$mod_strings['LBL_SUN']);
687 $this->monthsInt = array(0,1,2,3,4,5,6,7,8,9,10,11,12);
688 $this->monthsLabel = $app_list_strings['dom_cal_month_long'];
689 $this->metricsVar = array("*", "/", "-", ",");
690 $this->metricsVal = array(' every ','',' thru ',' and ');
694 * takes the serialized interval string and renders it into an array
696 function parseInterval() {
698 $ws = array(' ', '\r','\t');
699 $blanks = array('','','');
701 $intv = $this->job_interval;
702 $rawValues = explode('::', $intv);
703 $rawProcessed = str_replace($ws,$blanks,$rawValues); // strip all whitespace
705 $hours = $rawValues[1].':::'.$rawValues[0];
706 $months = $rawValues[3].':::'.$rawValues[2];
708 $intA = array ( 'raw' => $rawProcessed,
713 $this->intervalParsed = $intA;
717 * checks for cURL libraries
719 function checkCurl() {
722 if(!function_exists('curl_init')) {
724 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
726 <th width="25%" colspan="2"><slot>
727 '.$mod_strings['LBL_WARN_CURL_TITLE'].'
730 <tr class="oddListRowS1" >
731 <td scope="row" valign=TOP width="20%"><slot>
732 '.$mod_strings['LBL_WARN_CURL'].'
733 <td scope="row" valign=TOP width="80%"><slot>
734 <span class=error>'.$mod_strings['LBL_WARN_NO_CURL'].'</span>
742 function displayCronInstructions() {
744 global $sugar_config;
746 if (!isset($_SERVER['Path'])) {
747 $_SERVER['Path'] = getenv('Path');
750 if(isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // IIS IUSR_xxx may not have access to Path or it is not set
751 if(!strpos($_SERVER['Path'], 'php')) {
752 // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>';
756 if(isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // some Linux servers do not make this available
757 if(!strpos($_SERVER['PATH'], 'php')) {
758 // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>';
768 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
771 '.$mod_strings['LBL_CRON_INSTRUCTIONS_WINDOWS'].'
774 <tr class="evenListRowS1">
775 <td scope="row" valign="top" width="70%"><slot>
776 '.$mod_strings['LBL_CRON_WINDOWS_DESC'].'<br>
777 <b>cd '.realpath('./').'<br>
778 php.exe -f cron.php</b>
785 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
788 '.$mod_strings['LBL_CRON_INSTRUCTIONS_LINUX'].'
792 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#fdfdfd" width="70%"><slot>
793 '.$mod_strings['LBL_CRON_LINUX_DESC'].'<br>
794 <b>* * * * *
795 cd '.realpath('./').'; php -f cron.php > /dev/null 2>&1</b>
804 * Archives schedulers of the same functionality, then instantiates new
807 function rebuildDefaultSchedulers() {
808 $mod_strings = return_module_language($GLOBALS['current_language'], 'Schedulers');
809 // truncate scheduler-related tables
810 $this->db->query('DELETE FROM schedulers');
813 $sched3 = new Scheduler();
814 $sched3->name = $mod_strings['LBL_OOTB_TRACKER'];
815 $sched3->job = 'function::trimTracker';
816 $sched3->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
817 $sched3->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
818 $sched3->job_interval = '0::2::1::*::*';
819 $sched3->status = 'Active';
820 $sched3->created_by = '1';
821 $sched3->modified_user_id = '1';
822 $sched3->catch_up = '1';
824 $sched4 = new Scheduler();
825 $sched4->name = $mod_strings['LBL_OOTB_IE'];
826 $sched4->job = 'function::pollMonitoredInboxes';
827 $sched4->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
828 $sched4->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
829 $sched4->job_interval = '*::*::*::*::*';
830 $sched4->status = 'Active';
831 $sched4->created_by = '1';
832 $sched4->modified_user_id = '1';
833 $sched4->catch_up = '0';
836 $sched5 = new Scheduler();
837 $sched5->name = $mod_strings['LBL_OOTB_BOUNCE'];
838 $sched5->job = 'function::pollMonitoredInboxesForBouncedCampaignEmails';
839 $sched5->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
840 $sched5->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
841 $sched5->job_interval = '0::2-6::*::*::*';
842 $sched5->status = 'Active';
843 $sched5->created_by = '1';
844 $sched5->modified_user_id = '1';
845 $sched5->catch_up = '1';
848 $sched6 = new Scheduler();
849 $sched6->name = $mod_strings['LBL_OOTB_CAMPAIGN'];
850 $sched6->job = 'function::runMassEmailCampaign';
851 $sched6->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
852 $sched6->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
853 $sched6->job_interval = '0::2-6::*::*::*';
854 $sched6->status = 'Active';
855 $sched6->created_by = '1';
856 $sched6->modified_user_id = '1';
857 $sched6->catch_up = '1';
861 $sched7 = new Scheduler();
862 $sched7->name = $mod_strings['LBL_OOTB_PRUNE'];
863 $sched7->job = 'function::pruneDatabase';
864 $sched7->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
865 $sched7->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
866 $sched7->job_interval = '0::4::1::*::*';
867 $sched7->status = 'Inactive';
868 $sched7->created_by = '1';
869 $sched7->modified_user_id = '1';
870 $sched7->catch_up = '0';
876 $sched12 = new Scheduler();
877 $sched12->name = $mod_strings['LBL_OOTB_SEND_EMAIL_REMINDERS'];
878 $sched12->job = 'function::sendEmailReminders';
879 $sched12->date_time_start = create_date(2008,1,1) . ' ' . create_time(0,0,1);
880 $sched12->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
881 $sched12->job_interval = '*::*::*::*::*';
882 $sched12->status = 'Active';
883 $sched12->created_by = '1';
884 $sched12->modified_user_id = '1';
885 $sched12->catch_up = '0';
888 $sched13 = new Scheduler();
889 $sched13->name = $mod_strings['LBL_OOTB_CLEANUP_QUEUE'];
890 $sched13->job = 'function::cleanJobQueue';
891 $sched13->date_time_start = create_date(2012,1,1) . ' ' . create_time(0,0,1);
892 $sched13->date_time_end = create_date(2030,12,31) . ' ' . create_time(23,59,59);
893 $sched13->job_interval = '0::5::*::*::*';
894 $sched13->status = 'Active';
895 $sched13->created_by = '1';
896 $sched13->modified_user_id = '1';
897 $sched13->catch_up = '0';
901 //// END SCHEDULER HELPER FUNCTIONS
902 ///////////////////////////////////////////////////////////////////////////
905 ///////////////////////////////////////////////////////////////////////////
906 //// STANDARD SUGARBEAN OVERRIDES
908 * function overrides the one in SugarBean.php
910 function create_export_query($order_by, $where, $show_deleted = 0) {
911 return $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted = 0);
915 * function overrides the one in SugarBean.php
919 * function overrides the one in SugarBean.php
921 function fill_in_additional_list_fields() {
922 $this->fill_in_additional_detail_fields();
926 * function overrides the one in SugarBean.php
928 function fill_in_additional_detail_fields() {
932 * function overrides the one in SugarBean.php
934 function get_list_view_data()
937 $temp_array = $this->get_list_view_array();
938 $temp_array["ENCODED_NAME"]=$this->name;
939 $this->parseInterval();
940 $this->setIntervalHumanReadable();
941 $temp_array['JOB_INTERVAL'] = $this->intervalHumanReadable;
942 if($this->date_time_end == '2020-12-31 23:59' || $this->date_time_end == '') {
943 $temp_array['DATE_TIME_END'] = $mod_strings['LBL_PERENNIAL'];
945 $this->created_by_name = get_assigned_user_name($this->created_by);
946 $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
952 * returns the bean name - overrides SugarBean's
954 function get_summary_text()
958 //// END STANDARD SUGARBEAN OVERRIDES
959 ///////////////////////////////////////////////////////////////////////////
960 static public function getJobsList()
962 if(empty(self::$job_strings)) {
964 include_once('modules/Schedulers/_AddJobsHere.php');
967 self::$job_strings = array('url::' => 'URL');
968 foreach($job_strings as $k=>$v){
969 self::$job_strings['function::' . $v] = $mod_strings['LBL_'.strtoupper($v)];
972 return self::$job_strings;
974 } // end class definition