Sugar 7 API Wrapper Class Updates

Previously, the wrapper class was… well… just that, a class. Working with custom endpoints was awkward and felt hacky. The more I dived in to Sugar 7 customization the more I realized I needed something more flexible and future proof.

That something is, at the time of this writing, the latest push to github.

Now the wrapper class is now a facade to a more powerful rest client. The reason for going this route was to keep the class intuitive but also allow a developer more flexibility. Prior to this latest push to github, in order to support a new endpoint a new method in the wrapper class had to be coded. Now, with a simplified rest client and improved facade you can easily work with custom endpoints and endpoints that have not been defined in the wrapper class.

Does this mean new features? Of course!

There have been 4 new methods added to the wrapper class. Those 4 methods allow you to interact with any endpoint that is not covered by the wrapper class. This includes both custom and stock endpoints.

Examples of these endpoints are:

<?php
$sugar = new \Spinegar\Sugar7Wrapper\Rest();

$sugar->setUrl('https://sugar/rest/v10/')
    ->setUsername('restUser')
    ->setPassword('password')
    ->connect();
    
/* Get Endpoint*/
$arguments = array();
$result = $sugar->getEndpoint('MyCompany/MyAddon/MyGetEndpoint', $arguments);

/* Post Endpoint*/
$arguments = array();
$result = $sugar->postEndpoint('MyCompany/MyAddon/MyPostEndpoint', $arguments);

/* Put Endpoint*/
$arguments = array();
$result = $sugar->putEndpoint('MyCompany/MyAddon/MyPutEndpoint', $arguments);

/* Delete Endpoint*/
$arguments = array();
$result = $sugar->deleteEndpoint('MyCompany/MyAddon/MyCustomDeleteEndpoint', $arguments);

Nifty, right? Enjoy!

Securing Laravel Push Queues

Push queues are the all the hype at the moment. However, I have not seen much discussion around securing them. Thats likely do the the simplicity of securing the receiving route, but either way…lets cover it.

There are two basic ways to secure the receiving route.

  • SSL – Use a security certificate to secure the connection.
  • Token and Route Filter – Build a route filter that requires a valid token.

Route Filter & Route Example

Configure the subscriber URL on iron.io to look something like the following. In this example the URL query string is set to the value of the iron.io token in app/config/queue.php.

SugarCRM Logic Hook Improvements

Edit 1: In response to comments from Jason Eggers I have updated my closure concept to include labels so that they can be identified and uninstalled.

Edit 2: Chad Hutchins further contributed to this concept with a basic outline of a helper class. This post has been updated accordingly.

Like a lot of you SugarCRM dev’s, I find myself creating simple logic hooks fairly often. While this is a simple task I feel that it could be even simpler. Lets look at the current process of creating a logic hook.

1. Create the file /custom/modules/{module}/logic_hooks.php

2. Create your logic hook class at /custom/modules/{module}/logic_hooks_class.php

Two easy steps. That’s all it takes. While this is pretty straight forward I cant help but feel like its an unnecessary amount of work for executing 1 function.

If logic_hooks.php were to support closures (PHP 5.3.0 +) we could achieve all of the above in 1 file (logic_hooks.php) and eliminate the need for the “logic_hooks_class” class all together.

Here is a brief example of how it could potentially work:

In 1 file and roughly 10% of the initial code required we have included all of our logic which makes the logic hook easier to maintain and quicker to write. Personally, this would eliminate at least 75% of my logic hook related files.

Somewhere deeper in the SugarCRM platform this code could be executed with something along the following lines:

To further make using logic hooks more efficient Chad Hutchins has contributed the following helper class concept to make adding and removing logic hooks that much easier.

Thoughts? Opinions? I would love to hear some feedback on this concept!