Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Logic hook is not working, apache crashes

  1. #1
    chilyroll is offline Member
    Join Date
    Apr 2010
    Posts
    15

    Default Logic hook is not working, apache crashes

    Hi all,

    I have added a logic hook which is not working as expected. Below is the complete code:

    logic_hooks.php

    PHP Code:
    <?php

    $hook_version
    =1;
    $hook_array=array();

    $hook_array['after_save']=array();
    $hook_array['after_save'][]=array(1,'SetData','custom/modules/Opportunities/SetData/SetData.php','SetData','SetData');
    ?>
    and my logic_hook handler is:

    PHP Code:
    <?php

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

    class 
    SetData {  

        function 
    SetData($bean$event$args) {
                
    $dbm DBManagerFactory::getInstance();
                
    $sql="update accounts_cstm
                      set acc_data_id_c = '"
    .$bean->fetched_row['data_id_c']."'
                      where id_c='"
    .$account_data['id']."'";
                
    $dbm->query($sql,true,"Error updating Opportunities: ");
            }
        }
    }

    ?>
    data_id_c is a Relate field which is related to the Opportunities module. I want to set acc_data_id_c to the Opp.data_id_c. It works fine and updates the DB perfectly when I look up the accounts_cstm table, but when I try to view the Account my Apache crashes and it doesn't work until I clear off the acc_data_id_c field in accounts_cstm table.

    Let me know if these details are sufficient. Any kind of help is appreciated.

    Thanks in advance

  2. #2
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Logic hook is not working, apache crashes

    Try it like this:

    Code:
        function SetData($bean, $event, $args) {  
                $sql="update accounts_cstm 
                      set acc_data_id_c = '".$bean->fetched_row['data_id_c']."' 
                      where id_c='".$account_data['id']."'"; 
                $bean->db->query($sql,true); 
            }
    Regards,

    Angel Magaña
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  3. #3
    chilyroll is offline Member
    Join Date
    Apr 2010
    Posts
    15

    Default Re: Logic hook is not working, apache crashes

    Hi Angel,

    Thanks for the response. The thing is I am facing a strange issue. My DB is updated properly through the logic hooks, no issues in that. But once the DB is updated, my apache crashes for no reason. It works fine for some of the relate field IDs, but for some IDs it just crashes my apache and won't let me access the accounts, opp pages unless I clear that relate field value from the accounts_cstm field. I have been banging my head on this trying to figure out the issue, but no luck till now. May be something to do with the relations but not very much sure about it.

    Thanks again for your response. Much appreciated!

  4. #4
    Angel's Avatar
    Angel is offline Sugar Community Member
    Join Date
    Jul 2005
    Location
    Los Angeles
    Posts
    4,813

    Default Re: Logic hook is not working, apache crashes

    Ok, I am confused. Did the change help or are you still stuck?
    Regards,

    Angel Magaña
    Co-Author: Implementing SugarCRM 5.x (Packt Publishing -- Sept. 2010)
    Blog: http://cheleguanaco.blogspot.com.
    Twitter: @cheleguanaco.

    ________
    | Projects: |_____________________________________
    |
    | CandyWrapper (.NET Wrapper for SugarCRM SOAP API). Source now available on GitHub!
    | GoldMine to SugarCRM Express Conversion. Latest: 1.0.1.7 (Nov. 3, 2009)
    | CRM SkyDialer (Skype Integration). Latest: 1.0.2 (Feb. 17, 2010)
    | Round Robin Leads Assignment
    | Phone Number Formatter
    | CaseTwit (Twitter Integration)
    ______________________________________________

  5. #5
    chilyroll is offline Member
    Join Date
    Apr 2010
    Posts
    15

    Default Re: Logic hook is not working, apache crashes

    I am still stuck.

  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: Logic hook is not working, apache crashes

    Can you see any error message at error log of your apache?

    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.

  7. #7
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: Logic hook is not working, apache crashes

    Where did you set $account_data['id'] in your code?

    Your function should have the header

    function SetData(& $bean, $event, $args) {
    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


  8. #8
    chilyroll is offline Member
    Join Date
    Apr 2010
    Posts
    15

    Default Re: Logic hook is not working, apache crashes

    @andopes: No significant or relevant messages in Apache logs.

    @kuske: Just FYI I am attaching the entire code again...

    logic_hook:

    PHP Code:
    <?php

    $hook_version
    =1;
    $hook_array=array();

    $hook_array['after_save']=array();
    $hook_array['after_save'][]=array(1,'SetSoldSystem','custom/modules/Opportunities/SetSoldSystem/SetSoldSystem.php','SetSoldSystem','SetSoldSystem');
    ?>
    And below is the logic hook handler:

    PHP Code:
    <?php

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

    class 
    SetSoldSystem {  

        function 
    SetSoldSystem($bean$event$args) {
            if (
    $bean->sales_stage == 'Closed/Won') {
                
    $account_data $bean->get_account_detail($bean->id);
                
    $account = new Account();
                
    $account->retrieve($account_data['id']);
                
    $account->description 'this description is changed through the logic hook';
                
    $account->sun_systems_id2_c $bean->fetched_row['sun_systems_id_c'];

                
    /*
                 * Works fine if I use the System Id our couple of others but not every ID though those Sugar Objects are perfectly fine when viewed in Sugar
                 */
                //$account->sun_systems_id_c = '647783da-14fd-d82c-e827-4c079d31f642';

                /*
                 * Comment out below line as it crashes the APACHE
                 */
                
    $account->save();
            }
        }
    }

    ?>
    See if this helps...

    Thanks again for you time guys!

  9. #9
    chilyroll is offline Member
    Join Date
    Apr 2010
    Posts
    15

    Default Re: Logic hook is not working, apache crashes

    I am getting a feeling that it's Sugar core issue. It's not able to handle the complex relationship between interlinked modules.

    I will try to explain my relationship matrix here a bit and will tell you what I have done.

    I have a custom module say 'TestModule'

    Opportunity < 1:M > TestModule
    Opportunity <1:1> Accounts

    'TestModule' is itself is considerably complex and having a lot of related modules.

    Currently I have a couple of relate fields on the Opportunities Detail view pages added. And it was working absolutely fine till yesterday when I added one relate field of the type 'TestModule' on Accounts page. Under some condition I set the value of that field on accounts as that of Opportunity. And then because of some complex stuff that sugar doesn't handle very well, it crashes my apache. Note that there is no relation between the Accounts and TestModule, I just added the relate field on the accounts.

    I tested it on windows 7, xp and also on Ubuntu systems but no luck.

    So just confirm with me that it's sugar thing only

    Thanks again!

  10. #10
    chilyroll is offline Member
    Join Date
    Apr 2010
    Posts
    15

    Default Re: Logic hook is not working, apache crashes

    To add something more, if I delete the relationship between the Opportunity and TestModule but keep the relate fields on the Accounts as is, the page loads just fine.

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Logic Hook is working far too well issue
    By routledge in forum Help
    Replies: 1
    Last Post: 2009-10-07, 11:53 AM
  2. Apache crashes on new installation 5.2
    By rudolfo in forum Installation and Upgrade Help
    Replies: 1
    Last Post: 2009-06-29, 10:47 PM
  3. Logic hook to set a date (not working)
    By LechnerJ in forum Developer Help
    Replies: 5
    Last Post: 2009-06-15, 07:09 PM
  4. Replies: 0
    Last Post: 2008-07-15, 07:20 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
  •