dev in Suite vs CE?

Hey! If Iā€™m creating a custom module that uses the same code for Suite and CEā€¦how can I tell if I am in Suite or CE? My initial thought is to use the config for suitecrm_version, something like:

global $sugar_config;
if (!empty($sugar_config[ā€™suitecrm_versionā€™]))
{
// run suite code
}
else
{
// run ce code
}

Any thoughts or best practices here? Thanks for any suggestions!

check to see if the suitecrm_version.php file exists in the root of your instance.

if so the your using suite. otherwise you are using sugar.

Thanks for that! Can you advise why itā€™s better to make that call than to use the config? I was thinking the config would be less intensive?

It makes little difference in terms of performance or in best practices.

Checking for the suitecrm_version.php file is functionally agnostic. it doesnā€™t require an entrypoint to pre-fetch the dependencies and set up the SugarApplication class object.

It is particularly useful when you are creating a php script outside of SuiteCRM. However to get the version of suitecrm using an external script: you will need to set up a fake ā€˜sugarEntryā€™ global variable, require the file and then use $suitecrm_version variable get the version your are working with.

In your case using the $sugar_config global makes sense because the SugarApplication will have already setup the globals for you. But the solution I gave is the most robust way to check to see if you are using SuiteCRM. Getting the version depends on the context of your code. As version handling, is left up to you to deal with.

You may just explode the version number to get the major, minor, patched numbers.

1 Like

Also there is little architectural difference between SuiteCRM and Sugar CE. Itā€™s the modules that are different. So that if you intend to use a module that only exists in SuiteCRM then it would be a better way to check the $moduleList and the $beanList instead.

I appreciate the deep answer and explanation! Thanks.