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-2013 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);
225 $GLOBALS['log']->debug('----->got * day');
227 } elseif(strstr($days, '*/')) {
228 // the "*/x" format is nonsensical for this field
229 // do basically nothing.
230 $theDay = str_replace('*/','',$days);
231 $dayName[] = $theDay;
232 } elseif($days != '*') { // got particular day(s)
233 if(strstr($days, ',')) {
234 $exDays = explode(',',$days);
235 foreach($exDays as $k1 => $dayGroup) {
236 if(strstr($dayGroup,'-')) {
237 $exDayGroup = explode('-', $dayGroup); // build up range and iterate through
238 for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) {
241 } else { // individuals
242 $dayName[] = $dayGroup;
245 } elseif(strstr($days, '-')) {
246 $exDayGroup = explode('-', $days); // build up range and iterate through
247 for($i=$exDayGroup[0];$i<=$exDayGroup[1];$i++) {
254 // check the day to be in scope:
255 if(!in_array($today['wday'], $dayName)) {
263 // derive months part
265 $GLOBALS['log']->debug('----->got * months');
266 } elseif(strstr($mons, '*/')) {
267 $mult = str_replace('*/','',$mons);
268 $startMon = $timedate->fromDb(date_time_start)->month;
269 $startFrom = ($startMon % $mult);
272 for($i=$startFrom;$i<=12;$i+$mult) {
273 $compMons[] = $i+$mult;
276 // this month is not in one of the multiplier months
277 if(!in_array($today['mon'],$compMons)) {
280 } elseif($mons != '*') {
282 if(strstr($mons,',')) { // we have particular (groups) of months
283 $exMons = explode(',',$mons);
284 foreach($exMons as $k1 => $monGroup) {
285 if(strstr($monGroup, '-')) { // we have a range of months
286 $exMonGroup = explode('-',$monGroup);
287 for($i=$exMonGroup[0];$i<=$exMonGroup[1];$i++) {
291 $monName[] = $monGroup;
294 } elseif(strstr($mons, '-')) {
295 $exMonGroup = explode('-', $mons);
296 for($i=$exMonGroup[0];$i<=$exMonGroup[1];$i++) {
299 } else { // one particular month
303 // check that particular months are in scope
304 if(!in_array($today['mon'], $monName)) {
312 $GLOBALS['log']->debug('----->got * dates');
313 } elseif(strstr($dates, '*/')) {
314 $mult = str_replace('*/','',$dates);
315 $startDate = $timedate->fromDb($focus->date_time_start)->day;
316 $startFrom = ($startDate % $mult);
318 for($i=$startFrom; $i<=31; $i+$mult) {
319 $dateName[] = str_pad(($i+$mult),2,'0',STR_PAD_LEFT);
323 if(!in_array($today['mday'], $dateName)) {
326 } elseif($dates != '*') {
327 if(strstr($dates, ',')) {
328 $exDates = explode(',', $dates);
329 foreach($exDates as $k1 => $dateGroup) {
330 if(strstr($dateGroup, '-')) {
331 $exDateGroup = explode('-', $dateGroup);
332 for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) {
336 $dateName[] = $dateGroup;
339 } elseif(strstr($dates, '-')) {
340 $exDateGroup = explode('-', $dates);
341 for($i=$exDateGroup[0];$i<=$exDateGroup[1];$i++) {
345 $dateName[] = $dates;
348 // check that dates are in scope
349 if(!in_array($today['mday'], $dateName)) {
355 //$currentHour = gmdate('G');
356 //$currentHour = date('G', strtotime('00:00'));
359 $GLOBALS['log']->debug('----->got * hours');
360 for($i=0;$i<24; $i++) {
363 } elseif(strstr($hrs, '*/')) {
364 $mult = str_replace('*/','',$hrs);
365 for($i=0; $i<24; $i) { // weird, i know
369 } elseif($hrs != '*') {
370 if(strstr($hrs, ',')) {
371 $exHrs = explode(',',$hrs);
372 foreach($exHrs as $k1 => $hrGroup) {
373 if(strstr($hrGroup, '-')) {
374 $exHrGroup = explode('-', $hrGroup);
375 for($i=$exHrGroup[0];$i<=$exHrGroup[1];$i++) {
379 $hrName[] = $hrGroup;
382 } elseif(strstr($hrs, '-')) {
383 $exHrs = explode('-', $hrs);
384 for($i=$exHrs[0];$i<=$exHrs[1];$i++) {
393 //$currentMin = date('i');
395 $currentMin = $timedate->getNow()->minute;
396 if(substr($currentMin, 0, 1) == '0') {
397 $currentMin = substr($currentMin, 1, 1);
400 $GLOBALS['log']->debug('----->got * mins');
401 for($i=0; $i<60; $i++) {
402 if(($currentMin + $i) > 59) {
403 $minName[] = ($i + $currentMin - 60);
405 $minName[] = ($i+$currentMin);
408 } elseif(strstr($mins,'*/')) {
409 $mult = str_replace('*/','',$mins);
410 $startMin = $timedate->fromDb($focus->date_time_start)->minute;
411 $startFrom = ($startMin % $mult);
412 for($i=$startFrom; $i<=59; $i) {
413 if(($currentMin + $i) > 59) {
414 $minName[] = ($i + $currentMin - 60);
416 $minName[] = ($i+$currentMin);
421 } elseif($mins != '*') {
422 if(strstr($mins, ',')) {
423 $exMins = explode(',',$mins);
424 foreach($exMins as $k1 => $minGroup) {
425 if(strstr($minGroup, '-')) {
426 $exMinGroup = explode('-', $minGroup);
427 for($i=$exMinGroup[0]; $i<=$exMinGroup[1]; $i++) {
431 $minName[] = $minGroup;
434 } elseif(strstr($mins, '-')) {
435 $exMinGroup = explode('-', $mins);
436 for($i=$exMinGroup[0]; $i<=$exMinGroup[1]; $i++) {
444 // prep some boundaries - these are not in GMT b/c gmt is a 24hour period, possibly bridging 2 local days
445 if(empty($focus->time_from) && empty($focus->time_to) ) {
447 $timeToTs = $timedate->getNow(true)->get('+1 day')->ts;
449 $tfrom = $timedate->fromDbType($focus->time_from, 'time');
450 $timeFromTs = $timedate->getNow(true)->setTime($tfrom->hour, $tfrom->min)->ts;
451 $tto = $timedate->fromDbType($focus->time_to, 'time');
452 $timeToTs = $timedate->getNow(true)->setTime($tto->hour, $tto->min)->ts;
456 if(empty($focus->last_run)) {
459 $lastRunTs = $timedate->fromDb($focus->last_run)->ts;
464 * initialize return array
466 $validJobTime = array();
469 $timeStartTs = $timedate->fromDb($focus->date_time_start)->ts;
470 if(!empty($focus->date_time_end)) { // do the same for date_time_end if not empty
471 $timeEndTs = $timedate->fromDb($focus->date_time_end)->ts;
473 $timeEndTs = $timedate->getNow(true)->get('+1 day')->ts;
474 // $dateTimeEnd = '2020-12-31 23:59:59'; // if empty, set it to something ridiculous
477 /*_pp('hours:'); _pp($hrName);_pp('mins:'); _pp($minName);*/
478 $dateobj = $timedate->getNow();
479 $nowTs = $dateobj->ts;
480 $GLOBALS['log']->debug(sprintf("Constraints: start: %s from: %s end: %s to: %s now: %s",
481 gmdate('Y-m-d H:i:s', $timeStartTs), gmdate('Y-m-d H:i:s', $timeFromTs), gmdate('Y-m-d H:i:s', $timeEndTs),
482 gmdate('Y-m-d H:i:s', $timeToTs), $timedate->nowDb()
484 // _pp('currentHour: '. $currentHour);
485 // _pp('timeStartTs: '.date('r',$timeStartTs));
486 // _pp('timeFromTs: '.date('r',$timeFromTs));
487 // _pp('timeEndTs: '.date('r',$timeEndTs));
488 // _pp('timeToTs: '.date('r',$timeToTs));
489 // _pp('mktime: '.date('r',mktime()));
490 // _pp('timeLastRun: '.date('r',$lastRunTs));
496 foreach($hrName as $kHr=>$hr) {
497 foreach($minName as $kMin=>$min) {
498 $timedate->tzUser($dateobj);
499 $dateobj->setTime($hr, $min, 0);
500 $tsGmt = $dateobj->ts;
502 if( $tsGmt >= $timeStartTs ) { // start is greater than the date specified by admin
503 if( $tsGmt >= $timeFromTs ) { // start is greater than the time_to spec'd by admin
504 if($tsGmt > $lastRunTs) { // start from last run, last run should not be included
505 if( $tsGmt <= $timeEndTs ) { // this is taken care of by the initial query - start is less than the date spec'd by admin
506 if( $tsGmt <= $timeToTs ) { // start is less than the time_to
507 $validJobTime[] = $dateobj->asDb();
509 //_pp('Job Time is NOT smaller that TimeTO: '.$tsGmt .'<='. $timeToTs);
512 //_pp('Job Time is NOT smaller that DateTimeEnd: '.date('Y-m-d H:i:s',$tsGmt) .'<='. $dateTimeEnd); //_pp( $tsGmt .'<='. $timeEndTs );
516 //_pp('Job Time is NOT bigger that TimeFrom: '.$tsGmt .'>='. $timeFromTs);
519 //_pp('Job Time is NOT Bigger than DateTimeStart: '.date('Y-m-d H:i',$tsGmt) .'>='. $dateTimeStart);
523 //_ppd($validJobTime);
524 // need ascending order to compare oldest time to last_run
527 * If "Execute If Missed bit is set
529 $now = TimeDate::getInstance()->getNow();
530 $now = $now->setTime($now->hour, $now->min, "00")->asDb();
532 if($focus->catch_up == 1) {
533 if($focus->last_run == null) {
535 $validJobTime[] = $now;
537 // determine what the interval in min/hours is
538 // see if last_run is in it
540 if(!empty($validJobTime) && ($focus->last_run < $validJobTime[0]) && ($now > $validJobTime[0])) {
541 // cn: empty() bug 5914;
542 // if(!empty) should be checked, becasue if a scheduler is defined to run every day 4pm, then after 4pm, and it runs as 4pm,
543 // the $validJobTime will be empty, and it should not catch up.
544 // If $focus->last_run is the the day before yesterday, it should run yesterday and tomorrow,
545 // but it hadn't run yesterday, then it should catch up today.
546 // But today is already filtered out when doing date check before. The catch up will not work on this occasion.
547 // If the scheduler runs at least one time on each day, I think this bug can be avoided.
548 $validJobTime[] = $now;
552 return $validJobTime;
555 function handleIntervalType($type, $value, $mins, $hours) {
557 /* [0]:min [1]:hour [2]:day of month [3]:month [4]:day of week */
558 $days = array ( 1 => $mod_strings['LBL_MON'],
559 2 => $mod_strings['LBL_TUE'],
560 3 => $mod_strings['LBL_WED'],
561 4 => $mod_strings['LBL_THU'],
562 5 => $mod_strings['LBL_FRI'],
563 6 => $mod_strings['LBL_SAT'],
564 0 => $mod_strings['LBL_SUN'],
565 '*' => $mod_strings['LBL_ALL']);
570 return trim($mod_strings['LBL_ON_THE']).$mod_strings['LBL_HOUR_SING'];
571 } elseif(!preg_match('/[^0-9]/', $hours) && !preg_match('/[^0-9]/', $value)) {
574 } elseif(preg_match('/\*\//', $value)) {
575 $value = str_replace('*/','',$value);
576 return $value.$mod_strings['LBL_MINUTES'];
577 } elseif(!preg_match('[^0-9]', $value)) {
578 return $mod_strings['LBL_ON_THE'].$value.$mod_strings['LBL_MIN_MARK'];
583 global $current_user;
584 if(preg_match('/\*\//', $value)) { // every [SOME INTERVAL] hours
585 $value = str_replace('*/','',$value);
586 return $value.$mod_strings['LBL_HOUR'];
587 } elseif(preg_match('/[^0-9]/', $mins)) { // got a range, or multiple of mins, so we return an 'Hours' label
589 } else { // got a "minutes" setting, so it will be at some o'clock.
590 $datef = $current_user->getUserDateTimePreferences();
591 return date($datef['time'], strtotime($value.':'.str_pad($mins, 2, '0', STR_PAD_LEFT)));
593 case 2: // day of month
594 if(preg_match('/\*/', $value)) {
597 return date('jS', strtotime('December '.$value));
601 return date('F', strtotime('2005-'.$value.'-01'));
602 case 4: // days of week
603 return $days[$value];
605 return 'bad'; // no condition to touch this branch
609 function setIntervalHumanReadable() {
610 global $current_user;
613 /* [0]:min [1]:hour [2]:day of month [3]:month [4]:day of week */
614 $ints = $this->intervalParsed;
615 $intVal = array('-', ',');
616 $intSub = array($mod_strings['LBL_RANGE'], $mod_strings['LBL_AND']);
617 $intInt = array(0 => $mod_strings['LBL_MINS'], 1 => $mod_strings['LBL_HOUR']);
621 foreach($ints['raw'] as $key => $interval) {
622 if($tempInt != $iteration) {
625 $iteration = $tempInt;
627 if($interval != '*' && $interval != '*/1') {
628 if(false !== strpos($interval, ',')) {
629 $exIndiv = explode(',', $interval);
630 foreach($exIndiv as $val) {
631 if(false !== strpos($val, '-')) {
632 $exRange = explode('-', $val);
633 foreach($exRange as $valRange) {
635 $tempInt .= $mod_strings['LBL_AND'];
637 $tempInt .= $this->handleIntervalType($key, $valRange, $ints['raw'][0], $ints['raw'][1]);
639 } elseif($tempInt != $iteration) {
640 $tempInt .= $mod_strings['LBL_AND'];
642 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
644 } elseif(false !== strpos($interval, '-')) {
645 $exRange = explode('-', $interval);
646 $tempInt .= $mod_strings['LBL_FROM'];
649 foreach($exRange as $val) {
650 if($tempInt == $check) {
651 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
652 $tempInt .= $mod_strings['LBL_RANGE'];
655 $tempInt .= $this->handleIntervalType($key, $val, $ints['raw'][0], $ints['raw'][1]);
659 } elseif(false !== strpos($interval, '*/')) {
660 $tempInt .= $mod_strings['LBL_EVERY'];
661 $tempInt .= $this->handleIntervalType($key, $interval, $ints['raw'][0], $ints['raw'][1]);
663 $tempInt .= $this->handleIntervalType($key, $interval, $ints['raw'][0], $ints['raw'][1]);
669 $this->intervalHumanReadable = $mod_strings['LBL_OFTEN'];
671 $tempInt = trim($tempInt);
672 if(';' == substr($tempInt, (strlen($tempInt)-1), strlen($tempInt))) {
673 $tempInt = substr($tempInt, 0, (strlen($tempInt)-1));
675 $this->intervalHumanReadable = $tempInt;
680 /* take an integer and return its suffix */
681 function setStandardArraysAttributes() {
683 global $app_list_strings; // using from month _dom list
685 $suffArr = array('','st','nd','rd');
686 for($i=1; $i<32; $i++) {
687 if($i > 3 && $i < 21) {
688 $this->suffixArray[$i] = $i."th";
689 } elseif (substr($i,-1,1) < 4 && substr($i,-1,1) > 0) {
690 $this->suffixArray[$i] = $i.$suffArr[substr($i,-1,1)];
692 $this->suffixArray[$i] = $i."th";
694 $this->datesArray[$i] = $i;
697 $this->dayInt = array('*',1,2,3,4,5,6,0);
698 $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']);
699 $this->monthsInt = array(0,1,2,3,4,5,6,7,8,9,10,11,12);
700 $this->monthsLabel = $app_list_strings['dom_cal_month_long'];
701 $this->metricsVar = array("*", "/", "-", ",");
702 $this->metricsVal = array(' every ','',' thru ',' and ');
706 * takes the serialized interval string and renders it into an array
708 function parseInterval() {
710 $ws = array(' ', '\r','\t');
711 $blanks = array('','','');
713 $intv = $this->job_interval;
714 $rawValues = explode('::', $intv);
715 $rawProcessed = str_replace($ws,$blanks,$rawValues); // strip all whitespace
717 $hours = $rawValues[1].':::'.$rawValues[0];
718 $months = $rawValues[3].':::'.$rawValues[2];
720 $intA = array ( 'raw' => $rawProcessed,
725 $this->intervalParsed = $intA;
729 * checks for cURL libraries
731 function checkCurl() {
734 if(!function_exists('curl_init')) {
736 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
738 <th width="25%" colspan="2"><slot>
739 '.$mod_strings['LBL_WARN_CURL_TITLE'].'
742 <tr class="oddListRowS1" >
743 <td scope="row" valign=TOP width="20%"><slot>
744 '.$mod_strings['LBL_WARN_CURL'].'
745 <td scope="row" valign=TOP width="80%"><slot>
746 <span class=error>'.$mod_strings['LBL_WARN_NO_CURL'].'</span>
754 function displayCronInstructions() {
756 global $sugar_config;
758 if (!isset($_SERVER['Path'])) {
759 $_SERVER['Path'] = getenv('Path');
762 if(isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // IIS IUSR_xxx may not have access to Path or it is not set
763 if(!strpos($_SERVER['Path'], 'php')) {
764 // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>';
768 if(isset($_SERVER['Path']) && !empty($_SERVER['Path'])) { // some Linux servers do not make this available
769 if(!strpos($_SERVER['PATH'], 'php')) {
770 // $error = '<em>'.$mod_strings['LBL_NO_PHP_CLI'].'</em>';
780 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
783 '.$mod_strings['LBL_CRON_INSTRUCTIONS_WINDOWS'].'
786 <tr class="evenListRowS1">
787 <td scope="row" valign="top" width="70%"><slot>
788 '.$mod_strings['LBL_CRON_WINDOWS_DESC'].'<br>
789 <b>cd '.realpath('./').'<br>
790 php.exe -f cron.php</b>
797 <table cellpadding="0" cellspacing="0" width="100%" border="0" class="list view">
800 '.$mod_strings['LBL_CRON_INSTRUCTIONS_LINUX'].'
804 <td scope="row" valign=TOP class="oddListRowS1" bgcolor="#fdfdfd" width="70%"><slot>
805 '.$mod_strings['LBL_CRON_LINUX_DESC'].'<br>
806 <b>* * * * *
807 cd '.realpath('./').'; php -f cron.php > /dev/null 2>&1</b>
816 * Archives schedulers of the same functionality, then instantiates new
819 function rebuildDefaultSchedulers() {
820 $mod_strings = return_module_language($GLOBALS['current_language'], 'Schedulers');
821 // truncate scheduler-related tables
822 $this->db->query('DELETE FROM schedulers');
825 $sched3 = new Scheduler();
826 $sched3->name = $mod_strings['LBL_OOTB_TRACKER'];
827 $sched3->job = 'function::trimTracker';
828 $sched3->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
829 $sched3->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
830 $sched3->job_interval = '0::2::1::*::*';
831 $sched3->status = 'Active';
832 $sched3->created_by = '1';
833 $sched3->modified_user_id = '1';
834 $sched3->catch_up = '1';
836 $sched4 = new Scheduler();
837 $sched4->name = $mod_strings['LBL_OOTB_IE'];
838 $sched4->job = 'function::pollMonitoredInboxes';
839 $sched4->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
840 $sched4->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
841 $sched4->job_interval = '*::*::*::*::*';
842 $sched4->status = 'Active';
843 $sched4->created_by = '1';
844 $sched4->modified_user_id = '1';
845 $sched4->catch_up = '0';
848 $sched5 = new Scheduler();
849 $sched5->name = $mod_strings['LBL_OOTB_BOUNCE'];
850 $sched5->job = 'function::pollMonitoredInboxesForBouncedCampaignEmails';
851 $sched5->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
852 $sched5->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
853 $sched5->job_interval = '0::2-6::*::*::*';
854 $sched5->status = 'Active';
855 $sched5->created_by = '1';
856 $sched5->modified_user_id = '1';
857 $sched5->catch_up = '1';
860 $sched6 = new Scheduler();
861 $sched6->name = $mod_strings['LBL_OOTB_CAMPAIGN'];
862 $sched6->job = 'function::runMassEmailCampaign';
863 $sched6->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
864 $sched6->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
865 $sched6->job_interval = '0::2-6::*::*::*';
866 $sched6->status = 'Active';
867 $sched6->created_by = '1';
868 $sched6->modified_user_id = '1';
869 $sched6->catch_up = '1';
873 $sched7 = new Scheduler();
874 $sched7->name = $mod_strings['LBL_OOTB_PRUNE'];
875 $sched7->job = 'function::pruneDatabase';
876 $sched7->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
877 $sched7->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
878 $sched7->job_interval = '0::4::1::*::*';
879 $sched7->status = 'Inactive';
880 $sched7->created_by = '1';
881 $sched7->modified_user_id = '1';
882 $sched7->catch_up = '0';
888 $sched12 = new Scheduler();
889 $sched12->name = $mod_strings['LBL_OOTB_SEND_EMAIL_REMINDERS'];
890 $sched12->job = 'function::sendEmailReminders';
891 $sched12->date_time_start = create_date(2008,1,1) . ' ' . create_time(0,0,1);
892 $sched12->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
893 $sched12->job_interval = '*::*::*::*::*';
894 $sched12->status = 'Active';
895 $sched12->created_by = '1';
896 $sched12->modified_user_id = '1';
897 $sched12->catch_up = '0';
900 $sched13 = new Scheduler();
901 $sched13->name = $mod_strings['LBL_OOTB_CLEANUP_QUEUE'];
902 $sched13->job = 'function::cleanJobQueue';
903 $sched13->date_time_start = create_date(2012,1,1) . ' ' . create_time(0,0,1);
904 $sched13->date_time_end = create_date(2030,12,31) . ' ' . create_time(23,59,59);
905 $sched13->job_interval = '0::5::*::*::*';
906 $sched13->status = 'Active';
907 $sched13->created_by = '1';
908 $sched13->modified_user_id = '1';
909 $sched13->catch_up = '0';
912 $sched14 = new Scheduler();
913 $sched14->name = $mod_strings['LBL_OOTB_REMOVE_DOCUMENTS_FROM_FS'];
914 $sched14->job = 'function::removeDocumentsFromFS';
915 $sched14->date_time_start = create_date(2012, 1, 1) . ' ' . create_time(0, 0, 1);
916 $sched14->date_time_end = create_date(2030, 12, 31) . ' ' . create_time(23, 59, 59);
917 $sched14->job_interval = '0::3::1::*::*';
918 $sched14->status = 'Active';
919 $sched14->created_by = '1';
920 $sched14->modified_user_id = '1';
921 $sched14->catch_up = '0';
924 $sched15 = new Scheduler();
925 $sched15->name = $mod_strings['LBL_OOTB_SUGARFEEDS'];
926 $sched15->job = 'function::trimSugarFeeds';
927 $sched15->date_time_start = create_date(2005,1,1) . ' ' . create_time(0,0,1);
928 $sched15->date_time_end = create_date(2020,12,31) . ' ' . create_time(23,59,59);
929 $sched15->job_interval = '0::2::1::*::*';
930 $sched15->status = 'Active';
931 $sched15->created_by = '1';
932 $sched15->modified_user_id = '1';
933 $sched15->catch_up = '1';
937 //// END SCHEDULER HELPER FUNCTIONS
938 ///////////////////////////////////////////////////////////////////////////
941 ///////////////////////////////////////////////////////////////////////////
942 //// STANDARD SUGARBEAN OVERRIDES
944 * function overrides the one in SugarBean.php
946 function create_export_query($order_by, $where, $show_deleted = 0) {
947 return $this->create_new_list_query($order_by, $where,array(),array(), $show_deleted = 0);
951 * function overrides the one in SugarBean.php
955 * function overrides the one in SugarBean.php
957 function fill_in_additional_list_fields() {
958 $this->fill_in_additional_detail_fields();
962 * function overrides the one in SugarBean.php
964 function fill_in_additional_detail_fields() {
968 * function overrides the one in SugarBean.php
970 function get_list_view_data()
973 $temp_array = $this->get_list_view_array();
974 $temp_array["ENCODED_NAME"]=$this->name;
975 $this->parseInterval();
976 $this->setIntervalHumanReadable();
977 $temp_array['JOB_INTERVAL'] = $this->intervalHumanReadable;
978 if($this->date_time_end == '2020-12-31 23:59' || $this->date_time_end == '') {
979 $temp_array['DATE_TIME_END'] = $mod_strings['LBL_PERENNIAL'];
981 $this->created_by_name = get_assigned_user_name($this->created_by);
982 $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
988 * returns the bean name - overrides SugarBean's
990 function get_summary_text()
994 //// END STANDARD SUGARBEAN OVERRIDES
995 ///////////////////////////////////////////////////////////////////////////
996 static public function getJobsList()
998 if(empty(self::$job_strings)) {
1000 include_once('modules/Schedulers/_AddJobsHere.php');
1003 self::$job_strings = array('url::' => 'URL');
1004 foreach($job_strings as $k=>$v){
1005 self::$job_strings['function::' . $v] = $mod_strings['LBL_'.strtoupper($v)];
1008 return self::$job_strings;
1010 } // end class definition