예제 #1
0
 /**
  * Trigger custom logic for this module that is defined for the provided hook
  * The custom logic file is located under custom/modules/[CURRENT_MODULE]/logic_hooks.php.
  * That file should define the $hook_version that should be used.
  * It should also define the $hook_array.  The $hook_array will be a two dimensional array
  * the first dimension is the name of the event, the second dimension is the information needed
  * to fire the hook.  Each entry in the top level array should be defined on a single line to make it
  * easier to automatically replace this file.  There should be no contents of this file that are not replacable.
  *
  * $hook_array['before_save'][] = Array(1, testtype, 'custom/modules/Leads/test12.php', 'TestClass', 'lead_before_save_1');
  * This sample line creates a before_save hook.  The hooks are procesed in the order in which they
  * are added to the array.  The second dimension is an array of:
  *		processing index (for sorting before exporting the array)
  *		A logic type hook
  *		label/type
  *		php file to include
  *		php class the method is in
  *		php method to call
  *
  * The method signature for version 1 hooks is:
  * function NAME(&$bean, $event, $arguments)
  * 		$bean - $this bean passed in by reference.
  *		$event - The string for the current event (i.e. before_save)
  * 		$arguments - An array of arguments that are specific to the event.
  */
 function call_custom_logic($event, $arguments = null)
 {
     if (!isset($this->processed) || $this->processed == false) {
         //add some logic to ensure we do not get into an infinite loop
         if (!empty($this->logicHookDepth[$event])) {
             if ($this->logicHookDepth[$event] > 10) {
                 return;
             }
         } else {
             $this->logicHookDepth[$event] = 0;
         }
         //we have to put the increment operator here
         //otherwise we may never increase the depth for that event in the case
         //where one event will trigger another as in the case of before_save and after_save
         //Also keeping the depth per event allow any number of hooks to be called on the bean
         //and we only will return if one event gets caught in a loop. We do not increment globally
         //for each event called.
         $this->logicHookDepth[$event]++;
         //method defined in 'include/utils/LogicHook.php'
         $logicHook = new LogicHook();
         $logicHook->setBean($this);
         $logicHook->call_custom_logic($this->module_dir, $event, $arguments);
     }
 }
예제 #2
0
 /**
  * Handle exception
  * @param Exception $e
  */
 protected function handleException(Exception $e)
 {
     $GLOBALS['log']->fatal('Exception in Controller: ' . $e->getMessage());
     $logicHook = new LogicHook();
     if (isset($this->bean)) {
         $logicHook->setBean($this->bean);
         $logicHook->call_custom_logic($this->bean->module_dir, "handle_exception", $e);
     } else {
         $logicHook->call_custom_logic('', "handle_exception", $e);
     }
 }
예제 #3
0
 /**
  * Trigger custom logic for this module that is defined for the provided hook
  * The custom logic file is located under custom/modules/[CURRENT_MODULE]/logic_hooks.php.
  * That file should define the $hook_version that should be used.
  * It should also define the $hook_array.  The $hook_array will be a two dimensional array
  * the first dimension is the name of the event, the second dimension is the information needed
  * to fire the hook.  Each entry in the top level array should be defined on a single line to make it
  * easier to automatically replace this file.  There should be no contents of this file that are not replacable.
  *
  * $hook_array['before_save'][] = Array(1, testtype, 'custom/modules/Leads/test12.php', 'TestClass', 'lead_before_save_1');
  * This sample line creates a before_save hook.  The hooks are procesed in the order in which they
  * are added to the array.  The second dimension is an array of:
  *		processing index (for sorting before exporting the array)
  *		A logic type hook
  *		label/type
  *		php file to include
  *		php class the method is in
  *		php method to call
  *
  * The method signature for version 1 hooks is:
  * function NAME(&$bean, $event, $arguments)
  * 		$bean - $this bean passed in by reference.
  *		$event - The string for the current event (i.e. before_save)
  * 		$arguments - An array of arguments that are specific to the event.
  */
 function call_custom_logic($event, $arguments = array())
 {
     if (!isset($this->processed) || $this->processed == false) {
         //add some logic to ensure we do not get into an infinite loop
         if (!empty($this->logicHookDepth[$event])) {
             if ($this->logicHookDepth[$event] > $this->max_logic_depth) {
                 return;
             }
         } else {
             $this->logicHookDepth[$event] = 0;
         }
         //we have to put the increment operator here
         //otherwise we may never increase the depth for that event in the case
         //where one event will trigger another as in the case of before_save and after_save
         //Also keeping the depth per event allow any number of hooks to be called on the bean
         //and we only will return if one event gets caught in a loop. We do not increment globally
         //for each event called.
         $this->logicHookDepth[$event]++;
         //method defined in 'include/utils/LogicHook.php'
         $logicHook = new LogicHook();
         $logicHook->setBean($this);
         $logicHook->call_custom_logic($this->module_dir, $event, $arguments);
         $this->logicHookDepth[$event]--;
         //Fire dependency manager dependencies here for some custom logic types.
         if (in_array($event, array('after_relationship_add', 'after_relationship_delete', 'before_delete'))) {
             $this->updateRelatedCalcFields(isset($arguments['link']) ? $arguments['link'] : "");
         }
     }
 }
예제 #4
0
 public function testprocess_hooks()
 {
     //execute the method and test if it doesn't throws an exception
     $LogicHook = new LogicHook();
     $LogicHook->setBean(new Account());
     $hooks = $LogicHook->loadHooks('');
     try {
         $LogicHook->process_hooks($hooks, 'after_ui_footer', array());
         $this->assertTrue(true);
     } catch (Exception $e) {
         $this->fail();
     }
 }
예제 #5
0
 /**
  * Handle exception
  * @param Exception $e
  */
 protected function handleException(Exception $e)
 {
     $GLOBALS['log']->fatal('Exception in Controller: ' . $e);
     $logicHook = new LogicHook();
     SugarMetric_Manager::getInstance()->handleException($e);
     if (isset($this->bean)) {
         $logicHook->setBean($this->bean);
         $logicHook->call_custom_logic($this->bean->module_dir, "handle_exception", $e);
     } else {
         $logicHook->call_custom_logic('', "handle_exception", $e);
     }
 }
예제 #6
-1
 /**
  * Static Function which returns and instance of LogicHook
  *
  * @param SugarBean|null $bean
  *
  * @return LogicHook
  */
 public static function instance(SugarBean $bean = null)
 {
     if (is_null(static::$instance)) {
         static::$instance = new static();
     }
     static::$instance->setBean($bean);
     return static::$instance;
 }