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

Module uninstall #7442

Merged
merged 10 commits into from
May 23, 2024
Merged

Conversation

juggernautsei
Copy link
Member

Fixes #7441

Short description of what this resolves:

Changes proposed in this pull request:

@sjpadgett
Copy link
Sponsor Member

@claimrevolution Need you to look this over today. Want for patch!

Copy link
Sponsor Member

@sjpadgett sjpadgett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to finish the task handling for enable and disable actions. Thanks for taking care of the bootstrap includes. I'm surprised we let that slide when bringing module into core.
I'm not testing and leaving that to you.

Comment on lines +15 to +23
use OpenEMR\Core\ModulesClassLoader;

require_once dirname(__FILE__, 4) . '/globals.php';

/* required for config before install */
$classLoader = new ModulesClassLoader($GLOBALS['fileroot']);
$classLoader->registerNamespaceIfNotExists("OpenEMR\\Modules\\ClaimRevConnector\\", __DIR__ . DIRECTORY_SEPARATOR . 'src');

$module_config = 1;
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the MM config/settings frame is not being used by a module, this file is not required. Regardless, what you have here is fine but just not required fyi.

* @param string $col
* @return array
*/
function getModuleRegistry($modId, $col = '*'): array
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may move to abstract class or trait for convivence just a fyi.

Comment on lines 89 to 99
// private function install($modId, $currentActionStatus): mixed
// {
// $modService = new ModuleServices();
// /* setting the active ui flag here will allow the config button to show
// * before enable. This is a good thing because it allows the user to
// * configure the module before enabling it. However, if the module is disabled
// * this flag is reset by MM.
// */
// $modService::setModuleState($modId, '0', '1');
// return $currentActionStatus;
// }
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability either delete comment methods or just have them return $currentActionStatus. I opt to leave empty methods in place for future reference though all available method call but MM action events are listed in the abstract class or should be.. Sorry, I think I didn't update that class for last couple new events I added to MM. I will soon.

Bottom line, need to lose all the commented lines. I prefer if you leave empty method.

 private function install($modId, $currentActionStatus): mixed
    {
        $modService = new ModuleServices();
        /* setting the active ui flag here will allow the config button to show
         * before enable. This is a good thing because it allows the user to
         * configure the module before enabling it. However, if the module is disabled
         * this flag is reset by MM.
        */
 
        return $currentActionStatus;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was unsure of the role of the comment methods. I commented them out to make sure they were not causing the issue that I was facing at the time. I will uncomment. I think that will be best for future utilization

Comment on lines 147 to 152
// private function disable($modId, $currentActionStatus): mixed
// {
// // allow config button to show before enable.
// ModuleServices::setModuleState($modId, '0', '1');
// return $currentActionStatus;
// }
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uncomment method and add action to disable tasks because module is now disabled. You can make this cleaner or use below. Just use same for enable action by setting active to 1. Then unregister action will delete tasks so default table.sql will reinstall.

UPDATE `background_services` SET `active` = '0' WHERE `background_services`.`name` = 'ClaimRev_Elig_Send_Receive'; 
UPDATE `background_services` SET `active` = '0' WHERE `background_services`.`name` = 'ClaimRev_Receive';
UPDATE `background_services` SET `active` = '0' WHERE `background_services`.`name` = 'ClaimRev_Send';

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juggernautsei You still need the enable and disable tasks i.e active flag. If user disables then background tasks don't have access to module so need to make tasks inactive. Same with reverse and enable action. You're only half way there.
See the sql example I gave above for disable.

* @param $currentActionStatus
* @return mixed
*/
// private function reset_module($modId, $currentActionStatus): mixed
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If needed or wanted, this gets called also when unregistered action is called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I enabled all the methods that were commented out. The module will not install. It can enable but it won't install. I have uploaded what I have. The code does not produce any errors in the errors in the logs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to figure this out tomorrow. I got some other stuff to work on right now.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juggernautsei Just delete the unused methods(commented). The controller will simply ignore them. You need unregister, enable and disable for task maintenance.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured out what you were saying and just return current status. I have installed and removed. It removes all the globals and tables.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted a cleanup action that I chose to name reset i.e. reset module to a state before original install. All these still need to be documented but besides our admins, you and Brad, I've seen no third party user make any attempt to give feedback or contrib.
So, you're in the know now so to say:)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sjpadgett I move the getModuleState method into the listener. The reset_module method is not being called. I checked the error log and it does not show there. The background services are being removed but not the table or globals as you would know.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forget reset_module just delete it you won't be using.
You don't need getModuleState. I wrote those for how I use weno module actions.
All you need is enable method with the sql to set the 3 active flag in background services, disable to unset active flag in background service table and what you already have to delete the tasks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it and here are the updates.

Comment on lines 130 to 136
$sql = "DELETE FROM `globals` WHERE `gl_name` LIKE 'oe_claimrev%'";
$rtn = sqlQuery($sql);
$logMessage .= "DELETE FROM `globals`: " . (empty($rtn) ? "Success" : "Failed") . "\n";

// return log messages to the MM to show user.
return text($logMessage);
}

public static function getModuleState($modId): bool
{
$sql = "SELECT `mod_active` FROM `modules` WHERE `mod_id` = ? OR `mod_directory` = ?";
$flag = sqlQuery($sql, array($modId, $modId));

return !empty($flag['mod_active']);
$sql = "DROP TABLE IF EXISTS `mod_claimrev_eligibility`";
$rtn = sqlQuery($sql);
$logMessage .= "DROP TABLE `mod_claimrev_eligibility`: " . (empty($rtn) ? "Success" : "Failed") . "\n";
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this and leave it up to Brad to remove history by dropping tables or globals.
We are only worried about background services.
Please Please just add the enable and disable and unregister methods. I've explain enable and disabled with example in my comments. If you need a call let me know.

@sjpadgett
Copy link
Sponsor Member

Thanks for doing Brads job here @juggernautsei I appreciate it as well as all those users that enable the module then decide to disable.
I've seen on a user site this issue causing one to three fatal errors every time background service ran every one to two minutes.

I'm looking into making this class mandatory or module will not get initialized from boot.
Anyway good job my friend and I'll be merging

@sjpadgett sjpadgett merged commit 4e8432a into openemr:master May 23, 2024
25 checks passed
@sjpadgett
Copy link
Sponsor Member

woops! forgot to squash!

sjpadgett added a commit to sjpadgett/openemr that referenced this pull request May 23, 2024
…nager

Module uninstall

(cherry picked from commit 4e8432a)
sjpadgett added a commit that referenced this pull request May 23, 2024
@juggernautsei
Copy link
Member Author

It is always a learning experience with you. I seek after as much. I will go back to some of my modules and revamp them to include this basic feature request starting with the Quest module. Always improving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Claimrev leaves background service on when module is uninstalled
2 participants