pre_execute.php ignored

Hello. I am trying to remove a custom module of ours from a 9.0.2 installation, called AG_AG_Version. I updated the code in the files using the module, that part is working. BUT, I also have to remove the module folder itself and a file generated by the module. I am using this as base: https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_9.0/Cookbook/Module_Loadable_Packages/R… 

This is the content of pre_execute.php:

echo "In pre_execute";
if (isset($this->installdefs['remove_files'])) {
foreach($this->installdefs['remove_files'] as $relpath){
if (SugarAutoloader::fileExists($relpath)) {
SugarAutoloader::unlink($relpath);
}
}
}
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}
echo "Deleting custom/modules/AG_AG_Versions";
deleteDir('custom/modules/AG_AG_Versions');
echo "Deleting modules/AG_AG_Versions";
deleteDir('modules/AG_AG_Versions')

The manifest.php's relevant part looks like this (inside installdefs array):

'pre_execute' => [
'<base_path>/Files/pre_execute.php'
],
'remove_files'=>[
'custom/modules/logic_hooks.php'
]

Any idea why those echo messages from pre_execute.php appears nowhere in the logs and .. nothing is deleted. Like the file is completly ignored.

Parents
  • Do you receive any error messages? Package scan should not allow an MLP with commands like unlink. You would, however, see an error message like the one here:

    Let me know what the experience is when you try to install. Are there any messages? does the installation task complete? etc

    Note: If you are installing into a cloud instance (or have Package Scan enabled), you cannot delete files via code. To have files removed, you can submit a case to Sugar Support with a list of files to be removed or request a package approval and provide your module loadable package.

  • I am using a silent upgrader (command line upgrader), not module loader. I want and am required to make it work as a module loader package too. The install succeeds, no errors, but I doubt any checking is enabled. The install is on premise server, not cloud. Let me ask the other way around: I have to remove 1 files and 2 folders ( I want to remove all traces of a module), besides patching other stuff. How can I do this correctly from manifest.php and pre_execute.php? I would like to avoid listing all the files one by one from the folders, as there are many. Basically rm -R custom/modules/AG_AG_Version and rmdir same thing.

  • honestly, what you are doing should work just fine. While researching this I think there is a bug with the pre_execute scripts. i have submitted a support request and we'll see what can be done about it. For now, could you run the remove files after the installation is complete? from the post_install?

  • I found the bug. I replaced pre with post_execute as you said. Same effect. Than on a hunch I used module loader instead of silent upgrader and I got this:

    PHP Warning: require_once(&lt;base_path&gt;/Files/post_execute.php): failed to open stream: No such file or directory in /var/www/acloud-crm/ModuleInstall/ModuleInstaller.php on line 277

    PHP Fatal error: require_once(): Failed opening required '&lt;base_path&gt;/Files/post_execute.php' (include_path='/var/www/acloud-crm:/var/www/acloud-crm/vendor:.:/usr/share/php') in /var/www/acloud-crm/ModuleInstall/ModuleInstaller.php on line 277

    Basically it does not recongize <basepath> because it URL encodes < and >. Is this a bug or intended?

  • when you used Module Loader, did you use the UI or the new API endpoints?

Reply Children