earthgirlllc Posted August 6, 2020 Share Posted August 6, 2020 (edited) Hi, I'm new to WHMCS dev and trying to piece a hook together. I can't figure out how to pass values from the parameter array to my query. This is what I have so far, any help appreciated. 🙂 There are no errors in the activity log and no PHP errors. Hook debug is on and these are the only pertinent entries (not in this order): Hooks Debug: Hook Point AfterModuleSuspend - Calling Hook Function (anonymous function) Hooks Debug: Hook File Loaded: /home/*****/public_html/modules/addons/callfire/hooks.php Hooks Debug: Attempting to load hook file: /home/*****/public_html/modules/addons/callfire/hooks.php Hooks Debug: Hook Defined for Point: AfterModuleSuspend - Priority: 1 - Function Name: (anonymous function) Thank you! <?php use Illuminate\Database\Capsule\Manager as Capsule; add_hook('AfterModuleSuspend', 1, function($vars) { $userid=$vars['params']['userid']; $domain=$vars['params']['domain']; try { Capsule::connection()->transaction( function ($connectionManager2) { $connectionManager2->table('mod_callfire')->insert( [ 'userid'=>$userid, 'message'=>$domain, 'status'=>'Pending', ] ); } ); } catch (\Exception $e) { } });  Edited August 7, 2020 by earthgirlllc code edit 0 Quote Link to comment Share on other sites More sharing options...
earthgirlllc Posted August 19, 2020 Author Share Posted August 19, 2020 Anyone? 0 Quote Link to comment Share on other sites More sharing options...
Wouter0100 Posted August 20, 2020 Share Posted August 20, 2020 (edited) It seems that this is not really a WHMCS thing. It's more of a PHP issue. There are some things to know: Your vars $userid and $domain are most likely not available within your transaction (because there's an anonymous function involved). Use `use ($userid, $domain)` behind `function ($connectionManager2)` to get the variables within your function. You've catched errors with no further processing or printing and thus there will be none in your error log. You could remove the try-catch statement, in this case WHMCS will catch any Exceptions if thrown. Or just print `var_dump($e)` in your catch statement. You don't need to setup a transaction. You're able to do queries more easily by doing `Capsule::table(`bla`)->insert`. Edited August 20, 2020 by Wouter0100 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.