Continuing the discussion on my custom admin cron job, I found out debugging a problem that the notifiers in function zen_mail are not triggered when the zen_mail function is called from a cron job. They are triggered during normal store operation. To review, the cron job is on the admin side. It calls a function in admin/functions/extra_functions. That function calls zen_mail which is located in includes/functions/functions_email.php on the store side. A notifier in zen_mail triggers an observer located in includes/classes/observers on the store side.
I have placed trigger_error(' some string') statements in zen_mail before and after a notifier and in the observer associated with the notifier. When the cron job is running, the two statements in zen_mail are executed and logs generated, but the statement inside the observer is not executed. When operating normally all three statements generate logs.
I suspected that something was not being loaded that should be. Thinking it was associated with observers on the store side, I added the following code (in red) to the cron job autoloader file to pick up the observer class notifier from the store side and instantiate it:
<?php
/**
* @copyright Copyright 2003-2020 Zen Cart Development Team
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: Scott C Wilson 2020 May 14 Modified in v1.5.7 $
*/
if (!defined('USE_PCONNECT')) define('USE_PCONNECT', 'false');
/**
* autoloader array for admin currency_cron.php
*/
$autoLoadConfig[0][] = array('autoType'=>'require',
'loadFile'=> DIR_FS_CATALOG . DIR_WS_INCLUDES . 'version.php');
$autoLoadConfig[0][] = array('autoType'=>'class',
'loadFile'=>'class.notifier.php');
$autoLoadConfig[0][] = array('autoType'=>'classInstantiate',
'className'=>'notifier',
'objectName'=>'zco_notifier');
$autoLoadConfig[0][] = array('autoType'=>'class',
'loadFile'=>DIR_FS_CATALOG . DIR_WS_INCLUDES . 'class.notifier.php');
$autoLoadConfig[0][] = array('autoType'=>'classInstantiate',
'className'=>'notifier',
'objectName'=>'zco_notifier');
$autoLoadConfig[0][] = array('autoType'=>'class',
'loadFile'=>'sniffer.php');
$autoLoadConfig[0][] = array('autoType'=>'class',
'loadFile'=>'object_info.php',
'classPath'=>DIR_WS_CLASSES);
$autoLoadConfig[0][] = array('autoType'=>'class',
'loadFile'=>'class.phpmailer.php');
$autoLoadConfig[20][] = array('autoType'=>'init_script',
'loadFile'=> 'init_db_config_read.php');
$autoLoadConfig[30][] = array('autoType'=>'classInstantiate',
'className'=>'sniffer',
'objectName'=>'sniffer');
$autoLoadConfig[40][] = array('autoType'=>'init_script',
'loadFile'=> 'init_general_funcs.php');
$autoLoadConfig[60][] = array('autoType'=>'require',
'loadFile'=> DIR_FS_CATALOG . DIR_WS_FUNCTIONS . 'sessions.php');
$autoLoadConfig[70][] = array('autoType'=>'init_script',
'loadFile'=> 'init_languages.php');
$autoLoadConfig[120][] = array('autoType'=>'init_script',
'loadFile'=> 'init_special_funcs.php');
// $autoLoadConfig[140][] = array('autoType'=>'init_script',
// 'loadFile'=> 'init_errors.php');
$autoLoadConfig[170][] = array('autoType'=>'init_script',
'loadFile'=> 'init_admin_history.php');
$autoLoadConfig[1][] = array('autoType'=>'class',
'loadFile'=>'class.admin.zcObserverLogEventListener.php',
'classPath'=>DIR_WS_CLASSES);
$autoLoadConfig[40][] = array('autoType'=>'classInstantiate',
'className'=>'zcObserverLogEventListener',
'objectName'=>'zcObserverLogEventListener');
But no change. No error logs other than the zen_mail trigger_error logs. Running the cron job with VERBOSE showed normal expected output and nothing associated with the problem.
Although warned not to do it in the admin cron job model script, I moved the cron job to the store side and set the cron autoloader file identical to the store side includes/auto_loaders/config.core.php. The result was lots of already defined constant error messages, a few undefined array key error messages, but the trigger_error statements were executed in the zen_mail observer when the cron job ran.
So I conclude I'm missing one or more files or not including them correctly in the admin cron job auto_loader file.
Any help would be greatly appreciated.
Dave