How to use new Laminas Module Manager maintenance action hooks

Overview

Since we first developed Modules in OpenEMR, the need to have the ability to act on the various Module Manager (LMM) actions became obvious. For example, when disabling a module from the LMM the module in question will have its active flag turned off to prevent the module bootstrap from running. However and as in the case where the module has its own setup and Globals maintenance, related disable actions from the modules stand point may need to be cleaned up. In the case of my FaxSMS module, a global enabled flag needs to be reset as well.

The LMM has the following actions performed from the Manage Modules. These can be discerned from the newly created AbstractModuleActionListener class with:

Helpers

  • getModuleRegistry(modId, [col: string = ‘*’]): array
  • moduleManagerAction(methodName: string, modId: string, [currentActionStatus: string = ‘Success’]): string
  • getModuleNamespace(): string
  • initListenerSelf()

Actions reported

  • disable(modId, currentActionStatus): mixed
  • enable(modId, currentActionStatus): mixed
  • install(modId, currentActionStatus): mixed
  • install_sql(modId, currentActionStatus): mixed
  • unregister(modId, currentActionStatus): mixed
  • upgrade_sql(modId, currentActionStatus): mixed

From these methods the module will perform any needed actions and return back to LMM to continue with its work.

The methods are called after the LMM action completes. Passed in are the module id and the status of the LMM action. Normally ‘Success’ is standard. Any other strings returned by new class will be popped up by LMM to notify user but LMM will continue as LMM action has already been handled.

Implementation

The project consist of three classes where two are part of core namespace \OpenEMR\Core

  1. ModuleManagerAfterActionListener.php - Main class called from LMM.
  2. Core/AbstractModuleActionListener.php. - Class to be extended in ModuleManagerAfterActionListener.php implemented in modules root. One may create a new class or use the one I implemented in the FaxSMS as an example. You must use the class name because it is hardcoded in LMM.
  3. Core/AbstractModuleActionTrait.php - Trait class of helpers, mainly supers handling, used in above class.

By populating the necessary methods in new ModuleManagerAfterActionListener class that are specific to the modules needs I hope to further the modules usefulness.

Soon to be continued… Install, upgrade and general SQL workflow.

2 Likes