18class Legacy_ModuleUninstaller
28 public $_mForceMode =
false;
35 public $_mXoopsModule =
null;
47 public function Legacy_ModuleUninstaller()
52 public function __construct()
56 $this->m_fireNotifyUninstallTemplateBegun->register(
'Legacy_ModuleUninstaller._fireNotifyUninstallTemplateBegun');
67 $this->_mXoopsModule =& $xoopsModule;
76 $this->_mForceMode = $isForceMode;
87 $moduleHandler =& xoops_gethandler(
'module');
88 if (!$moduleHandler->delete($this->_mXoopsModule)) {
89 $this->mLog->addError(_AD_LEGACY_ERROR_DELETE_MODULEINFO_FROM_DB);
91 $this->mLog->addReport(_AD_LEGACY_MESSAGE_DELETE_MODULEINFO_FROM_DB);
102 $root =& XCube_Root::getSingleton();
103 $db =& $root->mController->getDB();
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];
109 $tables = $this->_mXoopsModule->getInfo(
'tables');
110 if (
false != $tables && is_array($tables)) {
111 foreach ($tables as $table) {
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);
119 $t_tableName = $db->prefix($table);
122 $sql =
'DROP TABLE ' . $t_tableName;
124 if ($db->query($sql)) {
139 $this->m_fireNotifyUninstallTemplateBegun->call(
new XCube_Ref($this->_mXoopsModule));
140 Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates($this->_mXoopsModule, $this->mLog);
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()));
162 public function _uninstallPreferences()
165 Legacy_ModuleInstallUtils::deleteAllOfNotifications($this->_mXoopsModule, $this->mLog);
166 Legacy_ModuleInstallUtils::deleteAllOfComments($this->_mXoopsModule, $this->mLog);
169 public function _processScript()
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');
176 if (!preg_match(
'/^[a-zA-Z_][a-zA-Z0-9_]*$/', $funcName)) {
181 if (function_exists($funcName)) {
185 $result = $funcName($this->_mXoopsModule,
new XCube_Ref($this->mLog));
193 public function _processReport()
195 if (!$this->mLog->hasError()) {
196 $this->mLog->add(
XCube_Utils::formatString(_AD_LEGACY_MESSAGE_UNINSTALLATION_MODULE_SUCCESSFUL, $this->_mXoopsModule->get(
'name')));
198 $this->mLog->addError(
XCube_Utils::formatString(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get(
'name')));
208 if (!$this->_mForceMode && $this->mLog->hasError()) {
209 $this->_processReport();
212 if (
null != $this->_mXoopsModule->get(
'mid')) {
214 if (!$this->_mForceMode && $this->mLog->hasError()) {
215 $this->_processReport();
220 if (!$this->_mForceMode && $this->mLog->hasError()) {
221 $this->_processReport();
226 if (!$this->_mForceMode && $this->mLog->hasError()) {
227 $this->_processReport();
231 $this->_uninstallPreferences();
232 if (!$this->_mForceMode && $this->mLog->hasError()) {
233 $this->_processReport();
237 $this->_processScript();
238 if (!$this->_mForceMode && $this->mLog->hasError()) {
239 $this->_processReport();
243 $this->_processReport();