AnsweredAssumed Answered

logic hook cannot redeclare class

Question asked by Jerry Way on Jul 24, 2016
Latest reply on Jul 25, 2016 by M Waleed Raza



I'm new to the v7.7 style of Sugar customization.  I have a heavy background in the 6.5 pro world but was out of that while Sugar moved on.  Now I'm trying to deploy a logic_hook.  I've read a bit about the name spaces but not having much time I've elected to go with the old school way though not so far back as to invoking backward compatibility.


My problem is that when I save the opportunity record I get the following error in the Apache error log

Cannot redeclare class clsOpptUpdate in /var/www/html/sugarcrm/custom/Extension/modules/Opportunities/Ext/LogicHooks/OpptUpdate.php on line 10,

If you look at the code below I'm clearly I'm not redeclaring the class.  Other than in the Logic hook calling file.

All this code does is look to see if a radio button is set to yes. If it is then there's a query run to find a max value and a value from a field in the account.  Then one is added to the max of the opportunity ID an a new ID is created.

Is there something new that I'm not aware of?  Any help is greatly appreciated.


I've added the code below.

I've created my logic hook file as /var/www/html/sugarcrm/custom/modules/Opportunities/logic_hooks.php


        $hook_array['before_save'][] = array(


                        'Opportunity ID Generated',






And my logic code is in: /var/www/html/sugarcrm/custom/Extension/modules/Opportunities/Ext/LogicHooks/OpptUpdate.php


if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

//Need to verify the oppt ID created to make sure nobody else chose the same number before saving.  If it is, create a new one

// save.





class clsOpptUpdate {

    function OpportunityUpdate($bean, $event, $arguments)


        //Verify Oppt id against db oppt id.  If necessary, increment one before saving.

        //This is done since the ID might be requested via javascript some time prior to saving the record

        //In the interim somone may have requested the same id.


        if ($bean->create_oppt_id_c == 'Yes'){

            $IDLen = '';

            $CompDivCode = '';

            $bean->create_oppt_id_c = 'No';


                if ($bean->load_relationship('accounts'))


                        $relatedBeans = $bean->accounts->getBeans();

                        $parentBean = false;

                        if (!empty($relatedBeans))



                                $parentBean = current($relatedBeans);

                                $accountBeanDiv = $parentBean->company_division_c;




                        $CompDivCode = substr($parentBean->company_division_c,0,1);

                        $OpptID_Date = date("Ymd");

                        $sqlSelectID = "Select substring_index(oppt_id_c, '-', -1) maxid from opportunities_cstm where oppt_id_c is not null AND oppt_id_c <> ''";

                        $qryID = $bean->db->query($sqlSelectID);

                        while ($qryFetchID = $bean->db->fetchByAssoc($qryID)){

                                $MaxID = $qryFetchID['maxid'];

                                $MaxID = $MaxID + 1;


                        $OpptID = $CompDivCode . $OpptID_Date . "-" . $MaxID;

                        $bean->oppt_id_c = $CompDivCode . $OpptID_Date . "-" . $MaxID;