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


Command line calendars with Khal and fastmail

Tue 04 April 2017

Recently I've been on a bit of a command line kick and I started using khal to render my calendar agenda locally.

All of the codebases used are python based so before I start I've created a virtualenv so as not to pollute my OS.

mkvirtualenv khal
workon khal

Vdirsyncer …

Category: Linux


Read More

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

NetworkX - Get all Paths from all sources to sinks

Wed 04 November 2015

Often when I'm working with graphs and a set of masses in a spectrum I need to be able to iterate over all paths for all sources and sinks in that graph. Especially if I'm looking to compare multiple ideal spectrums against a given spectrum. Here's some code that will …

Category: Python


Read More

Generate Binary Tree From String

Tue 27 October 2015

Recently while implementing the Small Parsimony Problem I had the need to generate a binary tree from a string in Python.

The pseudo-code in the question implicitly assumes you have some functionality that will generate a DNA sequence like CAAATCCC into a binary tree, then run SmallParsimony on it. I …

Category: Python


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

Tiddlywiki to Org-Mode

Mon 31 August 2015


Okay, I swear this is the last document conversion script I’m writing this year. I’ve been on a bit of a rampage to move all of my life in Emacs Org-Mode and converting all of my Tiddlywiki notes into Org mode has been on my list for a …

Category: Projects Tagged: projects python emacs


Read More
Page 1 of 12

Next »