Repository navigation
Expand file tree
/
Copy pathModuleManagerListener.php
More file actions
157 lines (140 loc) · 4.13 KB
/
Copy pathModuleManagerListener.php
File metadata and controls
157 lines (140 loc) · 4.13 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
/**
* Class to be called from Laminas Module Manager for reporting management actions.
* This listener enables module lifecycle hooks, including SQL upgrade hooks.
*
* @package OpenEMR Modules
* @link https://www.open-emr.org
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
use OpenEMR\Core\AbstractModuleActionListener;
class ModuleManagerListener extends AbstractModuleActionListener
{
public function __construct()
{
parent::__construct();
}
/**
* @param string $methodName
* @param mixed $modId
* @param string $currentActionStatus
* @return string
*/
public function moduleManagerAction($methodName, $modId, string $currentActionStatus = 'Success'): string
{
if (method_exists(self::class, $methodName)) {
return self::$methodName($modId, $currentActionStatus);
}
return $currentActionStatus;
}
/**
* Required method to return namespace.
*
* @return string
*/
public static function getModuleNamespace(): string
{
return 'Juggernaut\\SimpleStorageSolution\\Module\\';
}
/**
* Required method to return this class object.
*
* @return ModuleManagerListener
*/
public static function initListenerSelf(): ModuleManagerListener
{
return new self();
}
/**
* @param mixed $modId
* @param string $currentActionStatus
* @return string
*/
private function install($modId, string $currentActionStatus): string
{
return $currentActionStatus;
}
/**
* @param mixed $modId
* @param string $currentActionStatus
* @return string
*/
private function enable($modId, string $currentActionStatus): string
{
return $currentActionStatus;
}
/**
* @param mixed $modId
* @param string $currentActionStatus
* @return string
*/
private function disable($modId, string $currentActionStatus): string
{
return $currentActionStatus;
}
/**
* @param mixed $modId
* @param string $currentActionStatus
* @return string
*/
private function unregister($modId, string $currentActionStatus): string
{
$logPrefix = 'oe-simple-storage-solution unregister cleanup';
$tablesToDrop = [
'module_s3_credentials',
];
try {
foreach ($tablesToDrop as $tableName) {
$sql = "DROP TABLE IF EXISTS `" . $tableName . "`";
sqlStatement($sql);
error_log(sprintf('%s: dropped table %s', $logPrefix, $tableName));
}
return $currentActionStatus;
} catch (\Throwable $throwable) {
error_log(
sprintf(
'%s error for modId=%s: %s',
$logPrefix,
(string) $modId,
$throwable->getMessage()
)
);
return 'Cleanup failed: ' . $throwable->getMessage();
}
}
/**
* Hook called by Module Manager when running install SQL.
*
* @param mixed $modId
* @param string $currentActionStatus
* @return string
*/
private function install_sql($modId, string $currentActionStatus): string
{
return $currentActionStatus;
}
/**
* Hook called by Module Manager when running upgrade SQL scripts.
*
* @param mixed $modId
* @param string $currentActionStatus
* @return string
*/
private function upgrade_sql($modId, string $currentActionStatus): string
{
try {
$message = sprintf(
'oe-simple-storage-solution upgrade_sql hook invoked: modId=%s status=%s',
(string) $modId,
$currentActionStatus
);
error_log($message);
return $currentActionStatus;
} catch (\Throwable $throwable) {
error_log(
'oe-simple-storage-solution upgrade_sql hook error: ' . $throwable->getMessage()
);
return $currentActionStatus;
}
}
}