diff --git a/cron.php b/cron.php
index 445cea6c6..d2df5751b 100755
--- a/cron.php
+++ b/cron.php
@@ -44,6 +44,11 @@ if ((PHP_SAPI === "apache" || PHP_SAPI === "litespeed") && $_E107['debug'] === f
require_once(realpath(__DIR__ . "/class2.php"));
+if(!empty($_E107['debug']))
+{
+ error_reporting(E_ALL);
+}
+
require_once(e_HANDLER . "cron_class.php");
$cron = new cronScheduler();
diff --git a/e107_handlers/Shims/Internal/StrftimeTrait.php b/e107_handlers/Shims/Internal/StrftimeTrait.php
index 2fe4de4f6..bfa5083c3 100644
--- a/e107_handlers/Shims/Internal/StrftimeTrait.php
+++ b/e107_handlers/Shims/Internal/StrftimeTrait.php
@@ -69,7 +69,7 @@ trait StrftimeTrait
self::getSensibleLocale(),
\IntlDateFormatter::NONE,
\IntlDateFormatter::NONE,
- null,
+ 'GMT'.date('O'), // More accurate timezone. @see https://stackoverflow.com/questions/31707395/why-php-intldateformatter-returns-wrong-date-1-hour
null,
$format
);
diff --git a/e107_handlers/cron_class.php b/e107_handlers/cron_class.php
index 097f4503b..bbc5a2266 100644
--- a/e107_handlers/cron_class.php
+++ b/e107_handlers/cron_class.php
@@ -157,7 +157,13 @@ class _system_cron
function sendEmail() // Test Email.
{
global $pref, $_E107;
- if($_E107['debug']) { echo "
sendEmail() executed"; }
+
+ if($_E107['debug'])
+ {
+ echo "sendEmail() executed";
+ error_log('e107: Cron running _system_cron::sendEmail(); ', E_USER_NOTICE);
+ }
+
// require_once(e_HANDLER.'mail.php');
$message = "Your Cron test worked correctly. Sent on ".date("r").".";
@@ -205,7 +211,10 @@ class _system_cron
'body' => $message
);
- e107::getEmail()->sendEmail($pref['siteadminemail'], $pref['siteadmin'], $eml);
+ if(!e107::getEmail()->sendEmail($pref['siteadminemail'], $pref['siteadmin'], $eml))
+ {
+ error_log('e107: Cron _system_cron::sendEmail() failed to send email.', E_ERROR);
+ }
// sendemail($pref['siteadminemail'], "e107 - TEST Email Sent by cron.".date("r"), $message, $pref['siteadmin'],SITEEMAIL, $pref['siteadmin']);
}
@@ -397,6 +406,7 @@ class CronParser
var $bits = Array(); //exploded String like 0 1 * * *
var $now = Array(); //Array of cron-style entries for time()
var $lastRan; //Timestamp of last ran time.
+ private $lastDue;
var $taken;
var $debug;
var $year;
@@ -416,6 +426,16 @@ class CronParser
return explode(",", eShims::strftime("%M,%H,%d,%m,%w,%Y", $this->lastRan)); //Get the values for now in a format we can use
}
+ public function getLastDue()
+ {
+ return $this->lastDue;
+ }
+
+ public function getNow()
+ {
+ return $this->now;
+ }
+
/**
* @return mixed
*/
@@ -432,26 +452,25 @@ class CronParser
return $this->debug;
}
+ function setDebug($bool)
+ {
+ $this->debug = (bool) $bool;
+ }
+
/**
* @param $str
* @return void
*/
function debug($str)
{
- if (is_array($str))
+ if(!$this->debug)
{
- $this->debug .= "\nArray: ";
- foreach($str as $k=>$v)
- {
- $this->debug .= "$k=>$v, ";
- }
+ return;
+ }
- }
- else
- {
- $this->debug .= "\n$str";
- }
- //echo nl2br($this->debug);
+ $text = (is_array($str) ? print_r($str,true) : $str);
+ error_log('e107: Cron '.$text);
+ echo $text."\n";
}
/**
@@ -513,9 +532,10 @@ class CronParser
*/
function calcLastRan($string)
{
+ $this->debug(__METHOD__.' ('.__LINE__.'): '.date_default_timezone_get());
$tstart = microtime(true);
- $this->debug = "";
+
$this->lastRan = 0;
$this->year = NULL;
$this->month = NULL;
@@ -526,20 +546,20 @@ class CronParser
$this->minutes_arr = array();
$this->months_arr = array();
- $string = preg_replace('/[\s]{2,}/', ' ', $string);
+ $string = preg_replace('/\s{2,}/', ' ', $string);
if (preg_match('/[^-,* \\d]/', $string) !== 0)
{
- $this->debug("Cron String contains invalid character");
+ $this->debug("e107: Cron string contains invalid character: ".$string);
return false;
}
- $this->debug("Working on cron schedule: $string");
+ $this->debug("\n----- Working on cron schedule: $string ----");
$this->bits = @explode(" ", $string);
if (count($this->bits) != 5)
{
- $this->debug("Cron string is invalid. Too many or too little sections after explode");
+ $this->debug("e107: Cron string is invalid. Too many or too little sections after explode.".print_r($this->bits,true));
return false;
}
@@ -656,8 +676,12 @@ class CronParser
}
else
{
- $this->debug("LAST DUE: " . $this->hour . ":" . $this->minute . " on " . $this->day . "/" . $this->month . "/" . $this->year);
+ $lastDue = $this->year.'-'.(strlen($this->month) === 1 ? '0'.$this->month : $this->month).'-'.(strlen($this->day) === 1 ? '0'.$this->day : $this->day).'T'.(strlen($this->hour) === 1 ? '0'.$this->hour : $this->hour) . ":" . (strlen($this->minute) === 1 ? '0'.$this->minute : $this->minute);
+ $this->debug(__METHOD__.' ('.__LINE__.'): '.date_default_timezone_get());
+ $this->debug(__METHOD__.' ('.__LINE__.'): Setting lastDue to ' . $lastDue);
+ $this->lastDue = $lastDue;
$this->lastRan = mktime($this->hour, $this->minute, 0, $this->month, $this->day, $this->year);
+ $this->debug(__METHOD__.' ('.__LINE__.'): Setting lastRan to '.date('c', $this->lastRan));
return true;
}
}
@@ -914,7 +938,7 @@ class CronParser
}
}
$this->debug("Days array matching weekdays for $year-$month");
- $this->debug($days);
+ //$this->debug($days);
return $days;
}
@@ -959,8 +983,8 @@ class CronParser
$hours = $this->_sanitize($hours, 0, 23);
}
- $this->debug("Hour array");
- $this->debug($hours);
+ // $this->debug("Hour array");
+ // $this->debug($hours);
$this->hours_arr = $hours;
}
return $this->hours_arr;
@@ -987,8 +1011,8 @@ class CronParser
$minutes = $this->expand_ranges($this->bits[0]);
$minutes = $this->_sanitize($minutes, 0, 59);
}
- $this->debug("Minutes array");
- $this->debug($minutes);
+ // $this->debug("Minutes array");
+ // $this->debug($minutes);
$this->minutes_arr = $minutes;
}
return $this->minutes_arr;
@@ -1014,8 +1038,8 @@ class CronParser
$months = $this->expand_ranges($this->bits[3]);
$months = $this->_sanitize($months, 1, 12);
}
- $this->debug("Months array");
- $this->debug($months);
+ // $this->debug("Months array");
+ // $this->debug($months);
$this->months_arr = $months;
}
return $this->months_arr;
@@ -1067,6 +1091,7 @@ class cronScheduler
$this->cron = new CronParser();
$this->debug = $_E107['debug'];
+ $this->cron->setDebug($_E107['debug']);
$this->pref = e107::getPref();
}
@@ -1083,24 +1108,23 @@ class cronScheduler
{
if($this->debug)
{
- error_log('e107: Invalid token used for cron class');
+ $this->cron->debug('e107: Invalid token used for cron class');
}
return false;
}
if(!@file_put_contents(e_CACHE . 'cronLastLoad.php', time()))
{
- error_log('e107: Unable to write to: '.e_CACHE . 'cronLastLoad.php. Permissions issue?');
+ $this->cron->debug('e107: Unable to write to: '.e_CACHE . 'cronLastLoad.php. Permissions issue?');
}
// Get active cron jobs.
$cron_jobs = $this->getCronJobs(true);
- if($this->debug && $_SERVER['QUERY_STRING'])
+ if($this->debug)
{
- echo "