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)) {
94 $this->user = Scheduler::initUser();
100 * Function returns an Admin user for running Schedulers or false if no admin users are present in the system
101 * (which means the Scheduler Jobs which need admin rights will fail to execute)
103 public static function initUser()
106 $db = DBManagerFactory::getInstance();
108 //Check is default admin exists
109 $adminId = $db->getOne(
110 'SELECT id FROM users WHERE id = ' . $db->quoted('1') . ' AND is_admin = 1 AND deleted = 0 AND status = ' . $db->quoted('Active'),
112 'Error retrieving Admin account info'
115 if ($adminId === false) {// Retrieve another admin if default admin doesn't exist
116 $adminId = $db->getOne(
117 'SELECT id FROM users WHERE is_admin = 1 AND deleted = 0 AND status = ' . $db->quoted('Active'),
119 'Error retrieving Admin account info'
121 if ($adminId) {// Get admin user
122 $user->retrieve($adminId);
123 } else {// Return false and log error
124 $GLOBALS['log']->fatal('No Admin account found!');
127 } else {// Scheduler jobs run as default Admin
128 $user->retrieve('1');
134 ///////////////////////////////////////////////////////////////////////////
135 //// SCHEDULER HELPER FUNCTIONS
138 * calculates if a job is qualified to run
140 public function fireQualified()
142 if(empty($this->id)) { // execute only if we have an instance
143 $GLOBALS['log']->fatal('Scheduler called fireQualified() in a non-instance');
147 $now = TimeDate::getInstance()->getNow();
148 $now = $now->setTime($now->hour, $now->min, "00")->asDb();
149 $validTimes = $this->deriveDBDateTimes($this);
151 if(is_array($validTimes) && in_array($now, $validTimes)) {
152 $GLOBALS['log']->debug('----->Scheduler found valid job ('.$this->name.') for time GMT('.$now.')');
155 $GLOBALS['log']->debug('----->Scheduler did NOT find valid job ('.$this->name.') for time GMT('.$now.')');
161 * Create a job from this scheduler
162 * @return SchedulersJob
164 public function createJob()
166 $job = new SchedulersJob();
167 $job->scheduler_id = $this->id;
168 $job->name = $this->name;
169 $job->execute_time = $GLOBALS['timedate']->nowDb();
170 $job->assigned_user_id = $this->getUser()->id;
171 $job->target = $this->job;
176 * Checks if any jobs qualify to run at this moment
177 * @param SugarJobQueue $queue
179 public function checkPendingJobs($queue)
181 $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."')");
183 $GLOBALS['log']->info('-----> Scheduler found [ '.count($allSchedulers).' ] ACTIVE jobs');
185 if(!empty($allSchedulers)) {
186 foreach($allSchedulers as $focus) {
187 if($focus->fireQualified()) {
188 $job = $focus->createJob();
189 $queue->submitJob($job, $this->getUser());
193 $GLOBALS['log']->debug('----->No Schedulers found');
198 * This function takes a Scheduler object and uses its job_interval
199 * attribute to derive DB-standard datetime strings, as many as are
200 * qualified by its ranges. The times are from the time of calling the
203 * @param $focus Scheduler object
204 * @return $dateTimes array loaded with DB datetime strings derived from
205 * the job_interval attribute
206 * @return false If we the Scheduler is not in scope, return false.
208 function deriveDBDateTimes($focus)
211 $GLOBALS['log']->debug('----->Schedulers->deriveDBDateTimes() got an object of type: '.$focus->object_name);
212 /* [min][hr][dates][mon][days] */
213 $dateTimes = array();
214 $ints = explode('::', str_replace(' ','',$focus->job_interval));
220 $today = getdate($timedate->getNow()->ts);
224 $GLOBALS['log']->debug('----->got * day');
226 } elseif(strstr($days, '*/')) {
227 // the "*/x" format is nonsensical for this field
228 // do basically nothing.
229 $theDay = str_replace('*/','',$days);
230 $dayName[] = $theDay;
231 } elseif($days != '*') { // got particular day(s)
232 if(strstr($days, ',')) {
233 $exDays = explode(',',$days);
234 foreach($exDays as $k1 => $dayGroup) {
235 if(strstr($dayGroup,'-')) {
236 $exDayGroup = explode('-', $dayGroup); // build up range and iterate through
237 for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) {
240 } else { // individuals
241 $dayName[] = $dayGroup;
244 } elseif(strstr($days, '-')) {
245 $exDayGroup = explode('-', $days); // build up range and iterate through
246 for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) {
253 // check the day to be in scope:
254 if(!in_array($today['wday'], $dayName)) {
262 // derive months part
264 $GLOBALS['log']->debug('----->got * months');
265 } elseif(strstr($mons, '*/')) {
266 $mult = str_replace('*/','',$mons);
267 $startMon = $timedate->fromDb(date_time_start)->month;
268 $startFrom = ($startMon % $mult);
270 for($i=$startFrom;$i<=12;$i+$mult) {
271 $compMons[] = $i+$mult;
274 // this month is not in one of the multiplier months
275 if(!in_array($today['mon'],$compMons)) {
278 } elseif($mons != '*') {
279 if(strstr($mons,',')) { // we have particular (groups) of months
280 $exMons = explode(',',$mons);
281 foreach($exMons as $k1 => $monGroup) {
282 if(strstr($monGroup, '-')) { // we have a range of months
283 $exMonGroup = explode('-',$monGroup);
284 for($i=$exMonGroup[0];$i<=$exMonGroup[1];$i++) {
288 $monName[] = $monGroup;
291 } elseif(strstr($mons, '-')) {
292 $exMonGroup = explode('-', $mons);
293 for($i=$exMonGroup[0];$i<=$exMonGroup[1];$i++) {
296 } else { // one particular month
300 // check that particular months are in scope
301 if(!in_array($today['mon'], $monName)) {
308 $GLOBALS['log']->debug('----->got * dates');
309 } elseif(strstr($dates, '*/')) {
310 $mult = str_replace('*/','',$dates);
311 $startDate = $timedate->fromDb($focus->date_time_start)->day;
312 $startFrom = ($startDate % $mult);
314 for($i=$startFrom; $i<=31; $i+$mult) {
315 $dateName[] = str_pad(($i+$mult),2,'0',STR_PAD_LEFT);
319 if(!in_array($today['mday'], $dateName)) {
322 } elseif($dates != '*') {
323 if(strstr($dates, ',')) {
324 $exDates = explode(',', $dates);
325 foreach($exDates as $k1 => $dateGroup) {
326 if(strstr($dateGroup, '-')) {
327 $exDateGroup = explode('-', $dateGroup);
328 for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) {
332 $dateName[] = $dateGroup;
335 } elseif(strstr($dates, '-')) {
336 $exDateGroup = explode('-', $dates);
337 for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) {
341 $dateName[] = $dates;
344 // check that dates are in scope
345 if(!in_array($today['mday'], $dateName)) {
351 //$currentHour = gmdate('G');
352 //$currentHour = date('G', strtotime('00:00'));
354 $GLOBALS['log']->debug('----->got * hours');
355 for($i=0;$i<24; $i++) {
358 } elseif(strstr($hrs, '*/')) {
359 $mult = str_replace('*/','',$hrs);
360 for($i=0; $i<24; $i) { // weird, i know
364 } elseif($hrs != '*') {
365 if(strstr($hrs, ',')) {
366 $exHrs = explode(',',$hrs);
367 foreach($exHrs as $k1 => $hrGroup) {
368 if(strstr($hrGroup, '-')) {
369 $exHrGroup = explode('-', $hrGroup);
370 for($i=$exHrGroup[0];$i<=$exHrGroup[1];$i++) {
374 $hrName[] = $hrGroup;
377 } elseif(strstr($hrs, '-')) {
378 $exHrs = explode('-', $hrs);
379 for($i=$exHrs[0];$i<=$exHrs[1];$i++) {
388 //$currentMin = date('i');
389 $currentMin = $timedate->getNow()->minute;
390 if(substr($currentMin, 0, 1) == '0') {
391 $currentMin = substr($currentMin, 1, 1);
394 $GLOBALS['log']->debug('----->got * mins');
395 for($i=0; $i<60; $i++) {
396 if(($currentMin + $i) > 59) {
397 $minName[] = ($i + $currentMin - 60);
399 $minName[] = ($i+$currentMin);
402 } elseif(strstr($mins,'*/')) {
403 $mult = str_replace('*/','',$mins);
404 $startMin = $timedate->fromDb($focus->date_time_start)->minute;
405 $startFrom = ($startMin % $mult);
406 for($i=$startFrom; $i<=59; $i) {
407 if(($currentMin + $i) > 59) {
408 $minName[] = ($i + $currentMin - 60);
410 $minName[] = ($i+$currentMin);
415 } elseif($mins != '*') {
416 if(strstr($mins, ',')) {
417 $exMins = explode(',',$mins);
418 foreach($exMins as $k1 => $minGroup) {
419 if(strstr($minGroup, '-')) {
420 $exMinGroup = explode('-', $minGroup);
421 for($i=$exMinGroup[0]; $i<=$exMinGroup[1]; $i++) {
425 $minName[] = $minGroup;
428 } elseif(strstr($mins, '-')) {
429 $exMinGroup = explode('-', $mins);
430 for($i=$exMinGroup[0]; $i<=$exMinGroup[1]; $i++) {
438 // prep some boundaries - these are not in GMT b/c gmt is a 24hour period, possibly bridging 2 local days
439 if(empty($focus->time_from) && empty($focus->time_to) ) {
441 $timeToTs = $timedate->getNow(true)->get('+1 day')->ts;
443 $tfrom = $timedate->fromDbType($focus->time_from, 'time');
444 $timeFromTs = $timedate->getNow(true)->setTime($tfrom->hour, $tfrom->min)->ts;
445 $tto = $timedate->fromDbType($focus->time_to, 'time');
446 $timeToTs = $timedate->getNow(true)->setTime($tto->hour, $tto->min)->ts;
450 if(empty($focus->last_run)) {
453 $lastRunTs = $timedate->fromDb($focus->last_run)->ts;
458 * initialize return array
460 $validJobTime = array();
463 $timeStartTs = $timedate->fromDb($focus->date_time_start)->ts;
464 if(!empty($focus->date_time_end)) { // do the same for date_time_end if not empty
465 $timeEndTs = $timedate->fromDb($focus->date_time_end)->ts;
467 $timeEndTs = $timedate->getNow(true)->get('+1 day')->ts;
468 // $dateTimeEnd = '2020-12-31 23:59:59'; // if empty, set it to something ridiculous
471 /*_pp('hours:'); _pp($hrName);_pp('mins:'); _pp($minName);*/
472 $dateobj = $timedate->getNow();
473 $nowTs = $dateobj->ts;
474 $GLOBALS['log']->debug(sprintf("Constraints: start: %s from: %s end: %s to: %s now: %s",
475 gmdate('Y-m-d H:i:s', $timeStartTs), gmdate('Y-m-d H:i:s', $timeFromTs), gmdate('Y-m-d H:i:s', $timeEndTs),
476 gmdate('Y-m-d H:i:s', $timeToTs), $timedate->nowDb()
478 // _pp('currentHour: '. $currentHour);
479 // _pp('timeStartTs: '.date('r',$timeStartTs));
480 // _pp('timeFromTs: '.date('r',$timeFromTs));
481 // _pp('timeEndTs: '.date('r',$timeEndTs));
482 // _pp('timeToTs: '.date('r',$timeToTs));
483 // _pp('mktime: '.date('r',mktime()));
484 // _pp('timeLastRun: '.date('r',$lastRunTs));
490 foreach($hrName as $kHr=>$hr) {
491 foreach($minName as $kMin=>$min) {
492 $timedate->tzUser($dateobj);
493 $dateobj->setTime($hr, $min, 0);
494 $tsGmt = $dateobj->ts;
496 if( $tsGmt >= $timeStartTs ) { // start is greater than the date specified by admin
497 if( $tsGmt >= $timeFromTs ) { // start is greater than the time_to spec'd by admin
498 if($tsGmt > $lastRunTs) { // start from last run, last run should not be included
499 if( $tsGmt <= $timeEndTs ) { // this is taken care of by the initial query - start is less than the date spec'd by admin
500 if( $tsGmt <= $timeToTs ) { // start is less than the time_to
501 $validJobTime[] = $dateobj->asDb();
503 //_pp('Job Time is NOT smaller that TimeTO: '.$tsGmt .'<='. $timeToTs);
506 //_pp('Job Time is NOT smaller that DateTimeEnd: '.date('Y-m-d H:i:s',$tsGmt) .'<='. $dateTimeEnd); //_pp( $tsGmt .'<='. $timeEndTs );
510 //_pp('Job Time is NOT bigger that TimeFrom: '.$tsGmt .'>='. $timeFromTs);
513 //_pp('Job Time is NOT Bigger than DateTimeStart: '.date('Y-m-d H:i',$tsGmt) .'>='. $dateTimeStart);
517 //_ppd($validJobTime);
518 // need ascending order to compare oldest time to last_run
521 * If "Execute If Missed bit is set
523 $now = TimeDate::getInstance()->getNow();
524 $now = $now->setTime($now->hour, $now->min, "00")->asDb();
526 if($focus->catch_up == 1) {
527 if($focus->last_run == null) {
529 $validJobTime[] = $now;
531 // determine what the interval in min/hours is
532 // see if last_run is in it
534 if(!empty($validJobTime) && ($focus->last_run < $validJobTime[0]) && ($now > $validJobTime[0])) {
535 // cn: empty() bug 5914;
536 // if(!empty) should be checked, becasue if a scheduler is defined to run every day 4pm, then after 4pm, and it runs as 4pm,
537 // the $validJobTime will be empty, and it should not catch up.
538 // If $focus->last_run is the the day before yesterday, it should run yesterday and tomorrow,
539 // but it hadn't run yesterday, then it should catch up today.
540 // But today is already filtered out when doing date check before. The catch up will not work on this occasion.
541 // If the scheduler runs at least one time on each day, I think this bug can be avoided.
542 $validJobTime[] = $now;
546 return $validJobTime;
549 function handleIntervalType($type, $value, $mins, $hours) {
551 /* [0]:min [1]:hour [2]:day of month [3]:month [4]:day of week */
552 $days = array ( 1 => $mod_strings['LBL_MON'],
553 2 => $mod_strings['LBL_TUE'],
554 3 => $mod_strings['LBL_WED'],
555 4 => $mod_strings['LBL_THU'],
556 5 => $mod_strings['LBL_FRI'],
557 6 => $mod_strings['LBL_SAT'],
558 0 => $mod_strings['LBL_SUN'],
559 '*' => $mod_strings['LBL_ALL']);
564 return trim($mod_strings['LBL_ON_THE']).$mod_strings['LBL_HOUR_SING'];
565 } elseif(!preg_match('/[^0-9]/', $hours) && !preg_match('/[^0-9]/', $value)) {
568 } elseif(preg_match('/\*\//', $value)) {
569 $value = str_replace('*/','',$value);
570 return $value.$mod_strings['LBL_MINUTES'];
571 } elseif(!preg_match('[^0-9]', $value)) {
572 return $mod_strings['LBL_ON_THE'].$value.$mod_strings['LBL_MIN_MARK'];
577 global $current_user;
578 if(preg_match('/\*\//', $value)) { // every [SOME INTERVAL] hours
579 $value = str_replace('*/','',$value);
580 return $value.$mod_strings['LBL_HOUR'];
581 } elseif(preg_match('/[^0-9]/', $mins)) { // got a range, or multiple of mins, so we return an 'Hours' label
583 } else { // got a "minutes" setting, so it will be at some o'clock.
584 $datef = $current_user->getUserDateTimePreferences();
585 return date($datef['time'], strtotime($value.':'.str_pad($mins, 2, '0', STR_PAD_LEFT)));
587 case 2: // day of month
588 if(preg_match('/\*/', $value)) {
591 return date('jS', strtotime('December '.$value));
595 return date('F', strtotime('2005-'.$value.'-01'));
596 case 4: // days of week
597 return $days[$value];
599 return 'bad'; // no condition to touch this branch
603 function setIntervalHumanReadable() {
604 global $current_user;
607 /* [0]:min [1]:hour [2]:day of month [3]:month [4]:day of week */
608 $ints = $this->intervalParsed;
609 $intVal = array('-', ',');
610 $intSub = array($mod_strings['LBL_RANGE'], $mod_strings['LBL_AND']);
611 $intInt = array(0 => $mod_strings['LBL_MINS'], 1 => $mod_strings['LBL_HOUR']);
615 foreach($ints['raw'] as $key => $interval) {
616 if($tempInt != $iteration) {
619 $iteration = $tempInt;
621 if($interval != '*' && $interval != '*/1') {
622 if(false !== strpos($interval, ',')) {
623 $exIndiv = explode(',', $interval);
624 foreach($exIndiv as $val) {
625 if(false !== strpos($val, '-')) {
626 $exRange = explode('-', $val);
627 foreach($exRange as $valRange) {
629 $tempInt .= $mod_strings['LBL_AND'];
631 $tempInt .= $this->handleIntervalType($key, $valRange, $ints['raw'][0], $ints['raw'][1]);
633 } elseif($tempInt != $iteration) {
634 $tempInt .= $mod_strings['LBL_AND'];
636 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
638 } elseif(false !== strpos($interval, '-')) {
639 $exRange = explode('-', $interval);
640 $tempInt .= $mod_strings['LBL_FROM'];
643 foreach($exRange as $val) {
644 if($tempInt == $check) {
645 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
646 $tempInt .= $mod_strings['LBL_RANGE'];
649 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
653 } elseif(false !== strpos($interval, '*/')) {
654 $tempInt .= $mod_strings['LBL_EVERY'];
655 $tempInt .= $this->handleIntervalType($key, $interval, $ints['raw'][0], $ints['raw'][1]);
657 $tempInt .= $this->handleIntervalType($key, $interval, $ints['raw'][0], $ints['raw'][1]);
663 $this->intervalHumanReadable = $mod_strings['LBL_OFTEN'];
665 $tempInt = trim($tempInt);
666 if(';' == substr($tempInt, (strlen($tempInt)-1), strlen($tempInt))) {
667 $tempInt = substr($tempInt, 0, (strlen($tempInt)-1));
669 $this->intervalHumanReadable = $tempInt;
674 /* take an integer and return its suffix */
675 function setStandardArraysAttributes() {
677 global $app_list_strings; // using from month _dom list
679 $suffArr = array('','st','nd','rd');
680 for($i=1; $i<32; $i++) {
681 if($i > 3 && $i < 21) {
682 $this->suffixArray[$i] = $i."th";
683 } elseif (substr($i,-1,1) < 4 && substr($i,-1,1) > 0) {
684 $this->suffixArray[$i] = $i.$suffArr[substr($i,-1,1)];
686 $this->suffixArray[$i] = $i."th";
688 $this->datesArray[$i] = $i;
691 $this->dayInt = array('*',1,2,3,4,5,6,0);
692 $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']);
693 $this->monthsInt = array(0,1,2,3,4,5,6,7,8,9,10,11,12);
694 $this->monthsLabel = $app_list_strings['dom_cal_month_long'];
695 $this->metricsVar = array("*", "/", "-", ",");
696 $this->metricsVal = array(' every ','',' thru ',' and ');
700 * takes the serialized interval string and renders it into an array
702 function parseInterval() {
704 $ws = array(' ', '\r','\t');
705 $blanks = array('','','');
707 $intv = $this->job_interval;
708 $rawValues = explode('::', $intv);
709 $rawProcessed = str_replace($ws,$blanks,$rawValues); // strip all whitespace
711 $hours = $rawValues[1].':::'.$rawValues[0];
712 $months = $rawValues[3].':::'.$rawValues[2];
714 $intA = array ( 'raw' => $rawProcessed,
719 $this->intervalParsed = $intA;
723 * checks for cURL libraries
725 function checkCurl() {
728 if(!function_exists('curl_init')) {
730 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
732 <th width="25%" colspan="2"><slot>
733 '.$mod_strings['LBL_WARN_CURL_TITLE'].'
736 <tr class="oddListRowS1" >
737 <td scope="row" valign=TOP width="20%"><slot>
738 '.$mod_strings['LBL_WARN_CURL'].'
739 <td scope="row" valign=TOP width="80%"><slot>
740 <span class=error>'.$mod_strings['LBL_WARN_NO_CURL'].'</span>
748 function displayCronInstructions() {
750 global $sugar_config;
752 if (!isset($_SERVER['Path'])) {
753 $_SERVER['Path'] = getenv('Path');
756 if(isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // IIS IUSR_xxx may not have access to Path or it is not set
757 if(!strpos($_SERVER['Path'], 'php')) {
758 // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>';
762 if(isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // some Linux servers do not make this available
763 if(!strpos($_SERVER['PATH'], 'php')) {
764 // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>';
774 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
777 '.$mod_strings['LBL_CRON_INSTRUCTIONS_WINDOWS'].'
780 <tr class="evenListRowS1">
781 <td scope="row" valign="top" width="70%"><slot>
782 '.$mod_strings['LBL_CRON_WINDOWS_DESC'].'<br>
783 <b>cd '.realpath('./').'<br>
784 php.exe -f cron.php</b>
791 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
794 '.$mod_strings['LBL_CRON_INSTRUCTIONS_LINUX'].'
798 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#fdfdfd" width="70%"><slot>
799 '.$mod_strings['LBL_CRON_LINUX_DESC'].'<br>
800 <b>* * * * *
801 cd '.realpath('./').'; php -f cron.php > /dev/null 2>&1</b>
810 * Archives schedulers of the same functionality, then instantiates new
813 function rebuildDefaultSchedulers() {
814 $mod_strings = return_module_language($GLOBALS['current_language'], 'Schedulers');
815 // truncate scheduler-related tables
816 $this->db->query('DELETE FROM schedulers');
819 $sched3 = new Scheduler();
820 $sched3->name = $mod_strings['LBL_OOTB_TRACKER'];
821 $sched3->job = 'function::trimTracker';
822 $sched3->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
823 $sched3->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
824 $sched3->job_interval = '0::2::1::*::*';
825 $sched3->status = 'Active';
826 $sched3->created_by = '1';
827 $sched3->modified_user_id = '1';
828 $sched3->catch_up = '1';
830 $sched4 = new Scheduler();
831 $sched4->name = $mod_strings['LBL_OOTB_IE'];
832 $sched4->job = 'function::pollMonitoredInboxes';
833 $sched4->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
834 $sched4->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
835 $sched4->job_interval = '*::*::*::*::*';
836 $sched4->status = 'Active';
837 $sched4->created_by = '1';
838 $sched4->modified_user_id = '1';
839 $sched4->catch_up = '0';
842 $sched5 = new Scheduler();
843 $sched5->name = $mod_strings['LBL_OOTB_BOUNCE'];
844 $sched5->job = 'function::pollMonitoredInboxesForBouncedCampaignEmails';
845 $sched5->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
846 $sched5->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
847 $sched5->job_interval = '0::2-6::*::*::*';
848 $sched5->status = 'Active';
849 $sched5->created_by = '1';
850 $sched5->modified_user_id = '1';
851 $sched5->catch_up = '1';
854 $sched6 = new Scheduler();
855 $sched6->name = $mod_strings['LBL_OOTB_CAMPAIGN'];
856 $sched6->job = 'function::runMassEmailCampaign';
857 $sched6->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
858 $sched6->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
859 $sched6->job_interval = '0::2-6::*::*::*';
860 $sched6->status = 'Active';
861 $sched6->created_by = '1';
862 $sched6->modified_user_id = '1';
863 $sched6->catch_up = '1';
867 $sched7 = new Scheduler();
868 $sched7->name = $mod_strings['LBL_OOTB_PRUNE'];
869 $sched7->job = 'function::pruneDatabase';
870 $sched7->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
871 $sched7->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
872 $sched7->job_interval = '0::4::1::*::*';
873 $sched7->status = 'Inactive';
874 $sched7->created_by = '1';
875 $sched7->modified_user_id = '1';
876 $sched7->catch_up = '0';
882 $sched12 = new Scheduler();
883 $sched12->name = $mod_strings['LBL_OOTB_SEND_EMAIL_REMINDERS'];
884 $sched12->job = 'function::sendEmailReminders';
885 $sched12->date_time_start = create_date(2008,1,1) . ' ' . create_time(0,0,1);
886 $sched12->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
887 $sched12->job_interval = '*::*::*::*::*';
888 $sched12->status = 'Active';
889 $sched12->created_by = '1';
890 $sched12->modified_user_id = '1';
891 $sched12->catch_up = '0';
894 $sched13 = new Scheduler();
895 $sched13->name = $mod_strings['LBL_OOTB_CLEANUP_QUEUE'];
896 $sched13->job = 'function::cleanJobQueue';
897 $sched13->date_time_start = create_date(2012,1,1) . ' ' . create_time(0,0,1);
898 $sched13->date_time_end = create_date(2030,12,31) . ' ' . create_time(23,59,59);
899 $sched13->job_interval = '0::5::*::*::*';
900 $sched13->status = 'Active';
901 $sched13->created_by = '1';
902 $sched13->modified_user_id = '1';
903 $sched13->catch_up = '0';
907 //// END SCHEDULER HELPER FUNCTIONS
908 ///////////////////////////////////////////////////////////////////////////
911 ///////////////////////////////////////////////////////////////////////////
912 //// STANDARD SUGARBEAN OVERRIDES
914 * function overrides the one in SugarBean.php
916 function create_export_query($order_by, $where, $show_deleted = 0) {
917 return $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted = 0);
921 * function overrides the one in SugarBean.php
925 * function overrides the one in SugarBean.php
927 function fill_in_additional_list_fields() {
928 $this->fill_in_additional_detail_fields();
932 * function overrides the one in SugarBean.php
934 function fill_in_additional_detail_fields() {
938 * function overrides the one in SugarBean.php
940 function get_list_view_data()
943 $temp_array = $this->get_list_view_array();
944 $temp_array["ENCODED_NAME"]=$this->name;
945 $this->parseInterval();
946 $this->setIntervalHumanReadable();
947 $temp_array['JOB_INTERVAL'] = $this->intervalHumanReadable;
948 if($this->date_time_end == '2020-12-31 23:59' || $this->date_time_end == '') {
949 $temp_array['DATE_TIME_END'] = $mod_strings['LBL_PERENNIAL'];
951 $this->created_by_name = get_assigned_user_name($this->created_by);
952 $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
958 * returns the bean name - overrides SugarBean's
960 function get_summary_text()
964 //// END STANDARD SUGARBEAN OVERRIDES
965 ///////////////////////////////////////////////////////////////////////////
966 static public function getJobsList()
968 if(empty(self::$job_strings)) {
970 include_once('modules/Schedulers/_AddJobsHere.php');
973 self::$job_strings = array('url::' => 'URL');
974 foreach($job_strings as $k=>$v){
975 self::$job_strings['function::' . $v] = $mod_strings['LBL_'.strtoupper($v)];
978 return self::$job_strings;
980 } // end class definition