XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ModuleUninstaller.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_LEGACY_PATH . '/admin/class/ModuleInstallUtils.class.php';
17
18class Legacy_ModuleUninstaller
19{
26 public $mLog = null;
27
28 public $_mForceMode = false;
29
35 public $_mXoopsModule = null;
36
46
47 public function Legacy_ModuleUninstaller()
48 {
49 self::__construct();
50 }
51
52 public function __construct()
53 {
54 $this->mLog =new Legacy_ModuleInstallLog();
55 $this->m_fireNotifyUninstallTemplateBegun =new XCube_Delegate();
56 $this->m_fireNotifyUninstallTemplateBegun->register('Legacy_ModuleUninstaller._fireNotifyUninstallTemplateBegun');
57 }
58
65 public function setCurrentXoopsModule(&$xoopsModule)
66 {
67 $this->_mXoopsModule =& $xoopsModule;
68 }
69
74 public function setForceMode($isForceMode)
75 {
76 $this->_mForceMode = $isForceMode;
77 }
78
85 public function _uninstallModule()
86 {
87 $moduleHandler =& xoops_gethandler('module');
88 if (!$moduleHandler->delete($this->_mXoopsModule)) {
89 $this->mLog->addError(_AD_LEGACY_ERROR_DELETE_MODULEINFO_FROM_DB);
90 } else {
91 $this->mLog->addReport(_AD_LEGACY_MESSAGE_DELETE_MODULEINFO_FROM_DB);
92 }
93 }
94
100 public function _uninstallTables()
101 {
102 $root =& XCube_Root::getSingleton();
103 $db =& $root->mController->getDB();
104
105 $dirname = $this->_mXoopsModule->get('dirname');
106 $t_search = ['{prefix}', '{dirname}', '{Dirname}', '{_dirname_}'];
107 $t_replace = [XOOPS_DB_PREFIX, strtolower($dirname), ucfirst(strtolower($dirname)), $dirname];
108
109 $tables = $this->_mXoopsModule->getInfo('tables');
110 if (false != $tables && is_array($tables)) {
111 foreach ($tables as $table) {
112 //
113 // TODO Do we need to check reserved core tables?
114 //
115 $t_tableName = $table;
116 if (isset($this->_mXoopsModule->modinfo['cube_style']) && true == $this->_mXoopsModule->modinfo['cube_style']) {
117 $t_tableName = str_replace($t_search, $t_replace, $table);
118 } else {
119 $t_tableName = $db->prefix($table);
120 }
121
122 $sql = 'DROP TABLE ' . $t_tableName;
123
124 if ($db->query($sql)) {
125 $this->mLog->addReport(XCube_Utils::formatString(_AD_LEGACY_MESSAGE_DROP_TABLE, $t_tableName));
126 } else {
127 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_DROP_TABLE, $t_tableName));
128 }
129 }
130 }
131 }
132
137 public function _uninstallTemplates()
138 {
139 $this->m_fireNotifyUninstallTemplateBegun->call(new XCube_Ref($this->_mXoopsModule));
140 Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates($this->_mXoopsModule, $this->mLog);
141 }
142
148 public function _uninstallBlocks()
149 {
150 Legacy_ModuleInstallUtils::uninstallAllOfBlocks($this->_mXoopsModule, $this->mLog);
151
152 //
153 // Additional
154 //
155 $tplHandler =& xoops_gethandler('tplfile');
156 $criteria =new Criteria('tpl_module', $this->_mXoopsModule->get('dirname'));
157 if (!$tplHandler->deleteAll($criteria)) {
158 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_COULD_NOT_DELETE_BLOCK_TEMPLATES, $tplHandler->db->error()));
159 }
160 }
161
162 public function _uninstallPreferences()
163 {
164 Legacy_ModuleInstallUtils::uninstallAllOfConfigs($this->_mXoopsModule, $this->mLog);
165 Legacy_ModuleInstallUtils::deleteAllOfNotifications($this->_mXoopsModule, $this->mLog);
166 Legacy_ModuleInstallUtils::deleteAllOfComments($this->_mXoopsModule, $this->mLog);
167 }
168
169 public function _processScript()
170 {
171 $installScript = trim($this->_mXoopsModule->getInfo('onUninstall'));
172 if (false != $installScript) {
173 require_once XOOPS_MODULE_PATH . '/' . $this->_mXoopsModule->get('dirname') . '/' . $installScript;
174 $funcName = 'xoops_module_uninstall_' . $this->_mXoopsModule->get('dirname');
175
176 if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $funcName)) {
177 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName));
178 return;
179 }
180
181 if (function_exists($funcName)) {
182 // Because X2 can use reference parameter, Legacy doesn't use the following code;'
183 // if (!call_user_func($funcName, $this->_mXoopsModule, new XCube_Ref($this->mLog))) {
184
185 $result = $funcName($this->_mXoopsModule, new XCube_Ref($this->mLog));
186 if (!$result) {
187 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName));
188 }
189 }
190 }
191 }
192
193 public function _processReport()
194 {
195 if (!$this->mLog->hasError()) {
196 $this->mLog->add(XCube_Utils::formatString(_AD_LEGACY_MESSAGE_UNINSTALLATION_MODULE_SUCCESSFUL, $this->_mXoopsModule->get('name')));
197 } else {
198 $this->mLog->addError(XCube_Utils::formatString(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get('name')));
199 }
200 }
201
205 public function executeUninstall()
206 {
207 $this->_uninstallTables();
208 if (!$this->_mForceMode && $this->mLog->hasError()) {
209 $this->_processReport();
210 return false;
211 }
212 if (null != $this->_mXoopsModule->get('mid')) {
213 $this->_uninstallModule();
214 if (!$this->_mForceMode && $this->mLog->hasError()) {
215 $this->_processReport();
216 return false;
217 }
218
219 $this->_uninstallTemplates();
220 if (!$this->_mForceMode && $this->mLog->hasError()) {
221 $this->_processReport();
222 return false;
223 }
224
225 $this->_uninstallBlocks();
226 if (!$this->_mForceMode && $this->mLog->hasError()) {
227 $this->_processReport();
228 return false;
229 }
230
231 $this->_uninstallPreferences();
232 if (!$this->_mForceMode && $this->mLog->hasError()) {
233 $this->_processReport();
234 return false;
235 }
236
237 $this->_processScript();
238 if (!$this->_mForceMode && $this->mLog->hasError()) {
239 $this->_processReport();
240 return false;
241 }
242 }
243 $this->_processReport();
244
245 return true;
246 }
247}
static uninstallAllOfConfigs(&$module, &$log)
static uninstallAllOfBlocks(&$module, &$log)
$m_fireNotifyUninstallTemplateBegun
XCube_Delegate.
[Final] Used for the simple mechanism for common delegation in XCube.
static formatString()
[Static] Formats string with special care for international.