Jump to content

Local api not working properly, sometimes


tolja

Recommended Posts

With the following code on a cron hook, I occasionally get "No matching admin user found" error message instead of the invoice I'm after.

$values["invoiceid"] = $data['whmcs_id'];
$invoice = localAPI('getinvoice', $values, get_admin_user());

(get_admin_user function just returns the admin user I have set in my module settings)

 

I'm using a cron task to add invoice payments for invoices and lately the amount of invoices I'm processing at the same time has been increasing.

 

This same piece of code worked properly up until now and the only ways I'm able to get around this error are:

  • Switch my function get_admin_user to return id instead of the admin username, but this fixed the problem only for a few days
  • Use a different admin account
  • Run my script through admin rather than on cron hook

 

However, switching the accounts isn't a proper fix and I need to be able to run my script through cron.

The admin user I'm using primarly for this has full permissions and it's account is active and the WHMCS version I'm using is 6.3.1.

Link to comment
Share on other sites

  • 4 weeks later...

function get_admin_user(){
   return $_SESSION['adminid'] ?: get_setting('admin_user');
}
function get_setting($setting){
   $result = nv_full_query("SELECT setting, value FROM tbladdonmodules WHERE module = 'mymodule' AND setting = '$setting'");
   $data   = $result->fetch();
   return $data ? $data['value'] : null;
}

 

- - - Updated - - -

 

I have also verified that the get_admin_user function returns a proper username even when I'm getting the error.

Link to comment
Share on other sites

you need to provide admin username not ID, maybe it work when you're logged-in as admin, let's modify your code a little and see

 

function get_admin_user(){
   return get_setting('admin_user');
}
function get_setting($setting){
   $result = nv_full_query("SELECT * FROM `tbladdonmodules` WHERE `module`='mymodule' AND `setting`='".$setting."'");
   $data   = $result->fetch();
   return $data['value'];
}

Link to comment
Share on other sites

Local api accepts both the username and id as admin parameter.

 

// these produce the same result
localAPI('getinvoice', array('invoiceid' => 1000), 'admin');
localAPI('getinvoice', array('invoiceid' => 1000), 1);

 

The problems is that localAPI('getinvoice') sometimes returns invalid results with valid parameters.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated