Repository navigation
Expand file tree
/
Copy pathModuleManagerListener.php
More file actions
61 lines (52 loc) · 1.82 KB
/
Copy pathModuleManagerListener.php
File metadata and controls
61 lines (52 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Called by the Module Manager on install, enable, disable and similar actions.
*
* Install SQL is in sql/install.sql and is run by the Module Manager itself.
* Uninstalling leaves the tables in place: they map each imported record back to its
* source, which later imports need so they add nothing twice.
*
* @package OpenHealthcare\Migration
* @license https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License 3
*/
use OpenEMR\Common\Database\QueryUtils;
use OpenEMR\Core\AbstractModuleActionListener;
class ModuleManagerListener extends AbstractModuleActionListener
{
public function __construct()
{
parent::__construct();
}
public function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string
{
if (method_exists(self::class, $methodName)) {
return self::$methodName($modId, $currentActionStatus);
}
return $currentActionStatus;
}
public static function getModuleNamespace(): string
{
return 'OpenHealthcare\\Migration\\';
}
public static function initListenerSelf(): ModuleManagerListener
{
return new self();
}
private function enable($modId, $currentActionStatus): mixed
{
self::setModuleState($modId, '1', '0');
return $currentActionStatus;
}
private function disable($modId, $currentActionStatus): mixed
{
self::setModuleState($modId, '0', '0');
return $currentActionStatus;
}
private static function setModuleState(int|string $modId, string $flag, string $flagUi): void
{
QueryUtils::sqlStatementThrowException(
"UPDATE `modules` SET `mod_active` = ?, `mod_ui_active` = ? WHERE `mod_id` = ? OR `mod_directory` = ?",
[$flag, $flagUi, $modId, $modId],
);
}
}