-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Modules Manager action hooks for module cleanup #7150
Changes from 2 commits
339747b
1fede3f
2121169
b825e48
9506330
3f273f7
083204a
9a7a399
4fcdce4
c1600c4
ff86148
7377c8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
/** | ||
* Class to be called from Laminas Module Manager reporting management actions. | ||
* Example is if module is disabled or unregistered ect. | ||
* | ||
* @package OpenEMR Modules | ||
* @link https://www.open-emr.org | ||
* @author Jerry Padgett <sjpadgett@gmail.com> | ||
* @copyright Copyright (c) 2024 Jerry Padgett <sjpadgett@gmail.com> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
|
||
/* | ||
* Currently register isn't supported and support should be a part of install. | ||
* If an error needs to be reported to user, return description of error. | ||
* However, whatever action trapped here has already occurred in Manager. | ||
* Catch any exceptions because chances are they will be overlooked in Laminas module. | ||
* Report them in return value. | ||
*/ | ||
|
||
class ModuleManagerActionListener | ||
{ | ||
// Prevent instantiation | ||
private function __construct() | ||
{ | ||
} | ||
|
||
|
||
/** | ||
* @param $methodName | ||
* @param $modId | ||
* @param string $currentActionStatus | ||
* @return string On method success a $currentAction status should be returned or error string. | ||
*/ | ||
public static function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string | ||
{ | ||
// Check if the action method exists | ||
if (method_exists(self::class, $methodName)) { | ||
return self::$methodName($modId, $currentActionStatus); | ||
} else { | ||
// TODO Perhaps this should be an exception! | ||
return "Module cleanup method $methodName does not exist."; | ||
} | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private static function install($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private static function enable($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private static function disable($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private static function unregister($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private static function install_sql($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private static function upgrade_sql($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,10 @@ public function manageAction() | |
$request = $this->getRequest(); | ||
$status = $this->listenerObject->z_xlt("Failure"); | ||
if ($request->isPost()) { | ||
$modId = $request->getPost('modId') ?? null; | ||
$registryEntry = $this->getInstallerTable()->getRegistryEntry($modId, "mod_directory"); | ||
$dirModule = $registryEntry->modDirectory; | ||
$modType = $registryEntry->type; | ||
if ($request->getPost('modAction') == "enable") { | ||
$status = $this->EnableModule($request->getPost('modId')); | ||
Comment on lines
143
to
144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What the heck! This is backwards. enable actually disables the module and disable enables in the controller functions. |
||
} elseif ($request->getPost('modAction') == "disable") { | ||
|
@@ -168,6 +172,10 @@ public function manageAction() | |
} elseif ($request->getPost('modAction') == "unregister") { | ||
$status = $this->UnregisterModule($request->getPost('modId')); | ||
} | ||
// cleanup action. | ||
if ($modType == InstModuleTable::MODULE_TYPE_CUSTOM) { | ||
$status = $this->callModuleAfterAction($request->getPost('modAction'), $modId, $dirModule, $status); | ||
} | ||
} | ||
$output = ""; | ||
if (!empty($div) && is_array($div)) { | ||
|
@@ -177,11 +185,40 @@ public function manageAction() | |
exit(0); | ||
} | ||
|
||
/** | ||
* @param $action | ||
* @param $modId | ||
* @param $dirModule | ||
* @param $currentStatus | ||
* @return mixed | ||
*/ | ||
private function callModuleAfterAction($action, $modId, $dirModule, $currentStatus): mixed | ||
{ | ||
$modPath = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "custom_modules/" . $dirModule; | ||
$moduleClassPath = $modPath . '/ModuleManagerAfterActions.php'; | ||
$action = trim($action); | ||
if (!file_exists($moduleClassPath)) { | ||
return $currentStatus; | ||
} | ||
require_once($moduleClassPath); | ||
$className = 'ModuleManagerActionListener'; | ||
$methodName = trim($action); | ||
if (class_exists($className)) { | ||
if (method_exists($className, 'moduleManagerAction')) { | ||
return call_user_func([$className, 'moduleManagerAction'], $methodName, $modId); | ||
} else { | ||
return $currentStatus; | ||
} | ||
} else { | ||
return $currentStatus; | ||
} | ||
} | ||
|
||
/** | ||
* @param $version | ||
* @return int|string | ||
*/ | ||
function upgradeAclFromVersion($ACL_UPGRADE, $version) | ||
private function upgradeAclFromVersion($ACL_UPGRADE, $version) | ||
{ | ||
$toVersion = ''; | ||
foreach ($ACL_UPGRADE as $toVersion => $function) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bradymiller Do we have somewhere to put this file perhaps we have example module somewhere.