Jump to content

Passing $vars['params']


Recommended Posts

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 by earthgirlllc
code edit
Link to comment
Share on other sites

  • 2 weeks later...

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 by Wouter0100
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