Author Topic: Task.php, Task API Key and tsk Documentation  (Read 3391 times)

Offline dhigz

  • Newbie
  • *
  • Posts: 45
  • Karma: +16/-0
    • View Profile
Task.php, Task API Key and tsk Documentation
« on: December 05, 2020, 10:44:01 PM »
OK,

I have a task set up. It works perfectly when run from the Schedule Tasks screen. It also works perfectly when run from the browser when adding ?task_api_key=[my key] to the url. What I cannot get to work is running the task.php from CRON.

Following the examples on CRON in the documentation: https://abantecart.atlassian.net/wiki/spaces/AD/pages/15007901/Scheduled+Tasks#ScheduledTasks-CRON for my Plesk server CRON will run the Task.php script but I get a response of: "Authorize the Access".

Looking at the task.php code it is clear this message is coming from the following:
Code: [Select]
// add to settings API et task_api_key
$task_api_key = $config->get('task_api_key');
if (!$task_api_key || $task_api_key != (string)$_GET['task_api_key']) {
    exit('Authorize to access.');
}

What is clear is that running the command in CRON per the documentation does not work and to get it to work requires the task_api_key to be sent. However, there is no mention or explanation on how to do this.

My attempts at different methods to send the key have all failed. I attempted adding parameters to the file name gave a could not open file error. Passing the key value pair as an argument open the file but gave me the "Authorize the Access" error.

The only way I can successfully run the task.php file from CRON is to remove the $_GET requirement from the is statement.

What does work and I am doing for now is to direct CRON to the task_cli.php file instead. Problem is there is no API Key security. Using task_cli.php is not even mentioned on this documentation page. 

My point of this post is that something needs to be fixed so others do not have their time wasted as mine was today.
  • Tell me how to pass the task api parameter for I can use task.php.
  • Fix task.php so it recognizes an argument value and not just $_GET.
  • Fix the documentation.

I am ready to release a new extension and this is the only thing holding me up. I do not want to mislead people by sending them to misleading documentation. If there is an answer to #1, I would sure like to know it.

Thanks

Don Higbee

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Task.php, Task API Key and tsk Documentation
« Reply #1 on: December 07, 2020, 02:02:11 AM »
Hi,
Please check your task api key in the settings (see screenshot).
it must be set to run task via cron.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline dhigz

  • Newbie
  • *
  • Posts: 45
  • Karma: +16/-0
    • View Profile
Re: Task.php, Task API Key and tsk Documentation
« Reply #2 on: December 08, 2020, 02:24:59 PM »
abolabo,

Sigh  ??? That is all you have to say after everything I wrote?

Of course I entered a TASK API KEY in the settings.

Don Higbee

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Task.php, Task API Key and tsk Documentation
« Reply #3 on: December 09, 2020, 02:19:33 AM »
abolabo,

Sigh  ??? That is all you have to say after everything I wrote?

Of course I entered a TASK API KEY in the settings.

are you sure?
Code: [Select]
$task_api_key = $config->get('task_api_key');This row means you do not have it when try to run via cli.
Please check it in the database table "settings"... or just in the code
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline dhigz

  • Newbie
  • *
  • Posts: 45
  • Karma: +16/-0
    • View Profile
Re: Task.php, Task API Key and tsk Documentation
« Reply #4 on: December 09, 2020, 05:33:01 PM »
abolabo,

You have always been a great help to me. But, respectfully, I think you may have missed the problem I was trying to point out.

1. The documentation says to use the task.php file with CRON.
2. The task.php file requires the use of the task_api_key (which does need to be entered on the settings API page) and verifies the task api key is passed to the task.php file in order to run without error (see line 67 of task.php file).
3. CRON does not allow you to pass the task key variable in the file name and the task.php file does not have provisions to interpret any command parameters sent from CRON.

To sum it all up: No matter what I have tried I have not been able to successfully run task.php from CRON as it states in the documentation.

As I initially stated, I am currently using task_api.php in order to run the task fro CRON. The use of task_api.php is not even discussed in the documentation for setting up CRON.

What I am asking for is 1) a how to answer to number 3 above or 2) address the documentation discrepancy and/or 3) fix the task.php file.


Don Higbee

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Task.php, Task API Key and tsk Documentation
« Reply #5 on: December 10, 2020, 04:22:17 AM »
ahh,,

your trying to run wrong script.
You should to run task_cli.php instead task.php.
task php uses only for probressbar run inside admin (probablt you saw modal with progressbar, for ex. during backup or language definitions sync)
task_cli.php needed to call from shel (or cron).

We'll change manual.
Thank you
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

 

Powered by SMFPacks Social Login Mod