With some help, I've been debugging the cron.php script. Here's what I found out:
If the script does not extend the JApplicationCli class, but is modified to
1) instantiate the Updatecron class directly
2) comment out the call to out ("$this->out($email)")
3) call the execute() function directly
The script starts producing emails as expected.
Below is the script. Please note that there are some echo statements that are for debug/trace that should be removed if you use this. I've highlighted the changes I've made.
<?php
// Make sure we're being called from the command line, not a web interface
if (array_key_exists('REQUEST_METHOD', $_SERVER)) die();
echo "DTRegister Script\n";
// Set flag that this is a parent file.
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', 1);
global $mainframe ;
class Climainframe {
function isAdmin() {
return true ;
}
}
$mainframe = new Climainframe();
chdir(dirname(__FILE__));
// Load system defines
chdir("../../");
if (file_exists(dirname(dirname(dirname(__FILE__))) . '/defines.php'))
{
require_once dirname(dirname(dirname(__FILE__))) . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', getcwd());
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE.'/includes/framework.php';
require_once JPATH_BASE.'/includes/application.php';
require_once JPATH_LIBRARIES . '/import.php';
require_once JPATH_LIBRARIES . '/cms.php';
// Force library to be in JError legacy mode
JError::$legacy = true;
// Load the configuration
require_once JPATH_CONFIGURATION . '/configuration.php';
// Get the framework.
require_once JPATH_LIBRARIES . '/import.php';
// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';
// Force library to be in JError legacy mode
JError::$legacy = true;
// Import necessary classes not handled by the autoloaders
jimport('joomla.application.menu');
jimport('joomla.environment.uri');
jimport('joomla.event.dispatcher');
jimport('joomla.utilities.utility');
jimport('joomla.utilities.arrayhelper');
if (!defined('DTR_COM_COMPONENT')){
define('DTR_COM_COMPONENT',"com_dtregister");
define("DTR_COMPONENT",str_replace("com_","",'DT_COM_COMPONENT'));
}
define('JPATH_COMPONENT_ADMINISTRATOR',JPATH_ADMINISTRATOR."/components/com_dtregister") ;
//global $mainframe;
//$mainframe = JFactory::getApplication('site');
//$mainframe->initialise();
//include_once(JPATH_COMPONENT_ADMINISTRATOR.DS.'lib'.DS.'defines.php');
JLoader::register('DtrModel' , JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_dtregister'.DS.'lib'.DS.'dtmodel.php');
JLoader::register('DtrModeladmin' , JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_dtregister'.DS.'lib'.DS.'dtmodeladmin.php');
JLoader::register('DtrTable' , JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_dtregister'.DS.'lib'.DS.'dttable.php');
JLoader::register('DT_Tagparser' , JPATH_SITE.DS.'administrator'.DS.'components'.DS.'com_dtregister'.DS.'lib'.DS.'tagparser.php');
include_once(JPATH_SITE."/administrator/components/com_dtregister/models/user.php");
include_once(JPATH_SITE."/administrator/components/com_dtregister/models/config.php");
include_once(JPATH_SITE."/administrator/components/com_dtregister/models/reminder.php");
include_once(JPATH_SITE."/administrator/components/com_dtregister/models/paymentmethod.php");
include_once(JPATH_SITE."/administrator/components/com_dtregister/models/fieldtype.php");
$config = new DtregisterModelConfig(array());
$config->setGlobal();
jimport('joomla.application.component.helper');
DtrTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.DTR_COM_COMPONENT.DS.'models');
class Updatecron // extends JApplicationCli
{
/**
* Entry point for the script
*
* @return void
*
* @since 2.5
*/
public function execute()
{
echo "In Execute()\n";
$this->_db = $db = JFactory::getDBO();
$reminder = & DtrTable::getInstance('Reminder','DtrTable');
$reminders = $reminder->find() ;
foreach($reminders as $reminder) {
$records = $this->get_records($reminder);
$reminderT = & DtrTable::getInstance('Reminder','DtrTable');
$reminderT->load($reminder->id);
$files = $reminderT->files;
foreach($records as $record) {
$this->send($record,$reminder->message,$reminder->subject,$reminderT->files);
}
}
}
function send($record,$message="",$subject= "",$files = array()) {
global $DT_mailfrom,$DT_fromname,$thanksmsg,$admin_registrationemail,$admin_notification,$subject_admin_registrationemail, $admin_email_from_user;
global $sendEmailToGroup ;
$event = & DtrTable::getInstance('event','Table');
$user = & DtrTable::getInstance('Duser','Table');
$user->load($record->userId);
$user->TableEvent->load($user->eventId);
$Tagparser = new DT_Tagparser();
$groupmsg = $Tagparser->getTagcontent('GROUP_MEMBER',$message);
$memberdata = "";
if($user->type == 'G'){
$memeber_msg = array();
foreach($user->members as $member){
$message = $Tagparser->parsetags($groupmsg,$member);
$memeber_msg[] = $message;
$memberdata .= $message;
$subject_mem = $Tagparser->parsetags($subject,$member);
}
if($sendEmailToGroup ==1){
$i = 0;
foreach($user->members as $member){
$Tagparser->parse_password = true;
$usermsg = $Tagparser->replaceTagContent('GROUP_MEMBER',$message,$memeber_msg[$i]);
$message = $Tagparser->parsetags($usermsg,$member);
$subject = $Tagparser->parsetags($subject,$member);
$attachments = array();
if(is_array($user->TableEvent->file) && $this->status != -2){
foreach($user->TableEvent->file as $attach){
$attachments[] = $attach->path;
}
}
if(isset($member->email) && $member->email != "" && $sendEmailToGroup ==1 ){
echo $member->email."\n";
JUTility::sendMail( $DT_mailfrom, strip_tags(html_entity_decode($DT_fromname)),$member->email,strip_tags(html_entity_decode($subject)),$message,1,null,null,$attachments);
}
$i++;
}
}
}
$Tagparser->parse_password = true;
$usermsg = $Tagparser->replaceTagContent('GROUP_MEMBER',$message,$memberdata);
$message = $Tagparser->parsetags($usermsg,$user);
$subject = $Tagparser->parsetags($subject,$user);
$email = $user->getFieldByName('email');
$attachments = array();
if(is_array($files) ){
foreach($files as $attach){
$attachments[] = $attach;
}
}
// $this->out($email);
// echo "Subject : ".$subject."\n ";
// echo "Message : ".$message."\n ";
JUTility::sendMail( $DT_mailfrom, strip_tags(html_entity_decode($DT_fromname)),$email,strip_tags(html_entity_decode($subject)),$message,1,null,null,$attachments);
}
function get_records($reminder = 0) {
if($reminder->timer == 0){
$timer = $reminder->timer + 1 ;
} else {
$timer = $reminder->timer ;
}
$condition = "" ;
if($reminder->eventId) {
$condition = " and e.slabId = '".$reminder->eventId."' ";
}
$query = "SELECT u.userId
FROM #__dtregister_user u
INNER JOIN #__dtregister_group_event e
ON e.slabId = u.eventId
WHERE DATEDIFF(e.dtstart,NOW()) = $timer and u.status in (0,1) ".$condition;
$this->_db->setQuery($query);
//echo $this->_db->getQuery()."\n";
$records = $this->_db->loadObjectList();
return $records ;
}
}
echo "Calling Execute\n";
$x = new Updatecron();
$x->execute();
//JApplicationCli::getInstance('Updatecron')->execute();
echo "Done with Execute\n";