getSystemUser(); /////////////////////////////////////////////////////////////////////////////// //// PREP FOR SCHEDULER PID $GLOBALS['log']->debug('--------------------------------------------> at cron.php <--------------------------------------------'); $cachePath = sugar_cached('modules/Schedulers'); $pid = 'pid.php'; if(!is_dir($cachePath)) { mkdir_recursive($cachePath); } if(!is_file($cachePath.'/'.$pid)) { if(is_writable($cachePath)) { // the "file" does not yet exist write_array_to_file('timestamp', array(strtotime(date('H:i'))) , $cachePath.'/'.$pid); require_once($cachePath.'/'.$pid); } else { $GLOBALS['log']->fatal('Scheduler cannot write PID file. Please check permissions on '.$cachePath); } } else { if(is_writable($cachePath.'/'.$pid)) { require_once($cachePath.'/'.$pid); } else { $GLOBALS['log']->fatal('Scheduler cannot read the PID file. Please check permissions on '.$cachePath); } } //// END PREP FOR SCHEDULER PID /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// //// EXECUTE IF VALID TIME (NOT DDOS) // mjamil | bug # 45229 - schedulers not able to run due to current time being equal to // $timestamp[0] if($timestamp[0] <= strtotime(date('H:i'))) { if(is_writable($cachePath.'/'.$pid)) { write_array_to_file('timestamp', array(strtotime(date('H:i'))) , $cachePath.'/'.$pid); require('modules/Schedulers/Scheduler.php'); $s = new Scheduler(); $s->flushDeadJobs(); $s->checkPendingJobs(); } else { $GLOBALS['log']->fatal('Scheduler cannot write PID file. Please check permissions on '.$cachePath); } } else { $GLOBALS['log']->fatal('If you see a whole string of these, there is a chance someone is attacking your system.'); } $exit_on_cleanup = true; sugar_cleanup(false); // some jobs have annoying habit of calling sugar_cleanup(), and it can be called only once // but job results can be written to DB after job is finished, so we have to disconnect here again // just in case we couldn't call cleanup if(class_exists('DBManagerFactory')) { $db = DBManagerFactory::getInstance(); $db->disconnect(); } if($exit_on_cleanup) exit;