Skip to content

Commit

Permalink
Merge pull request openemr#7248 from sjpadgett/modules_fixup
Browse files Browse the repository at this point in the history
Module Manager Refactor
  • Loading branch information
sjpadgett authored Feb 26, 2024
2 parents e670aa3 + f89380b commit 94258ab
Show file tree
Hide file tree
Showing 11 changed files with 475 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ public static function initListenerSelf(): ModuleManagerListener
*/
private function install($modId, $currentActionStatus): mixed
{
$modService = new ModuleService();
/* 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;
}

Expand All @@ -98,12 +105,6 @@ private function install($modId, $currentActionStatus): mixed
*/
private function preenable($modId, $currentActionStatus): mixed
{
$modService = new ModuleService();
if ($modService->isWenoConfigured()) {
$modService::setModuleState($modId, '0', '0');
return $currentActionStatus;
}
$modService::setModuleState($modId, '0', '1');
return $currentActionStatus;
}

Expand All @@ -130,7 +131,8 @@ private function enable($modId, $currentActionStatus): mixed
*/
private function disable($modId, $currentActionStatus): mixed
{
ModuleService::setModuleState($modId, '0', '0');
// allow config button to show before enable.
ModuleService::setModuleState($modId, '0', '1');
return $currentActionStatus;
}

Expand Down
12 changes: 9 additions & 3 deletions interface/modules/custom_modules/oe-module-weno/moduleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/

use OpenEMR\Core\ModulesClassLoader;

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

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

<iframe src="templates/weno_setup.php?module_config=1" style="border:none;height:100vh;width:100%;"></iframe>
$module_config = 1;
/* renders in a Laminas created iframe */
require_once dirname(__FILE__) . '/templates/weno_setup.php';
exit;
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,12 @@ public function isWenoConfigured(): bool
$config = $this->getVendorGlobals();
$keys = array_keys($config);
foreach ($keys as $key) {
if ($key === 'weno_rx_enable_test') {
if (
$key === 'weno_rx_enable_test'
|| $key === 'weno_secondary_admin_username'
|| $key === 'weno_secondary_admin_password'
|| $key === 'weno_secondary_encryption_key'
) {
continue;
}
$value = $GLOBALS[$key] ?? null;
Expand Down Expand Up @@ -161,7 +166,7 @@ public static function statusPharmacyDownloadReset(): bool
/**
* @param $modId string|int module id or directory name
* @param $flag string|int 1 or 0 to activate or deactivate module.
* @param $flag_ui string|int custom module ui flag to activate or deactivate Manager UI states.
* @param $flag_ui string|int custom flag to activate or deactivate Manager UI button states.
* @return array|bool|null
*/
public static function setModuleState($modId, $flag, $flag_ui): array|bool|null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public function getWenoProviderId($id = null): mixed
// get the weno provider id from the user table (weno_prov_id
$provider = sqlQuery("SELECT weno_prov_id FROM users WHERE id = ?", [$id]);
if (!empty(trim($provider['weno_prov_id'] ?? ''))) {
$doIt = $GLOBALS['weno_provider_uid'] != trim($provider['weno_prov_id']);
$doIt = ($GLOBALS['weno_provider_uid'] ?? '') != trim($provider['weno_prov_id']);
if ($doIt) {
$GLOBALS['weno_provider_uid'] = trim($provider['weno_prov_id']);
$sql = "UPDATE `user_settings` SET `setting_value` = ? WHERE `setting_user` = ? AND `setting_label` = 'global:weno_provider_uid'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Vipin Kumar <[email protected]>
* @author Remesh Babu S <[email protected]>
* @author Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2020 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2020-2024 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2013 Z&H Consultancy Services Private Limited <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
Expand Down Expand Up @@ -50,6 +50,9 @@ public function __construct(InstModuleTable $installerTable)
$this->dbAdapter = $adapter ?? null;
}

/**
* @return ViewModel
*/
public function nolayout()
{
// Turn off the layout, i.e. only render the view script.
Expand All @@ -58,18 +61,21 @@ public function nolayout()
return $viewModel;
}

/**
* @return ViewModel
*/
public function indexAction()
{
$this->scanAndRegisterCustomModules();
//get the list of installed and new modules
$result = $this->getInstallerTable()->allModules();

$allModules = array();
foreach ($result as $dataArray) {
$mod = new InstModule();
$mod->exchangeArray($dataArray);
$mod = $this->makeButtonForSqlAction($mod);
$mod = $this->makeButtonForAClAction($mod);
array_push($allModules, $mod);
$allModules[] = $mod;
}

return new ViewModel(array(
Expand All @@ -82,6 +88,67 @@ public function indexAction()
));
}

/**
* @return void
*/
private function scanAndRegisterCustomModules(): void
{
$baseModuleDir = $GLOBALS['baseModDir'];
$customDir = $GLOBALS['customModDir'];
$zendModDir = $GLOBALS['zendModDir'];
$coreModules = ['Application', 'Acl', 'Installer', 'FHIR', 'PatientFlowBoard'];
$allModules = array();

$result = $this->getInstallerTable()->allModules();
foreach ($result as $dataArray) {
$mod = new InstModule();
$mod->exchangeArray($dataArray);
$mod = $this->makeButtonForSqlAction($mod);
$mod = $this->makeButtonForAClAction($mod);
$allModules[] = $mod;
}

$dir_path = $GLOBALS['srcdir'] . "/../$baseModuleDir$customDir/";
$dp = opendir($dir_path);
$inDirCustom = array();
for ($i = 0; false != ($file_name = readdir($dp)); $i++) {
if ($file_name != "." && $file_name != ".." && $file_name != "Application" && is_dir($dir_path . $file_name)) {
$inDirCustom[$i] = $file_name;
}
}
/* Laminas directory Unregistered scan */
$dir_path = $GLOBALS['srcdir'] . "/../$baseModuleDir$zendModDir/module";
$dp = opendir($dir_path);
$inDirLaminas = array();
for ($i = 0; false != ($file_name = readdir($dp)); $i++) {
if ($file_name != "." && $file_name != ".." && (!in_array($file_name, $coreModules)) && is_dir($dir_path . "/" . $file_name)) {
$inDirLaminas[$i] = $file_name;
}
}
// do not show registered modules in the unregistered list
if (sizeof($allModules) > 0) {
foreach ($allModules as $modules) {
$key = array_search($modules->modDirectory, $inDirLaminas);
if ($key !== false) {
unset($inDirLaminas[$key]);
continue;
}
$key = array_search($modules->modDirectory, $inDirCustom);
if ($key !== false) {
unset($inDirCustom[$key]);
}
}
}
foreach ($inDirLaminas as $file_name) {
$rel_path = $file_name . "/index.php";
$status = $this->getInstallerTable()->register($file_name, $rel_path, 0, $zendModDir);
}
foreach ($inDirCustom as $file_name) {
$rel_path = $file_name . "/index.php";
$status = $this->getInstallerTable()->register($file_name, $rel_path);
}
}

/**
* @return Installer\Model\InstModuleTable
*/
Expand All @@ -90,6 +157,9 @@ public function getInstallerTable(): InstModuleTable
return $this->InstallerTable;
}

/**
* @return void
*/
public function registerAction()
{
if (!AclMain::aclCheckCore('admin', 'manage_modules')) {
Expand Down Expand Up @@ -126,6 +196,9 @@ public function registerAction()
}
}

/**
* @return void
*/
public function manageAction()
{
if (!AclMain::aclCheckCore('admin', 'manage_modules')) {
Expand All @@ -143,8 +216,13 @@ public function manageAction()
// cleanup action.
if ($modType == InstModuleTable::MODULE_TYPE_CUSTOM) {
$status = $this->callModuleAfterAction("pre" . $request->getPost('modAction'), $modId, $dirModule, $status);
if ($status == 'bypass') {
// future use
if ($status == 'bypass_event') {
$output = "";
if (!empty($div) && is_array($div)) {
$output = implode("<br />\n", $div);
}
echo json_encode(["status" => 'Success', "output" => $output]);
exit(0);
}
}
if ($request->getPost('modAction') == "enable") {
Expand Down Expand Up @@ -283,6 +361,9 @@ private function getContent($data)
return $string;
}

/**
* @return JsonModel
*/
public function SaveHooksAction()
{
$request = $this->getRequest();
Expand All @@ -305,6 +386,9 @@ public function SaveHooksAction()
return $arr;
}

/**
* @return ViewModel
*/
public function configureAction()
{
$request = $this->getRequest();
Expand Down Expand Up @@ -377,6 +461,9 @@ public function configureAction()
));
}

/**
* @return JsonModel
*/
public function saveConfigAction()
{
$request = $this->getRequest();
Expand All @@ -396,6 +483,9 @@ public function saveConfigAction()
return $return;
}

/**
* @return JsonModel
*/
public function DeleteAclAction()
{
$request = $this->getRequest();
Expand All @@ -405,6 +495,9 @@ public function DeleteAclAction()
return $arr;
}

/**
* @return JsonModel
*/
public function DeleteHooksAction()
{
$request = $this->getRequest();
Expand All @@ -414,6 +507,9 @@ public function DeleteHooksAction()
return $arr;
}

/**
* @return void
*/
public function nickNameAction()
{
$request = $this->getRequest();
Expand All @@ -422,6 +518,10 @@ public function nickNameAction()
exit(0);
}

/**
* @param $modId
* @return false|string
*/
function getModuleVersionFromFile($modId)
{
//SQL version of Module
Expand All @@ -442,6 +542,11 @@ function getModuleVersionFromFile($modId)
return false;
}

/**
* @param $modDirectory
* @param $sqldir
* @return array|false
*/
public function getFilesForUpgrade($modDirectory, $sqldir)
{
$ModulePath = $GLOBALS['srcdir'] . "/../" . $GLOBALS['baseModDir'] . "zend_modules/module/" . $modDirectory;
Expand Down Expand Up @@ -470,6 +575,10 @@ public function getFilesForUpgrade($modDirectory, $sqldir)
return $sortVersions;
}

/**
* @param InstModule $mod
* @return InstModule
*/
public function makeButtonForSqlAction(InstModule $mod)
{
$dirModule = $this->getInstallerTable()->getRegistryEntry($mod->modId, "mod_directory");
Expand Down Expand Up @@ -506,6 +615,10 @@ public function makeButtonForSqlAction(InstModule $mod)
return $mod;
}

/**
* @param InstModule $mod
* @return InstModule
*/
public function makeButtonForACLAction(InstModule $mod)
{
$dirModule = $this->getInstallerTable()->getRegistryEntry($mod->modId, "mod_directory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Vipin Kumar <[email protected]>
* @author Remesh Babu S <[email protected]>
* @author Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2020 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2020-2024 Jerry Padgett <[email protected]>
* @copyright Copyright (c) 2013 Z&H Consultancy Services Private Limited <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
Expand Down Expand Up @@ -246,10 +246,6 @@ public function saveSettings($fieldName, $fieldValue, $moduleId)
/**
* this will be used to register a module
*
* @param unknown_type $directory
* @param unknown_type $rel_path
* @param unknown_type $state
* @param unknown_type $base
* @return boolean
*/
public function register($directory, $rel_path, $state = 0, $base = "custom_modules")
Expand Down
Loading

0 comments on commit 94258ab

Please sign in to comment.