Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom logic_hooks deleted when redeploying module #105

Open
phil8900 opened this issue May 31, 2022 · 5 comments
Open

Custom logic_hooks deleted when redeploying module #105

phil8900 opened this issue May 31, 2022 · 5 comments
Labels
Area: Studio Issues & PRs related to all things regarding studio & module builder Priority:Important Issues & PRs that are important; broken functions; errors; there are workarounds Type: Bug Something isn't working Type:Suite7 Issue Spefc to SuiteCRM 7 that should be in the SuiteCRM 7 repo

Comments

@phil8900
Copy link
Contributor

phil8900 commented May 31, 2022

Issue

I placed the following files in the folder public/legacy/custom/modules/custom_ModuleName:

  • logic_hooks.php
  • nameHook.php (which is called from within logic_hooks.php and includes the logic)

After redeploying a custom module from the module builder the logic hook files were deleted from the server.

Expected Behavior

I would expect that the files that were manually created would stay on the server.

Actual Behavior

The logic_hook.php and all additional php files related to the logic hooks are deleted.

Possible Fix

Making the logic hook files read-only could fix the issue. Otherwise it would be good to keep them when the module is redeployed.

Steps to Reproduce

  1. Create a logic hook for a custom module
  2. Redeploy the custom module from the module builder
  3. Check if the logic hook files are still on the server

Context

I had to change some things in the module, but those changes were unrelated to the logic hook. After that I wanted to adapt the logic hook and couldn't find the files anymore.

This entry on the support forum sounds like the same issue I am facing, but I couldn't find the issue they are referring to.

Your Environment

  • SuiteCRM Version used: 8.1.1
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Not browser related, but I used Firefox 100.0.2 (64-Bit) and Chrome 102.0.5005.63 (64-Bit)
  • Environment name and version (e.g. MySQL, PHP 7): PHP 7.3.33-1, MySQL 5.7.38
  • Operating System and version (e.g Ubuntu 16.04): Ubuntu 18.04.1
@pgorod
Copy link
Contributor

pgorod commented Jun 1, 2022

You should specify exactly the paths and file names where you created the logic hook. And the contents. Having a minimum reproducible example of the bug helps make triage much faster and more precise. Thanks for reporting!

@phil8900
Copy link
Contributor Author

phil8900 commented Jun 2, 2022

Hey,
I edited the post above to include the details.
I placed the following files in the folder public/legacy/custom/modules/custom_ModuleName:

logic_hooks.php
NameHook.php (which is called from within logic_hooks.php and includes the logic)

The content of the files doesn't matter, but that's what I have:

logic_hooks.php:

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

$hook_array['after_relationship_add'][] = Array(
	10,
	'Set Name',
	'custom/modules/custom_ModuleName/NameHook.php',
	'NameHook',
	'setName'
);
$hook_array['after_relationship_delete'][] = Array(
	11,
	'Set Name',
	'custom/modules/custom_ModuleName/NameHook.php',
	'NameHook',
	'setName'
);
?>```

NameHook.php:
<?php
class NameHook{

    public function setName($bean, $event, $arguments){
        $bean->name = 'Some string';
    }
}

?>

@pgorod
Copy link
Contributor

pgorod commented Jun 2, 2022

Thanks.

Isn't this problem solved by just setting things up in a different folder, one that doesn't get overwritten by Module builder?

It would be more correct to do it elsewhere, I think.

The logic hook definition probably goes in
/custom/Extension/modules/[module]/Ext/LogicHooks/Custom_Module_Logic_Hooks.php

And the actual class file can be anywhere (the definition points to the file), for example custom/myDir/myClass.php

@johnM2401 johnM2401 added Type: Bug Something isn't working Priority:Important Issues & PRs that are important; broken functions; errors; there are workarounds Type:Suite7 Issue Spefc to SuiteCRM 7 that should be in the SuiteCRM 7 repo Area: Studio Issues & PRs related to all things regarding studio & module builder labels Jun 9, 2022
@phil8900
Copy link
Contributor Author

Hey,
I followed the guide outlined in the documentation and assumed the custom folder would be upgrade safe.
Are upgrade safe and being deleted while deploying a module two different things?

@pgorod
Copy link
Contributor

pgorod commented Jun 10, 2022

The custom directory includes parts that are read, and parts that are written to. So there is definitely some overwriting going on when people get confused about what-goes-where. And sometimes it can get confusing...

The Module builder is a different beast. I never use it. Other people recommend using it only once (initially), then doing the rest by editing files. Sometimes it seems to assume that it is the only thing doing changes in the custom module, as if there were no manual changes (but typically, there are). I think Studio is more respectful of manual changes, although you still need to know where to put your own stuff.

I would just advise to avoid sweeping assumptions, and try to figure out all behaviors one by one (logic hooks are not like vardefs; Module builder is not like Studio; etc), until you achieve something satisfactory.

If you like to go under the hood and really understand what is happening I recommend this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Studio Issues & PRs related to all things regarding studio & module builder Priority:Important Issues & PRs that are important; broken functions; errors; there are workarounds Type: Bug Something isn't working Type:Suite7 Issue Spefc to SuiteCRM 7 that should be in the SuiteCRM 7 repo
Projects
None yet
Development

No branches or pull requests

3 participants