After some extensive testing, I have found some issues with task_api.php that should be looked at.
1) Running a task from task_api cron causes an error which can be found in the error log:
warning: AbanteCart core v.1.2.16 Use of undefined constant RDIR_TEMPLATE - assumed 'RDIR_TEMPLATE' (this will throw an Error in a future version of PHP) in <b>[path to file]/httpdocs/core/engine/view.php</b> on line <b>93</b>
The error has to do with the declaration of the template directory. The simple solution is to add a declaration to task_api.php as it is in task.php:
define('RDIR_TEMPLATE', 'admin/view/default/');
2) The command "--force" is negated when running a task. Take a look at the function processTask().
function processTask($options)
{
$tm_mode = 'cli';
$tm = new ATaskManager($tm_mode);
if ($options['force']) {
echo "Force starting task! \n";
if (
!$tm->updateTask($options['task_id'], array('status' => $tm::STATUS_READY))
|| !($steps = $tm->getTaskSteps($options['task_id']))
) {
echo "Error: Task ID {$options['task_id']} can not be re-started! \n";
exit(1);
}
foreach ($steps as $step) {
$tm->updateStep($step['step_id'], array('status' => $tm::STATUS_READY));
}
}
echo "Running: Task ID {$options['task_id']}: \n";
if (!$tm->runTask($options['task_id'])) {
//error
echo "Error: Task ID ".$options['task_id']." has failed! \n";
}
if ($options['show_log']) {
$run_log = $tm->getRunLog();
$run_log_text = implode("\n", $run_log);
echo "{$run_log_text}\n";
}
echo "Finished running: Task ID ".$options['task_id'].": \n";
}
If option['force'] etc works as it should. the status values are reset to 1 or STATUS_READY as it should. However, when $tm->runTask is run later in the function, if successful, the status values are set to 5 or STATUS_COMPLETED. STATUS_FAILED if not.
The simple fix is to move the "force" section after the runTask section and before the log section, like:
function processTask($options)
{
$tm_mode = 'cli';
$tm = new ATaskManager($tm_mode);
echo "Running: Task ID {$options['task_id']}: \n";
if (!$tm->runTask($options['task_id'])) {
//error
echo "Error: Task ID ".$options['task_id']." has failed! \n";
}
if ($options['force']) {
echo "Force starting task! \n";
if (
!$tm->updateTask($options['task_id'], array('status' => $tm::STATUS_READY))
|| !($steps = $tm->getTaskSteps($options['task_id']))
) {
echo "Error: Task ID {$options['task_id']} can not be re-started! \n";
exit(1);
}
foreach ($steps as $step) {
$tm->updateStep($step['step_id'], array('status' => $tm::STATUS_READY));
}
}
if ($options['show_log']) {
$run_log = $tm->getRunLog();
$run_log_text = implode("\n", $run_log);
echo "{$run_log_text}\n";
}
echo "Finished running: Task ID ".$options['task_id'].": \n";
}
3. There is no way to use the force option to run all tasks. There are no provisions in the task_api file. There are a couple of ways this can be fixed but involves changing both the task_cli file as well as the core/task_manager file. Regardless it would be a nice option to have.