SugarCRM hook – what are they

SugarCRM is a very nice and open source CRM (Customer relationship management) system. And with being open source means that you are able to alter the internals of it and also are able to write modules for it easier than closed source applications because you can follow the direction of things if you are for example debugging etc.

The hooks part of the sugarCRM setup allows to place your own code into the base code at set parts of execution e.g. after retrieve of data, or post processing of data updates.

Here is a link to the sugarcrm site of hooks definitions. Basically there is 3 main types, with subhooks attached to those types.

  • Application hooks
    • after_ui_frame – Fired after the frame has been invoked and before the footer has been invoked
    • after_ui_footer – Fired after the footer has been invoked
    • server_round_trip – Fired at the end of every SugarCRM page
  • Module hooks
    • before_delete – Fired before a record is deleted
    • after_delete – Fired after a record is deleted
    • before_restore – Fired before a record is undeleted
    • after_restore – Fired after a record is undeleted
    • after_retrieve – Fired after a record has been retrieved from the database. This hook does not fire when you create a new record.
    • before_save – Fired before a record is saved.
    • after_save – Fired after a record is saved.
    • process_record – Fired immediately prior to the database query resulting in a record being made current. This gives developers an opportunity to examine and tailor the underlying queries. This is also a perfect place to set values in a record

Linux – memory and where is it

To find out what memory you have onboard and also where it is, here is a neat command

lshw -class memory

Here is my output

  *-firmware                                 
       description: BIOS
       vendor: Acer
       physical id: 0
       version: V2.04 (01/15/07)
       size: 103KiB
       capabilities: isa pci pcmcia pnp apm upgrade shadowing escd cdboot acpi usb agp biosbootspecification
  *-cache:0
       description: L1 cache
       physical id: 5
       slot: L1 Cache
       size: 16KiB
       capacity: 16KiB
       capabilities: asynchronous internal write-back
  *-cache:1
       description: L2 cache
       physical id: 6
       slot: L2 Cache
       size: 4MiB
       capabilities: burst external write-back
  *-memory
       description: System Memory
       physical id: 12
       slot: System board or motherboard
       size: 2GiB
     *-bank:0
          description: SODIMM Synchronous
          physical id: 0
          slot: M1
          size: 1GiB
          width: 32 bits
     *-bank:1
          description: SODIMM Synchronous
          physical id: 1
          slot: M2
          size: 1GiB
          width: 32 bits

I basically have 2GiB of memory and also L1 cache (on die cache on the cpu) of 16KiB and 4MiB L2 Cache.

Here is a wiki page that details what L1 and L2 cache are CPU cache, basically L1 means on CPU die, and L2 means slightly further away from the L1 cache. If there is a memory call L1 is the first hit, then L2 and then the memory and then swap space (harddrive), the lower down the line means slower result time.

SugarCRM add a new menu item

SugarCRM is a very nice and open source CRM (Customer relationship management) system. Being open source means that you are more than welcome to add/alter your own modules to it. I am going to do some modules which add in some basic information and how-to’s. This how to is how to add to a left menu item and in this case a account main menu left menu item.

Also going to be doing a module for it, so that you can upload to different SugarCRM’s that you may have, e.g. development version and live version.

The module consists of the main manifest.php file which holds all of the main details, module name author, description etc and also the install definitions.

Here is a basic manifest.php file that has the main details and install definitions for adding a menu item to the Accounts module.

<?php
$manifest = array(
  'acceptable_sugar_flavors' => array(
          0 => 'CE',
          1 => 'PRO',
          2 => 'ENT',
          3 => 'DEV'
        ),
    'acceptable_sugar_versions' => array (
        'regex_matches' => array (
            0 => "5\.*\.*.*"
        ),
    ),
 
    'name'              => 'Accounts insert left menu addition',
    'description'       => 'This module inserts a left menu addition',
    'author'            => 'Ian Porter',
    'published_date'    => '2009/06/01',
    'version'           => '0.1',
    'type'              => 'module',
    'icon'              => '',
    'is_uninstallable'   => 1,
    'silent' => true,
);
 
$installdefs = array (
  'id' => 'AccountsLeftMenu',
    'vardefs'=> array( ),
  'custom_fields' =>  array (  ),
  'copy' =>
  array ( ),
'menu'=> array(
array('from'=> '<basepath>/Menu.php',
'to_module'=> 'Accounts', ),
),
       'beans'=> array (
                 ),
  'language' => 
  array (
  ),
);
?>

As you can see from the above code, the acceptable sugar flavors means any of the version types of sugar, development, pro etc.. and the acceptable sugar versions means which version of sugar e.g. version 4.1.2 or 5.etc. the name etc speaks for itself really.

The installdefs are what happens with the files and such when the module is installed, id is the name of the module, the one that we are focusing in on is menu, this will insert the code below into the a set menu module (this case the Accounts menu structure).

Here is the Menu.php file

<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
 
/* licence and you stuff */
 
global $mod_strings, $app_strings, $sugar_config, $current_user;
 
/* you need to create the DetailViewPersonal.php file to communicate with */
 
if(ACLController::checkAccess('Accounts', 'edit', true)) {
    $module_menu[]=Array("index.php?module=Accounts&action=DetailViewPersonal&return_module=Accounts&return_action=DetailView&record=".$current_user->id, "Personal View",  'Accounts');
}
?>

The ACLController will check the access level of the user for editable, ACL(Access Control Level), and if so place a new menu below called “Personal View”, the action in the module_menu array is what is called and thus you will need to have a DetialViewPersonal.php in the modules/Accounts directory, but this was just a how to, of how to insert a menu item and not the underlying code.

There is more to come!.