Using SugarBeans outside of Sugar's framework

We need to be able to run PHP code that makes use of Sugar data in scripts that are outside of Sugar - not scheduler tasks or logic hooks or anything. Completely outside of the Sugar world. Based on what I found here I added the following to my script:

if(!defined('sugarEntry')) define('sugarEntry', true);

require_once('data/BeanFactory.php');

That led to a string of error messages and including various other files, and then I started by including the same files in the base index.php from my Sugar installation, but finally I came to an impasse. My error message is:

 

Notice: Undefined index: log in /var/www/html/include/SugarObjects/VardefManager.php on line 1054 Fatal error: Call to a member function debug() on null in /var/www/html/include/SugarObjects/VardefManager.php on line 1054

The code at line 1054 of VardefManager.php is:

$GLOBALS['log']->debug("VardefManager::loadVardef called for module: $module");

I can't find where "log" is being defined in the GLOBALS scope, and anyway, this is starting to look like a lot more than I should have to do to make this work - my current code draft has six require_once statements in it, not to mention several other very hacky details. Is there a better way to do this? Am I missing something?

Sugar 7.8 Professional.

Parents Reply Children
  • That actually is helpful, if only to confirm that I'm not missing something obvious. I had seen information about the endpoints and that they were being deprecated. If I understand correctly, including the code "if(!defined('sugarEntry')) define('sugarEntry', true);" basically is sidestepping the endpoint functionality anyway, with, as you said, security ramifications that need to be addressed. My code won't be running on our Sugar domain, but it will be on the same server with access to the same PHP code, so using REST calls seems excessive to me. Like using a pool cue to change the channel from across the room instead of pressing a button on the remote. It would incur network traffic for the machine to talk to itself, instead of just running code locally.

    Maybe our configuration is unusual, and that's why I'm struggling. I just want to use the SugarBean ORM functionality to make minor changes so I can leverage business logic baked in by the Sugar developers. It's looking like doing that may unfortunately be more trouble than it's worth, and I'm going to wind up having to do direct database inserts and hope I address all of the relevant details when I do so.