AbanteCart Development > AbanteCart v2.0

Suggested Changes to task_api.php

(1/1)

dhigz:
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: ---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>
--- End code ---

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: ---define('RDIR_TEMPLATE', 'admin/view/default/');

--- End code ---

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


--- Code: ---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";
}
--- End code ---

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: ---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";
}

--- End code ---

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.


Basara:
Thank you, dhigz.
I have created a new bug report in the tracker for these issues https://github.com/abantecart/abantecart-src/issues/1444

dhigz:
Thanks

Basara:
Hello, dhigz.
AbanteCart team made some changes in the upcoming 1.2.17 related to the task_api.php
Check the commit https://github.com/abantecart/abantecart-src/issues/1444

Navigation

[0] Message Index

Go to full version
Powered by SMFPacks Social Login Mod