NetworkJack Posted April 4, 2017 Report Share Posted April 4, 2017 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 Blesta Addons, Paul and Michael 3 Quote Link to comment Share on other sites More sharing options...
Paul Posted April 4, 2017 Report Share Posted April 4, 2017 Thanks for the contribution. I've added a note to that task to refer to this thread. Michael 1 Quote Link to comment Share on other sites More sharing options...
NetworkJack Posted April 5, 2017 Author Report Share Posted April 5, 2017 UPDATE Took a little more tweaking. I made two specific changes: 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) 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; } } Michael 1 Quote Link to comment Share on other sites More sharing options...
fossxplorer Posted June 29, 2017 Report Share Posted June 29, 2017 @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 := Quote Link to comment Share on other sites More sharing options...
Adam Posted June 29, 2017 Report Share Posted June 29, 2017 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 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.