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.

  • But, aren't Entry Points deprecated and scheduled to be removed in a future release? I'd hate to depend on something that's going to disappear later. This looks like a promising approach, though!

  • This isn't one of the bwc entry points which were discussed above. This is basically THE file which loads sugar application, so don't worry it will become deprecated any time soon  (it is used in main index.php, api/rest.php, cron.php etc.)

  • No joy... it keeps redirecting me to an "install.php" file (my file was in the Sugar directories in custom/custom/ for lack of a better location):

    The requested URL /custom/custom/install.php was not found on this server.

  • You also need to change current directory to sugar root in the beginning of the script... I thought it was obvious  ( chdir("/path/To/Sugar/Root/") ). 

  • Michael Jones,

    There are many many ways to integrate with Sugar.

    I agree with Patrick McQueen that the most robust, elegant and future proofed solution is to leverage the provided REST API. This would give you the most flexibility if/when your system will outgrow what seems to be a single server architecture shared with other systems, and still have a fully working solution just by changing the REST http url endpoint.

    In addition to that, you can easily create custom REST apis that achieve complex actions and call those custom apis through REST. See here. You would leverage Sugar beans as a mean to do that, within the custom endpoint logic. 

    Then as the thread progressed, you have other options like using the provided CLI framework as well.

    Standalone scripts are another option but obviously those solutions make the system more tied down to the current infrastructure setup and will require a re-engineering in the future when changes occur.

    Additionally, exposing framework specific functionality to the outside world via a url, might expose your company to security risks as the framework is no longer acting in its full extent, to the actions accomplished by the users. As an example of incorrect unwanted behaviour, is the possible introduction of an unwanted SQL injection problem if the script is reachable via the web and post/get variables are not sanitised accordingly and passed to the database layer directly.

    Hope this helps you choose your solution of choice

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States