Helpful tidbit: custom logic hooks are deleted when re-deployed through Module Builder

Ok, so I know i’ve seen a comment about this issue somewhere :dry: just can’t remember where lol.
So you have some custom logic hooks that you have created and your all so happy but then you realize that you forgot to include a crucial part in the module builder, but wait if you use the module builder and set it up and re-deploy you will loose all those logic_hooks that you spent so much time setting up.

Yes, I cursed my computer out a couple of times on this one. Then I thought you know what lets see what happens if I create the files that I need and then set the files to read only. So I did that and then re-deployed the module after making the changes. Since I redeployed I would have to also do a repair and rebuild in order for the logic_hooks to be used. So I did the repair and rebuild and all was right in universe again :).

I put the following file in the following directory and made it read only
custom/modules/Accounts/ConcatNameFieldsLogicHook.php

<?php
class ConcatNameFieldsLogicHook{

    public function concatnamefields(SugarBean $bean, $event, $arguments){
		$bean->name = $bean->name_first . " " . $bean->name_last;
    }

}

then i put the following file in it’s directory and made it read only
/custom/Extension/modules/[module]/Ext/LogicHooks/Custom_Accounts_Logic_Hooks.php

<?php
$hook_array['before_save'][] = Array(1, 'Concatenate First and Last Name to Name Field', 'custom/modules/Accounts/ConcatNameFieldsLogicHook.php','ConcatNameFieldsLogicHook', 'concatnamefields');

So, I included the code and as you can see it doesn’t do anything too spectacular except take the first and last name field concantenate them and place it in the name field in the database even though the ‘name’ field is no where on my layout :slight_smile:

it works just find and it saved me some time so I though i’d share it in case someone else ran into the same issue.

Cheers

Thanks for sharing. You might want to create an issue on SuiteCRM’s Github, maybe this could simply be fixed instead of worked-around.

:slight_smile: I was thinking the same thing and if I remember correctly I believe the wording that I saw in the post was “We are aware of this issue” but i’ll check if there is an active issue for it and if not i’ll submit one, just seems like the right thing to do