SugarCRM is now SugarAI! Read the announcement  

Bizarre logic hook problem

I was working on cleaning up some very very old code (I think v6 or v7)

As I do that I wanted to be more consistent with naming conventions

The original logic hook was

$hook_array['process_record'][] = Array(1,'conditional_formatting','custom/modules/Cases/conditional_formatting.php','ConditionalFormatting','conditional_formatting');

The cleaned up one was using camel case for the function, and a better name for the file

$hook_array['process_record'][] = array( 1, 'conditionalFormatting', 'custom/modules/Cases/Cases_ConditionalFormatting_Logic.php', 'ConditionalFormatting', 'conditionalFormatting');

Of course the class and the function names were changed consistently in the new file, the old file was removed.

I did a QRR, cleared cache etc... the logic_hook refuses to fire with the new names. I put a fatal log entry at the start of the hook function, nothing in the log.

If all I do is change the name of the refactored file, name of the function and name of the class to the old ones then everything runs smoothly.

Why would that be? How can renaming something (consistently I might add) break it?
It's puzzling...

FrancescaS

Parents Reply Children
  • I don't, but should they?
    I don't see any custom logic hooks in that file, not even for the hooks that work just fine. 

    This is all I see in 

    custom/modules/Cases/Ext/LogicHooks/logichooks.ext.php


    <?php
    // WARNING: The contents of this file are auto-generated.
    ?>
    <?php
    // Merged from modules/Cases/Ext/LogicHooks/RelationshipHook.php
    
    /*
     * Your installation or use of this SugarCRM file is subject to the applicable
     * terms available at
     * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
     * If you do not agree to all of the applicable terms or do not have the
     * authority to bind the entity as an authorized representative, then do not
     * install or use this SugarCRM file.
     *
     * Copyright (C) SugarCRM Inc. All rights reserved.
     */
    
    $hook_array['before_relationship_delete'][] = [
        1,
        'beforeRelationshipDelete',
        'modules/Cases/CasesHooks.php',
        'CasesHooks',
        'beforeRelationshipDelete',
    ];
    
    $hook_array['after_relationship_add'][] = [
        1,
        'afterRelationshipAdd',
        'modules/Cases/CasesHooks.php',
        'CasesHooks',
        'afterRelationshipAdd',
    ];
    
    $hook_array['after_relationship_delete'][] = [
        1,
        'afterRelationshipDelete',
        'modules/Cases/CasesHooks.php',
        'CasesHooks',
        'afterRelationshipDelete',
    ];
    
    ?>
    <?php
    // Merged from custom/Extension/modules/Cases/Ext/LogicHooks/denorm_field_hook.php
    
    /*
     * Your installation or use of this SugarCRM file is subject to the applicable
     * terms available at
     * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
     * If you do not agree to all of the applicable terms or do not have the
     * authority to bind the entity as an authorized representative, then do not
     * install or use this SugarCRM file.
     *
     * Copyright (C) SugarCRM Inc. All rights reserved.
     */
    
    // Relate Field Denormalization hook
    
    $hook_array['before_save'][] = [
        1,
        'denorm_field_watcher',
        null,
        '\\Sugarcrm\\Sugarcrm\\Denormalization\\Relate\\Hook',
        'handleBeforeUpdate',
    ];
    
    $hook_array['after_save'][] = [
        1,
        'denorm_field_watcher',
        null,
        '\\Sugarcrm\\Sugarcrm\\Denormalization\\Relate\\Hook',
        'handleAfterUpdate',
    ];
    
    $hook_array['before_relationship_delete'][] = [
        1,
        'denorm_field_watcher',
        null,
        '\\Sugarcrm\\Sugarcrm\\Denormalization\\Relate\\Hook',
        'handleDeleteRelationship',
    ];
    
    $hook_array['after_relationship_add'][] = [
        1,
        'denorm_field_watcher',
        null,
        '\\Sugarcrm\\Sugarcrm\\Denormalization\\Relate\\Hook',
        'handleAddRelationship',
    ];
    
    ?>

    And these are my working (tested) Logic hooks, 

    custom/modules/Cases/logic_hooks.php



    <?php
    /**
     * logic_hooks.php — Cases module
     *
     * Hook registration order within each event is determined by the first
     * element of each entry (the position integer). Lower numbers run first.
     *
     * Format: array(position, label, file, class, method)
     */
    
    $hook_version = 1;
    $hook_array   = array();
    
    // -----------------------------------------------------------------------------
    // before_save
    // -----------------------------------------------------------------------------
    $hook_array['before_save'][] = array( 3, 'beforeSave',        'custom/modules/Cases/Cases_Logic.php',                      'AutomatedCaseHandling', 'beforeSave',);
    $hook_array['before_save'][] = array( 4, 'updateLog',         'custom/modules/Cases/Cases_Logic.php',                      'AutomatedCaseHandling', 'updateLog',);
    $hook_array['before_save'][] = array( 5, 'checkEmailAddress', 'custom/modules/Cases/Cases_Logic.php',                      'AutomatedCaseHandling', 'checkEmailAddress',);
    $hook_array['before_save'][] = array( 6, 'checkVIP',          'custom/modules/Cases/Cases_Logic.php',                      'AutomatedCaseHandling', 'checkVIP',);
    $hook_array['before_save'][] = array( 7, 'checkGDPR',         'custom/modules/Cases/Cases_Logic.php',                      'AutomatedCaseHandling', 'checkGDPR',);
    
    // -----------------------------------------------------------------------------
    // after_save
    // -----------------------------------------------------------------------------
    $hook_array['after_save'][] = array( 3, 'afterSave',               'custom/modules/Cases/Cases_Logic.php',                 'AutomatedCaseHandling', 'afterSave',);
    $hook_array['after_save'][] = array( 4, 'saveContactRelationship', 'custom/modules/Cases/Cases_Logic.php',                 'AutomatedCaseHandling', 'saveContactRelationship',);
    
    // -----------------------------------------------------------------------------
    // after_relationship_add
    // -----------------------------------------------------------------------------
    $hook_array['after_relationship_add'][] = array( 1, 'checkVIP',          'custom/modules/Cases/Cases_Logic.php',           'AutomatedCaseHandling', 'checkVIP',);
    $hook_array['after_relationship_add'][] = array( 2, 'compProductNotes',  'custom/modules/Cases/Cases_Logic.php',           'AutomatedCaseHandling', 'compProductNotes',);
    
    // -----------------------------------------------------------------------------
    // after_relationship_delete
    // -----------------------------------------------------------------------------
    $hook_array['after_relationship_delete'][] = array( 1, 'checkVIP',       'custom/modules/Cases/Cases_Logic.php',           'AutomatedCaseHandling', 'checkVIP',);
    
    // -----------------------------------------------------------------------------
    // process_record
    // -----------------------------------------------------------------------------
    $hook_array['process_record'][] = Array(1,'conditional_formatting','custom/modules/Cases/conditional_formatting.php','ConditionalFormatting','conditional_formatting');
    

    Not all numbering starts with 1 because I removed some old hooks and didn't think to renumber until now, but that has no created issues for years.

    Thanks,

    Francesca

  • Whether it shows or doesn't will be dependent on how one goes about defining the hook.

    Older versions of Sugar would use the approach that leverages the logic_hooks.php file. At some point, we introduced Logic Hooks into the capabilities of the Extensions Framework, which then allowed one to define a logic hook by way of extensions and in turn, use the logichooks.ext.php file. Both approaches are equally valid, but we do favor the Extensions approach for situations where a customization can be implemented through multiple means.

    Your hooks are likely configured that way due to their age. There is nothing inherently wrong with them.

    As a side note, the order numbering is fine. That's mostly relevant for scenarios where you have multiple hooks of the same type (e.g. before_save) and need them to execute in a specific order.

    I'll ask a dumb question, does the hook work if you rename the files back to their prior name? 

  • Yes, the original hook works fine.

    I don't think it's worth your time trying to figure this out. 

    Thanks for the note on the change in Logic Hooks, I'll plan to move to Extensions with the next upgrade. It will be a bit of work given that over 40 modules have logic hooks...

    Thanks again! 
    Francesca