Faster SugarCRM Development with PHPStorm

Sun 30 April 2017


Javascript development with SugarCRM can be a bit of a pain, however combining PHPStorm's filewatcher tool with a cut down repair script can speed things up to a more tolerable level.

What this setup does is watch for any javascript changes in our custom/ folder(because you're not making core hacks are you?) and execute a light-weight repair script when any of those files change. So you'll hit save in PHPStorm, wait a few seconds and your dev javascript should be refreshed and ready to test.

The Repair Script

First thing to do is get our hands on a fast repair script. Thankfully FrancescaS on the SugarCRM forums came up with a tidy javascript focused version of a repair script(originally by Jeff Bikart. The whole thread is here but I'll reproduce the code below for the lazy.

 * Copyright 2013
 * Jeff Bickart
 * @bickart
 * jeff @
 * modified by FrancescaS @ to repair/rebuild
 * only what absolutely necessary to work on js scripts
if(!defined('sugarEntry'))define('sugarEntry', true);
//Bug 27991 . Redirect to index.php if the request is not come from CLI.
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) != 'cgi') {
    global $sugar_config;
                header("Location: ".$sugar_config['site_url'] . "/index.php");
                sugar_die("Didn't find site url in your sugarcrm config file");
//End of #27991
if(empty($current_language)) {
        $current_language = $sugar_config['default_language'];
$app_list_strings = return_app_list_strings_language($current_language);
$app_strings = return_application_language($current_language);
global $current_user;
$current_user = new User();
$GLOBALS['log']->debug('--------------------------------------------> at repair.php <--------------------------------------------');
$repair = new RepairAndClear();
// replace the repairAndClearAll with a limited set or clear actions
//$repair->repairAndClearAll(array('clearAll'),array(translate('LBL_ALL_MODULES')), true,false,'');
        $repair->module_list= array(translate('LBL_ALL_MODULES'));
        $repair->show_output = false;
        $repair->execute= true;
$exit_on_cleanup = true;
// some jobs have annoying habit of calling sugar_cleanup(), and it can be called only once
// but job results can be written to DB after job is finished, so we have to disconnect here again
// just in case we couldn't call cleanup
if(class_exists('DBManagerFactory')) {
        $db = DBManagerFactory::getInstance();
if($exit_on_cleanup) exit;

Take this file and move it to your ~/Bin folder or wherever you tend to put these one off little scripts.

The Watcher

The next thing to do is configure PHPStorm to start watching for Javascript file changes.

Go into Settings->Tools->File Watchers and hit the green plus to add a new watcher.

My file watcher configuration looks like this:


So, ensure the 'File type' is Javascript, then add a new scope. Essentially the scope configures which files to watch. My scope for getting all files in the custom folder in my project looks like this:


Simply alter your pattern to whatever your SugarCRM project structure looks like.

You should see a count of the number of files the scope has detected in the project and it should be more than 0, so use that as a guide to ensure the scope is correctly identifying all your interesting javascript files.

Once the scope is sorted, back in the watcher configuration, for the 'Argument' setting you will need to put in the path to the repair script from above then finally, for the 'Working Directory' put the root of the SugarCRM source.

After all of that is configured make some changes to a javascript file, hit save and hopefully you should see the 'Watch for JS Changes' task running for a few seconds.

Category: sugarcrm Tagged: sugarcrm php phpstorm


SugarCRM 7 - Conditional Read Only Fields

Sat 06 February 2016

SugarCRM has a few ways to set fields as read-only, but it leaves a lot to be desired. One of the missing features that you might need to implement is having a module flagged as read-only on the record view based on a field on the module or the result …

Category: SugarCRM


Read More

SugarCRM - Conditional Actions

Thu 15 October 2015


Say you need to hide certain actions in Sugar depending on the status of a field, I've come across a great snippet of code from an awesome comment by Felix Nilam on the SugarCRM forums and wanted to show you a brief snippet of how it could work.

Make sure …

Category: SugarCRM


Read More

SugarCRM - Prevent currencies getting overridden

Thu 16 April 2015


SugarCRM has some neat features involving currency rates, but one of the more annoying ones is that Sugar will automatically update the base rate every time you save a record with a currency field attached. This can be fairly annoying default behaviour if you wish to maintain the correct record …

Category: SugarCRM


Read More

SugarCRM 7 - Custom subpanels

Wed 13 August 2014


This tutorial should hopefully help you to create a new subpanel under the Contacts module in Sugar using a custom link class and driven by SugarCRM 7's new SugarQuery API.

1. Create a new link class

This should go into custom/modules/<YourModule>/YourNewLink.php and this class will act …

Category: SugarCRM Tagged: mysql php subpanels


Read More
Page 1 of 3

Next »