Each Sugar customer also has the ability to customize their system to make it work exactly as they need it. This poses a challenge for Add-Ons that get installed into Sugar customer environments because you need to ensure that your added functionality does not conflict or break existing customizations in the Sugar system.

Because of that, it is important to use the Extension Framework to create customization-aware solutions. However there are some rare cases where a customization cannot be done using the Extension Framework and requires that you override a core application file with a custom version.

If that happens to be the case, and every effort was made to find a safer way of doing customization, then it is important to check to see if that custom file already exists in an install and if it was already changed as part of different customizations. If it does exist already, then it should then be backed up in a safe manner along with an honest effort to let the customer installing the add-on know that a file has been backed up.

Below is an example of doing such a backup process. You can add a backup script to your Module Loadable Package zip by creating a pre_execute.php file in a scripts directory. This will automatically be picked up and ran by the Module Loader during install.

SugarCloud Support

Note that SugarCloud has many restrictions on the PHP APIs you are allowed to use and, in particular, it does not allow you to use File I/O APIs.

See Module Loader Restriction Alternatives

Here is an example pre_execute script that will output that files exist and abandon the install:

/scripts/pre_execute.php



$now = time();

$existing_file = 'custom/modules/Accounts/views/view.list.php';
if (SugarAutoloader::fileExists($existing_file)) {
    $new_file = 'custom/modules/Accounts/views/view.list'.$now.'.php';
    
    $message = 'Please back up '.$existing_file.' to '.$new_file.'. Remove '.$existing_file.' and try the installation again';
    echo $message;
    $GLOBALS['log']->fatal($message);

    exit;
}

In the rare case that SugarCloud does NOT need to be supported

Here is a pre_execute script that will back up an existing custom file prior to installation.

/scripts/pre_execute.php



$now = time();

$existing_file = 'custom/modules/Accounts/views/view.list.php';
if(file_exists($existing_file)) {
    $new_file = 'custom/modules/Accounts/views/view.list'.$now.'.php';
    
    $message = 'Backed up '.$existing_file.' to '.$new_file;
    echo $message;
    $GLOBALS['log']->fatal($message);

    rename($existing_file,$new_file);
}