Author Topic: Suggested Changes to task_api.php  (Read 7313 times)

Offline dhigz

  • Newbie
  • *
  • Posts: 46
  • Karma: +17/-0
    • View Profile
Suggested Changes to task_api.php
« on: December 14, 2020, 11:29:22 PM »
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:

Code: [Select]
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:

Code: [Select]
define('RDIR_TEMPLATE', 'admin/view/default/');

2) The command "--force" is negated when running a task. Take a look at the function processTask().

Code: [Select]
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:

Code: [Select]
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.


Don Higbee

Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5937
  • Karma: +284/-2
    • View Profile
Re: Suggested Changes to task_api.php
« Reply #1 on: December 15, 2020, 12:15:13 AM »
Thank you, dhigz.
I have created a new bug report in the tracker for these issues https://github.com/abantecart/abantecart-src/issues/1444

Offline dhigz

  • Newbie
  • *
  • Posts: 46
  • Karma: +17/-0
    • View Profile
Re: Suggested Changes to task_api.php
« Reply #2 on: December 15, 2020, 01:26:39 PM »
Thanks
Don Higbee

Offline Basara

  • Administrator
  • Hero Member
  • *****
  • Posts: 5937
  • Karma: +284/-2
    • View Profile
Re: Suggested Changes to task_api.php
« Reply #3 on: January 28, 2021, 02:05:27 AM »
Hello, dhigz.
AbanteCart team made some changes in the upcoming 1.3.0 related to the task_api.php
Check the commit https://github.com/abantecart/abantecart-src/issues/1444
« Last Edit: August 26, 2021, 05:54:29 AM by Basara »

 

Powered by SMFPacks Social Login Mod