Jump to content

Enhancing Universal Module Service Notifications


NetworkJack

Recommended Posts

I've been working on converting our 2.5 Blesta up to a recent version (3.6.x) and one of the things I've been dealing with is replacing a custom integration module we had that allowed us to modify usernames/passwords in a mysql table that was used for RADIUS authentication.

I've decided to KISS and use the Universal Module and have it make POSTs to a server that does the actual work of modifying the records as needed for add/edit/cancel/ etc..... The only issue that the information passed in a POST for a Cancel/Suspend/Unsuspend is woefully inadequate to meet our needs of 100% properly identifying the record to modified. In Add/Edit, there is the _other variable that gets data set into it that are not being sent in the other actions. Only the Service level fields are sent. No client ID or Service ID, etc...

So I did a little digging in the source code and some debugging and ended up making one simple little change to the following methods:

UniversalModule->cancelService
UniversalModule->suspendService
UniversalModule->unsuspendService
UniversalModule->renewService

public function cancelService($package, $service, $parent_package=null, $parent_service=null) {
	$ServiceMeta = array('client_id' => $service->client_id, 'service_id' => $service->id, 'package_id' => $package->id, 'module_id' => $package->module_id, );
	if (!$this->sendNotification("service_notice_cancel", $service->fields, $package->module_row, $ServiceMeta, $package->meta)) {
		$this->Input->setErrors(array('service_notice_cancel' => array('failed' => Language::_("UniversalModule.!error.service_notice_cancel.failed", true))));
		return;
	}
	
	return null;
}

Basically it's that $ServiceMeta array that is populated and then sent in the fourth parameter ($additional_fields) to UniversalModule->sendNotification.

This way the receiving endpoint will have all the information required to reference whatever is needed.

BTW, this bit of code should help satisfy this Feature Request:

http://dev.blesta.com/browse/CORE-1698

 

Link to comment
Share on other sites

UPDATE

Took a little more tweaking. I made two specific changes:

  1. It was necessary to add a fourth parameter to the UniversalModule->processService method to get the ServiceMeta into the notification POST data for Adds and Edits. I consciously delayed merging that data as long as possible. (see $NotifyVars)
  2. The old service fields data is passed along on an Edit to help the remote service know how to locate the record(s) being changed.
public function addService($package, array $vars=null, $parent_package=null, $parent_service=null, $status="pending") {
  $ServiceMeta = array('package_id' => $package->id, 'module_id' => $package->module_id, );
  $meta = $this->processService("add", $vars, $package, $ServiceMeta);



public function editService($package, $service, array $vars=array(), $parent_package=null, $parent_service=null) {
  $ServiceMeta = array('client_id' => $service->client_id, 'service_id' => $service->id, 'package_id' => $package->id,
          'module_id' => $package->module_id, 'old_service_fields' => $service->fields);
  $meta = $this->processService("edit", $vars, $package, $ServiceMeta);



private function processService($type, array $vars, $package = null, $ServiceMeta) {

  if (isset($vars['use_module']) && $vars['use_module'] == "true") {
    $NotifyVars = array_merge($vars, $ServiceMeta);
    if (!$this->sendNotification("service_notice_" . $type, $meta, $module_row_id, $NotifyVars, $package->meta)) {
        $this->Input->setErrors(array('service_notice_' . $type => array('failed' => Language::_("UniversalModule.!error.service_notice_" . $type . ".failed", true))));
      return;
    }
  }

 

Link to comment
Share on other sites

  • 2 months later...

@NetworkJack i'd like to have client's email address to be part of the POST data.

Would adding 'client_email' => $client->email, to the  $ServiceMeta array of addService() do it?

 

EDIT: it obvisouly wouldn't as we need a way of passing a "client" object to be able to access it's properties.

Any hints about how to achieve this appreciated :=

 

 

Link to comment
Share on other sites

7 hours ago, fossxplorer said:

@NetworkJack i'd like to have client's email address to be part of the POST data.

Would adding 'client_email' => $client->email, to the  $ServiceMeta array of addService() do it?

 

EDIT: it obvisouly wouldn't as we need a way of passing a "client" object to be able to access it's properties.

Any hints about how to achieve this appreciated :=

 

 

I would avoid modifying any Blesta code as much as possible. If you modify it, you own it. Think about upgrades and merging in requests, etc. Of course, if there is no other way, then go for -- a very nice feature of Blesta.

The approach I would take is use Blesta's API to get all the information you need via HTTP ReST calls. The information Blesta posts today is enough for you to query the API and get the full record as it exists within Blesta.

https://docs.blesta.com/display/dev/API

-Adam

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.

Loading...
×
×
  • Create New...