Say that you developed a cool logic hook and are ready to put it into use on your production instance of SugarCRM. However, you are faced with the challenge of the production instance being hosted on the SugarCRM OnDemand platform.
For those of you that are new to the world of logic hooks, the OnDemand environment presents a unique challenge in that in order for one to make use of logic hooks in general, one has place the logic hook files in specific sub-folders within the folder containing your SugarCRM installation. You would not have access to said folders for OnDemand installations. Thus, our challenge.
So how do we solve this problem?
Fortunately, we can leverage one of built-in features of SugarCRM to bypass the issue. Using the Module Loader tool, we can install or uninstall the logic hook at will.
But to do this, we must first create a Module Install package. Let us take a look at how we would prepare it for the purposes of installing the proper casing logic hook described in a previous post of mine.
From this point forward, it is assumed that you have already created the files corresponding with that logic hook and we will focus exclusively on the process required to install it via the Module Loader and in turn, apply them to an OnDemand instance.
To prepare the install package, you will first need to create a manifest.php file. This is a text file containing instructions that tell SugarCRM to perform specific tasks. For our needs, we need to instruct it to copy the code executed by the logic hook and also create the logic hook instruction file.
Below are the contents of the manifest.php file we will use:
Project: Logic Hooks Manifest
Original Dev: Angel Magaña, April 2011
@2009-2011 Angel Magaña
Desc: Manifest file for installing logic hook
The contents of this file are governed by the GNU General Public License (GPL).
A copy of said license is available here: http://www.gnu.org/copyleft/gpl.html
This code is provided AS IS and WITHOUT WARRANTY OF ANY KIND.
$upload_dir = $sugar_config['upload_dir'];
$manifest = array(
'acceptable_sugar_versions' => array(
'regex_matches' => array(
0 => '6\.*'
'acceptable_sugar_flavors' => array(
0 => 'CE',
1 => 'PRO',
2 => 'ENT',
'name' => 'Sample Logic Hook',
'description' => 'Logic Hook installation package.',
'is_uninstallable' => true,
'author' => 'Angel Magaña',
'published_date' => 'April 15, 2011',
'version' => '1.0.0',
'type' => 'module',
$installdefs = array(
'id' => 'CG_LogicHook',
'mkdir' => array(
array('path' => 'custom/modules/Contacts'),
'copy' => array(
'from' => '<basepath>/NewFiles/proper_test.php',
'to' => 'custom/modules/Contacts/proper_test.php',
'logic_hooks' => array(
'module' => 'Contacts',
'hook' => 'before_save',
'order' => 96,
'description' => 'Proper Casing',
'file' => 'custom/modules/Contacts/proper_test.php',
'class' => 'ProperText',
'function' => 'convertToProper',
Now we need to create the actual installer package. This is a simple archive file (zip) containing the manifest.php file, along with the file containing the code executed by the logic hook. Note that we do not actually need to include or create a logic_hooks.php file. The logic_hooks section within the manifest.php file will create it for us upon installation.
To create the install package:
- Create a new folder named InstallerTemp
- Within InstallerTemp, create another new folder named NewFiles
- Place the file proper_test.php in the NewFiles folder
- Navigate one level up, to the InstallerTemp folder
- Save the manifest.php file to the InstallerTemp folder
Lastly, create the zip archive file. If you are a Windows user, simply select the manifest.php file and the NewFiles folder, right-click and choose Send To > Compressed (zipped) Folder. We will assume the resulting file is named MyInstallPackage.zip.
It is important that the resulting zip archive reflects a structure similar to the following:
|__ manifest.php (file)
|__ NewFiles (folder)
|__ proper_test.php (file)
If the structure does not match, the Module Installer will fail, usually with an error indicating that the manifest file could not be found.
Assuming everything is in order, you can proceed to install it by accessing SugarCRM and selecting Admin > Module Installer, browsing to and uploading MyInstallPackage.zip and clicking Install.
Once the installation completes, your logic hook is ready for use!