AnsweredAssumed Answered

Logic Hook not working - Sugar Enterprise Edition

Question asked by Ramon Marcondes on Feb 23, 2016
Latest reply on Jun 1, 2016 by Ramon Marcondes

Hello.

I'm using SugarCRM Enterprise Edition 7.5.2.4, using an "On Demand" instance.

I developed a logic hook to the native module "RevenueLineItems", that is related to the module "Opportunities".

The logic is: on creating a RevenueLineItem (here I will treat as "Revenue", for simplifying...) for the Opportunity, it updates the Opportunity sales status with the Revenue sales stage value.

 

The first time I installed there was a missing "?>" in the php code, causing an infinite loop on saving the Revenue, and there weren't any logs I wrote for the hook in the sugar.log file. I tried to uninstall the module, but it didn't succeed.

Second time, I corrected the code and installed an updated package on the CRM. The Revenue was saving correctly, but the logic hook still didn't work, without a single log registered.

 

So, what I'm doing wrong? May be the old module version causing the problem, or there is something wrong with my code?

 

manifest.php:

<?php
$manifest = array(
    'acceptable_sugar_flavors' => array('CE','PRO','CORP','ENT','ULT'),
    'acceptable_sugar_versions' => array(
        'exact_matches' => array(),
        'regex_matches' => array('(.*?)\\.(.*?)\\.(.*?)$'),
    ),
    'readme' =>'',
    'author' => 'Ramon Marcondes',
    'description' => 'Modulo - Receita de Item de Linha (RevenueLineItems)',
    'icon' => '',
    'is_uninstallable' => true,
    'key' => 'mod_revenuelineitems',
    'name' => 'RevenueLineItems',
    'published_date' => '2016-02-22 14:00:00',
    'type' => 'module',
    'version' => '1.1',
);
$installdefs = array(
    'id' => 'revenuelineitem',
    'copy' => array(
        0 => array(
            'from' => '<basepath>/custom/modules/RevenueLineItems/lh_revenuelineitems.php',
            'to' => 'custom/modules/RevenueLineItems/lh_revenuelineitems.php',
        ),
    ),
    'logic_hooks' => array(
        array(
            'module' => 'RevenueLineItems',
            'hook' => 'after_save',
            'order' => 99,
            'description' => 'Logic hook - Receita Itens de Linha',
            'file' => 'custom/modules/RevenueLineItems/lh_revenuelineitems.php',
            'class' => 'Receita',
            'function' => 'receita_save',
        ),
    ),
);
?>

 

And the lh_revenuelineitems.php (the logic hook code):

<?php
if (!defined('sugarEntry') || !sugarEntry) {
    $GLOBALS['log']->fatal("Receita - not a valid entry point!");
    die('Not A Valid Entry Point');
}

class Receita {   
    function receita_save($bean, $event, $arguments) {
        //require_once('log4php/LoggerManager.php');
        //$db = DBManagerFactory::getInstance();
        $GLOBALS['log']->fatal('Receita chegou aqui');
        
        if ($bean->load_relationship('opportunities')) {  
            $GLOBALS['log']->fatal("Receita encontrou oportunidade relacionada");
            $relatedBeans = $bean->opportunities->getBeans();
            if (!empty($relatedBeans)) {
                $GLOBALS['log']->fatal("Encontrou oportunidade");
                $parentbean = current($relatedBeans);
                $parentbean->sales_status = $bean->sales_stage;
                $parentbean->save();
            } else {
                $GLOBALS['log']->fatal("Não encontrou oportunidade");
            }       
        } else {
            $GLOBALS['log']->fatal("Receita não encontrou oportunidade relacionada");
        }              
    }
}
?>

 

Any help would be appreciated.

Thanks.

Outcomes