#!/usr/bin/php -q
filter($_GET['token']);
}
else
{
$pwd = str_replace('token=','',$pwd);
}
if(($pref['e_cron_pwd'] != $pwd) || empty($pref['e_cron_pwd']))
{
if(!empty($pwd))
{
require_once(e_HANDLER."mail.php");
$message = "Your Cron Schedule is not configured correctly. Your passwords do not match.
Sent from cron: ".$pwd."
Stored in e107: ".$pref['e_cron_pwd']."
You should regenerate the cron command in admin and enter it again in your server configuration.
";
$message .= "
Debug Info
";
$message .= "_SERVER
";
$message .= print_a($_SERVER,true);
$message .= "_ENV
";
$message .= print_a($_ENV,true);
$message .= "_GET
";
$message .= print_a($_GET,true);
sendemail($pref['siteadminemail'], "e107 - Cron Schedule Misconfigured.", $message, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
}
exit;
}
// e107::getCache()->CachePageMD5 = '_';
@file_put_contents(e_CACHE.'cronLastLoad.php',time());
// from the plugin directory:
// realpath(dirname(__FILE__)."/../../")."/";
$list = array();
$sql = e107::getDb();
if($sql->select("cron",'cron_function,cron_tab','cron_active =1'))
{
while($row = $sql->fetch())
{
list($class,$function) = explode("::",$row['cron_function'],2);
$key = $class."__".$function;
$list[$key] = array(
'path' => $class,
'active' => 1,
'tab' => $row['cron_tab'],
'function' => $function,
'class' => $class
);
}
}
// foreach($pref['e_cron_pref'] as $func=>$cron)
// {
// if($cron['active']==1)
// {
// $list[$func] = $cron;
// }
// }
if($_E107['debug'] && $_SERVER['QUERY_STRING'])
{
echo "Cron Lists
";
print_a($list);
}
require_once(e_HANDLER."cron_class.php");
$cron = new CronParser();
require_once(e_HANDLER."mail.php");
foreach($list as $func=>$val)
{
$cron->calcLastRan($val['tab']);
$due = $cron->getLastRanUnix();
if($_E107['debug'])
{
echo "
Cron: ".$val['function'];
}
if($due > (time()-45))
{
if($_E107['debug']) { echo "
Running Now...
path: ".$val['path']; }
if(($val['path']=='_system') || is_readable(e_PLUGIN.$val['path']."/e_cron.php"))
{
if($val['path'] != '_system') // this is correct.
{
include_once(e_PLUGIN.$val['path']."/e_cron.php");
}
$classname = $val['class']."_cron";
if(class_exists($classname, false))
{
$obj = new $classname;
if(method_exists($obj,$val['function']))
{
// $mes->add("Executing config function ".$key." : ".$method_name."()", E_MESSAGE_DEBUG);
if($_E107['debug']) { echo "
Method Found: ".$classname."::".$val['function']."()"; }
// Exception handling
$methodname = $val['function'];
$status = false;
try
{
$status = $obj->$methodname();
}
catch (Exception $e)
{
$errorMData = $e->getFile().' '.$e->getLine();
$errorMData .= "\n\n".$e->getCode().''.$e->getMessage();
$errorMData .= "\n\n".implode("\n", $e->getTrace());
//TODO log error in admin log. Pref for sending email to Administator
sendemail($pref['siteadminemail'], $pref['siteadmin'].": Cron Schedule Exception", $errorMData, $pref['siteadmin'],$pref['siteadminemail'], $pref['siteadmin']);
}
// $status = call_user_func(array($obj,$val['function']));
// If task returns value which is not boolean (bc), it'll be used as a message (send email, logs)
if($status && true !== $status)
{
//TODO log error in admin log. Pref for sending email to Administator
// echo "\nerror running the function ".$func.".\n"; // log the error.
if($_E107['debug']) { echo "
Method returned message: [{$classname}::".$val['function'].'] '.$status; }
sendemail($pref['siteadminemail'], $pref['siteadmin'].": Cron Schedule Task Report", "Method returned message: [{$classname}::".$val['function'].'] '.$status, $pref['siteadmin'], $pref['siteadminemail'], $pref['siteadmin']);
}
}
else
{
if($_E107['debug']) { echo "
Couldn't find method: ".$val['function']; }
}
}
else
{
if($_E107['debug']) { echo "
Couldn't find class: ".$classname; }
}
}
}
// echo "Cron Unix = ". $cron->getLastRanUnix();
// echo "
Now = ".time();
}
// echo "
Cron '$cron_str0' last due at: " . date('r', $cron->getLastRanUnix()) . "";
// $cron->getLastRan() returns last due time in an array
// print_a($cron->getLastRan());
// echo "Debug:
" . nl2br($cron->getDebug());
/*
$cron_str1 = "3 12 * * *";
if ($cron->calcLastRan($cron_str1))
{
echo "
Cron '$cron_str1' last due at: " . date('r', $cron->getLastRanUnix()) . "
";
print_r($cron->getLastRan());
}
else
{
echo "Error parsing";
}
echo "Debug:
" . nl2br($cron->getDebug());
*/
exit;
?>