tolja Posted October 3, 2016 Share Posted October 3, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
tolja Posted October 26, 2016 Author Share Posted October 26, 2016 Any idea what's causing this? We can't upgrade to v7 just yet to test out if things work better on that side. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 26, 2016 Share Posted October 26, 2016 you may share code of get_admin_user function 0 Quote Link to comment Share on other sites More sharing options...
tolja Posted October 26, 2016 Author Share Posted October 26, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted October 26, 2016 Share Posted October 26, 2016 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']; } 0 Quote Link to comment Share on other sites More sharing options...
tolja Posted October 26, 2016 Author Share Posted October 26, 2016 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. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.