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.

Reply
  • 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.

Children
  • 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.

  • I’m stuck trying to figure out what it is you are even trying to do – the first class looks like it would be better handled as an “extends”, and the last class doesn’t look like it has any way to actually interface the first class… unless you’re defining it as a global someplace I’m not seeing PrepaidGiftBalance