Results 1 to 6 of 6

Thread: Custom, auto-included file?

  1. #1
    Join Date
    Sep 2008
    Posts
    6

    Default Custom, auto-included file?

    Client is currently using a maimed Sugar 4.0.1 -

    Just wondering if anyone knows if there was/is a certain place to put files or a certain file name to use to have a function library automatically included.

    Trying to move some code into an 'upgrade safe' area.

    Thanks!

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Custom, auto-included file?

    Hi theLowlyContractor2

    Your needs are not so clear.
    Can you explain again?

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    Join Date
    Sep 2008
    Posts
    6

    Default Re: Custom, auto-included file?

    A bit like config_override is automatically checked and included when sugar is launched, I was wondering if there is a good place to put custom function definitions.

    Developers before me placed several custom functions in utils.php - I didn't know that, and after upgrading, several modules broke.

    I was wondering if there's an upgrade-safe location to place PHP content that should be automatically included when sugar is run.

    Did I just repeat my confusing request, or did that make more sense?

    Thanks for your time!

  4. #4
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Custom, auto-included file?

    Hi theLowlyContractor2

    Your needs are pretty clear now.

    Create a logic_hook after_retrieve into Users module:

    1. Create the file custom/modules/Users/logic_hooks.php with this content:

    PHP Code:
    <?php
    $hook_version 
    1;
    $hook_array = Array();

    $hook_array['after_retrieve'] = Array();
    $hook_array['after_retrieve'][] = Array(1'include_custom_functions''custom/modules/Users/UserHook.php','UserHook''include_custom_functions');
    ?>
    2. Create the file custom/modules/Users/UserHook.php with this content:

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    UserHook {
        function 
    include_custom_functions(&$focus$event$arguments) {
            global 
    $current_user;
            
            if(
    $focus->id == $current_user->id) {
                
    $path 'custom/include';
                
    $dir dir($path);

                while(
    $entry $dir->read()){
                    if(
    is_file($path '/' $entry) && $entry != '.' && $entry != '..') {
                        if(
    substr($entrystrlen($entry) - 44) == '.php') {
                            require_once(
    $path '/' $entry);
                        }
                    }
                }
            }
        }
    }
    ?>
    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  5. #5
    Join Date
    Sep 2008
    Posts
    6

    Default Re: Custom, auto-included file?

    So this would cause custom functions to be imported after the User bean/record/information is retreived from the database?

    Suppose I could search for "after_retreive" to find out where it's called...

  6. #6
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: Custom, auto-included file?

    Hi theLowlyContractor2

    Creating these 2 files as I had specified always when the user access any page into SugarCRM all php files inside custom/include/ will be loaded making available all functions inside them, automagicly.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Saving and updating custom fields data
    By jones70 in forum Developer Help
    Replies: 2
    Last Post: 2011-10-05, 06:10 AM
  2. Module Builder
    By Olavo in forum Downloads
    Replies: 418
    Last Post: 2009-02-26, 06:36 AM
  3. Replies: 3
    Last Post: 2008-07-17, 01:17 PM
  4. Replies: 3
    Last Post: 2006-02-17, 05:12 PM
  5. Login File Main Scree Custom
    By perweb in forum Help
    Replies: 2
    Last Post: 2006-01-29, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •