JonesSmith

Multiple Logic hook - Does not work on my side. Why?

Discussion created by JonesSmith on Sep 17, 2017
Latest reply on Sep 18, 2017 by Mike Russell

Multiple Logic Hook not executing.

 

Hi all, I have browsed through all the topics on this forum and still have no solution. I am hoping to ask for your professional help.

 

1) I am working with 7.5, a new instance (production environment) with no logic hooks.

2) logic_hooks.php file in the specific module has the correct permissions   directory 775, files 664

3) I just used two basic logic hooks provided by Sugar documentation (Account + time and Description + assigned)

4) I modified the manifest and all the files to the required class, function and I am literally stomped.

5) GLOBAL[debug] shows the 2nd logic hook does not execute. 

 

Below is the basic and all the file codes. What appears to be the problem??? I have been working on this Friday night and the weekend and still cannot get the basic implementation fixed.

 

manifest.php

<?php

$manifest =array(
'acceptable_sugar_flavors' => array('CE','PRO','CORP','ENT','ULT'),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array('(.*?)\\.(.*?)\\.(.*?)$'),
),
'author' => 'SugarCRM',
'description' => 'Installs a sample logic hook',
'icon' => '',
'is_uninstallable' => true,
'name' => 'Example Logic Hook Installer',
'published_date' => '2012-07-06 2012 20:45:04',
'type' => 'module',
'version' => '1341607504',
);

$installdefs =array(
'id' => 'package_1341607504',
'copy' => array(
0 => array(
'from' => '<basepath>/Files/custom/modules/Accounts/accounts_save.php',
'to' => 'custom/modules/Accounts/accounts_save.php',
),
1 => array(
'from' => '<basepath>/Files/custom/modules/Accounts/add_to_description.php',
'to' => 'custom/modules/Accounts/add_to_description.php',
),
),
'logic_hooks' => array(
array(
'module' => 'Accounts',
'hook' => 'before_save',
'order' => 12,
'description' => 'Example Logic Hook - Updates account name',
'file' => 'custom/modules/Accounts/accounts_save.php',
'class' => 'Accounts_Save',
'function' => 'updateAccountName',
),
array(
'module' => 'Accounts',
'hook' => 'before_save',
'order' => 99,
'description' => 'Example Logic Hook - Updates account name',
'file' => 'custom/modules/Accounts/add_to_description.php',
'class' => 'add_to_description',
'function' => 'add_timestamp',
),
),
);

?>

 

account_save.php

<?php

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

class Accounts_Save
{
function updateAccountName($bean, $event, $arguments)
{
$bean->name = "My New Account Name (" . time() . ")";
}
}

?>

 

logic_hooks.php

<?php
//prevents directly accessing this file from a web browser
if (!defined('sugarEntry') || !sugarEntry) die ('Not A Valid Entry Point');
// Do not store anything in this file that is not part of the array or the hook version. This file will
// be automatically rebuilt in the future.
$hook_version = 1;
$hook_array = array();
$hook_array['before_save'] = array();
$hook_array['before_save'][] = array(200, 'add_to_description', 'custom/modules/Accounts/add_to_description.php', 'add_to_description', 'add_timestamp');

$hook_array['before_save'] = array();
$hook_array['before_save'][] = array(15, 'Accounts_save', 'custom/modules/Accounts/accounts_save.php', 'Accounts_Save', 'updateAccountName');
?>

 

add_to_description.php
<?php

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

class add_to_description
{
function add_timestamp($bean, $event, $arguments)
{

global $current_user;
global $db;
global $beanFiles;


$GLOBALS['log']->fatal(" My second logic hook is executed.. ");

$bean->description .= " Saved on". date('Y-m-d g:i a'). " by ". $current_user->user_name ."\n";
}
}

?>

 

 

All files are in the correct directory as I am only working with Accounts.  I tested this separately, it works perfectly fine. But I put them together and upload this, only account_save works and add_description does not.

 

I have no logic hooks, it's fresh so why is it executing in a strange way. 

 

If you can help and possibly with a module loader to quickly test it. It would be grateful to know whether it is my zip file is the issue.  I have checked all the codes, it should all work. 

Outcomes