forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modules Manager action hooks for module cleanup (openemr#7150)
* Modules Manager action hooks for module cleanup - new class to include in modules directory root called by Laminas Module Mananger * - refactor class name to be better decription - document new listener class * - refactor interface button action function arguement to reflect the action in the controller. * - rename new class again so it is somewhat unique. - implement fax sms clean up methods - add new method for listener save globals * - fix SMS notification cli adding run arguments * - create and refactor abstract class to extend in module listener. - fix sql action path for custom_module - new fetch module setup method - fix upgrade button to show when needed - restyle Module Manager - bump faxsms sql version to 3.1.0 - add faxsms sql upgrade sql * - add column to install sql. * Finish new abstract class for module manager actions Develop and implement trait class for convientence functions like handling get, post, session plus more supers. develop laminas get registry settings in abstract class * style * - more restyles
- Loading branch information
Showing
15 changed files
with
849 additions
and
98 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
interface/modules/custom_modules/oe-module-faxsms/ModuleManagerActionListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
* @copyright Copyright (c) 2024 Jerry Padgett <[email protected]> | ||
* @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; | ||
} | ||
} |
168 changes: 168 additions & 0 deletions
168
interface/modules/custom_modules/oe-module-faxsms/ModuleManagerAfterActionListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
<?php | ||
|
||
use OpenEMR\Core\AbstractModuleActionListener; | ||
use OpenEMR\Modules\FaxSMS\BootstrapService; | ||
|
||
/** | ||
* Class to be called from Laminas Module Manager for reporting management actions. | ||
* Example is if the module is enabled, disabled or unregistered ect. | ||
* | ||
* The class is in the Laminas "Installer\Controller" namespace. | ||
* Currently, register isn't supported of which 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 the return value. | ||
* | ||
* @package OpenEMR Modules | ||
* @link https://www.open-emr.org | ||
* @author Jerry Padgett <[email protected]> | ||
* @copyright Copyright (c) 2024 Jerry Padgett <[email protected]> | ||
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 | ||
*/ | ||
/* | ||
* Do not declare a namespace | ||
* If you want Laminas manager to set namespace set it in getModuleNamespace | ||
* otherwise uncomment below and set path. | ||
* | ||
* */ | ||
|
||
/* | ||
$classLoader = new \OpenEMR\Core\ModulesClassLoader($GLOBALS['fileroot']); | ||
$classLoader->registerNamespaceIfNotExists("OpenEMR\\Modules\\FaxSMS\\", __DIR__ . DIRECTORY_SEPARATOR . 'src'); | ||
*/ | ||
|
||
class ModuleManagerAfterActionListener extends AbstractModuleActionListener | ||
{ | ||
public $service; | ||
private $authUser; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->authUser = (int)$this->getSession('authUserID'); | ||
$this->service = new BootstrapService(); | ||
} | ||
|
||
/** | ||
* @param $methodName | ||
* @param $modId | ||
* @param string $currentActionStatus | ||
* @return string On method success a $currentAction status should be returned or error string. | ||
*/ | ||
public function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string | ||
{ | ||
if (method_exists(self::class, $methodName)) { | ||
return self::$methodName($modId, $currentActionStatus); | ||
} else { | ||
return "Module cleanup method $methodName does not exist."; | ||
} | ||
} | ||
|
||
/** | ||
* Required method to return namespace | ||
* If namespace isn't provided return an empty | ||
* and register namespace using example at top of this script. | ||
* | ||
* @return string | ||
*/ | ||
public static function getModuleNamespace(): string | ||
{ | ||
return 'OpenEMR\\Modules\\FaxSMS\\'; | ||
} | ||
|
||
/** | ||
* Required method to return this class object, | ||
* so it is instantiated in Laminas Manager. | ||
* | ||
* @return ModuleManagerAfterActionListener | ||
*/ | ||
public static function initListenerSelf(): ModuleManagerAfterActionListener | ||
{ | ||
return new self(); | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private function install($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private function enable($modId, $currentActionStatus): mixed | ||
{ | ||
if (empty($this->service)) { | ||
$this->service = new BootstrapService(); | ||
} | ||
$globals = $this->service->fetchPersistedSetupSettings() ?? ''; | ||
if (empty($globals)) { | ||
$globals = $this->service->getVendorGlobals(); | ||
} | ||
$this->service->saveModuleListenerGlobals($globals); | ||
|
||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private function disable($modId, $currentActionStatus) | ||
{ | ||
if (empty($this->service)) { | ||
$this->service = new BootstrapService(); | ||
} | ||
// fetch current. | ||
$globals = $this->service->getVendorGlobals(); | ||
// persist current for enable action. | ||
$rid = $this->service->persistSetupSettings($globals); | ||
foreach ($globals as $k => $v) { | ||
if ($k == 'oefax_enable_sms' || $k == 'oefax_enable_fax') { | ||
// force disable of services | ||
$globals[$k] = 0; | ||
} | ||
} | ||
// save new disabled settings. | ||
$this->service->saveModuleListenerGlobals($globals); | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private function unregister($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private function install_sql($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
|
||
/** | ||
* @param $modId | ||
* @param $currentActionStatus | ||
* @return mixed | ||
*/ | ||
private function upgrade_sql($modId, $currentActionStatus): mixed | ||
{ | ||
return $currentActionStatus; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
* @author Robert Down | ||
* @copyright Unknown | ||
* @copyright Copyright (c) 2008 Larry Lart | ||
* @copyright Copyright (c) 2018-2023 Jerry Padgett | ||
* @copyright Copyright (c) 2018-2024 Jerry Padgett | ||
* @copyright Copyright (c) 2021 Robert Down <[email protected]> | ||
*/ | ||
|
||
|
@@ -24,16 +24,25 @@ | |
$backpic = ""; | ||
$clientApp = null; | ||
// for cron | ||
if (($argc ?? null) > 1 && empty($_SESSION['site_id']) && empty($_GET['site'])) { | ||
$c = stripos($argv[1], 'site='); | ||
if ($c === false) { | ||
echo xlt("Missing Site Id using default") . "\n"; | ||
$argv[1] = "site=default"; | ||
$error = ''; | ||
$runtime = []; | ||
|
||
// Check for other arguments and perform your script logic | ||
|
||
if (($argc ?? null) > 1) { | ||
foreach ($argv as $k => $v) { | ||
if ($k == 0) { | ||
continue; | ||
} | ||
$args = explode('=', $v); | ||
if ((count($args ?? [])) > 1) { | ||
$runtime[trim($args[0])] = trim($args[1]); | ||
} | ||
} | ||
$args = explode('=', $argv[1]); | ||
$_GET['site'] = $args[1] ?? 'default'; | ||
} | ||
$isCli = 0; | ||
if (php_sapi_name() === 'cli') { | ||
$isCli = 1; | ||
$_SERVER["HTTP_HOST"] = "localhost"; | ||
$ignoreAuth = true; | ||
} | ||
|
@@ -43,13 +52,32 @@ | |
require_once(__DIR__ . "/../../../../globals.php"); | ||
require_once("$srcdir/appointments.inc.php"); | ||
|
||
$TYPE = "SMS"; | ||
// Check for help argument | ||
if ($argc > 1 && (in_array('--help', $argv) || in_array('-h', $argv))) { | ||
displayHelp(); | ||
exit(0); | ||
} | ||
|
||
if (empty($runtime['site']) && empty($_SESSION['site_id']) && empty($_GET['site'])) { | ||
echo xlt("Missing Site Id using default") . "\n"; | ||
$_GET['site'] = $runtime['site'] = 'default'; | ||
} else { | ||
$_GET['site'] = $runtime['site']; | ||
} | ||
|
||
$TYPE = ''; | ||
if (!empty($runtime['type'])) { | ||
$TYPE = strtoupper($runtime['type']); | ||
} else { | ||
$TYPE = $runtime['type'] = "SMS"; // default | ||
} | ||
$CRON_TIME = 150; | ||
// use service if needed | ||
if ($TYPE === "SMS") { | ||
$_SESSION['authUser'] = $runtime['user'] ?? ''; | ||
$clientApp = AppDispatch::getApiService('sms'); | ||
$cred = $clientApp->getCredentials(); | ||
if (!$clientApp->verifyAcl()) { | ||
if (!$clientApp->verifyAcl('admin', 'docs', $runtime['user'] ?? '')) { | ||
die("<h3>" . xlt("Not Authorised!") . "</h3>"); | ||
} | ||
} | ||
|
@@ -62,7 +90,7 @@ | |
|
||
// check command line for quite option | ||
$bTestRun = isset($_REQUEST['dryrun']) ? 1 : 0; | ||
if ($argc > 1 && $argv[2] == 'test') { | ||
if (!empty($runtime['testrun'])) { | ||
$bTestRun = 1; | ||
} | ||
|
||
|
@@ -311,3 +339,22 @@ function cron_GetNotificationSettings(): bool|array | |
return ($vectNotificationSettings); | ||
} | ||
|
||
function displayHelp(): void | ||
{ | ||
//echo text($helpt); | ||
$help = | ||
<<<HELP | ||
Usage: php rc_sms_notification.php [options] | ||
Example: php rc_sms_notification.php site=default user=admin type=sms testrun=1 | ||
--help Display this help message | ||
Options: | ||
site={site_id} Site | ||
user={authUser} Authorized username not id. | ||
type={sms} Send method SMS or email. | ||
testrun={1} Test run set to 1 | ||
HELP; | ||
|
||
echo text($help); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
interface/modules/custom_modules/oe-module-faxsms/sql/3_0_0-to-3_1_0_upgrade.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
#IfMissingColumn module_faxsms_credentials setup_persist | ||
ALTER TABLE `module_faxsms_credentials` ADD `setup_persist` tinytext; | ||
#Endif |
Oops, something went wrong.