1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallUtils.class.php";
14:
15: class Legacy_ModuleUninstaller
16: {
17: 18: 19: 20: 21: 22:
23: var $mLog = null;
24:
25: var $_mForceMode = false;
26:
27: 28: 29: 30: 31:
32: var $_mXoopsModule = null;
33:
34: 35: 36: 37: 38: 39: 40: 41:
42: var $m_fireNotifyUninstallTemplateBegun;
43:
44: function Legacy_ModuleUninstaller()
45: {
46: $this->mLog =new Legacy_ModuleInstallLog();
47: $this->m_fireNotifyUninstallTemplateBegun =new XCube_Delegate();
48: $this->m_fireNotifyUninstallTemplateBegun->register("Legacy_ModuleUninstaller._fireNotifyUninstallTemplateBegun");
49: }
50:
51: 52: 53: 54: 55: 56:
57: function setCurrentXoopsModule(&$xoopsModule)
58: {
59: $this->_mXoopsModule =& $xoopsModule;
60: }
61:
62: 63: 64: 65:
66: function setForceMode($isForceMode)
67: {
68: $this->_mForceMode = $isForceMode;
69: }
70:
71: 72: 73: 74: 75: 76:
77: function _uninstallModule()
78: {
79: $moduleHandler =& xoops_gethandler('module');
80: if (!$moduleHandler->delete($this->_mXoopsModule)) {
81: $this->mLog->addError(_AD_LEGACY_ERROR_DELETE_MODULEINFO_FROM_DB);
82: }
83: else {
84: $this->mLog->addReport(_AD_LEGACY_MESSAGE_DELETE_MODULEINFO_FROM_DB);
85: }
86: }
87:
88: 89: 90: 91: 92:
93: function _uninstallTables()
94: {
95: $root =& XCube_Root::getSingleton();
96: $db =& $root->mController->getDB();
97:
98: $dirname = $this->_mXoopsModule->get('dirname');
99: $t_search = array('{prefix}', '{dirname}', '{Dirname}', '{_dirname_}');
100: $t_replace = array(XOOPS_DB_PREFIX, strtolower($dirname), ucfirst(strtolower($dirname)), $dirname);
101:
102: $tables = $this->_mXoopsModule->getInfo('tables');
103: if ($tables != false && is_array($tables)) {
104: foreach($tables as $table) {
105:
106:
107:
108: $t_tableName = $table;
109: if (isset($this->_mXoopsModule->modinfo['cube_style']) && $this->_mXoopsModule->modinfo['cube_style'] == true) {
110: $t_tableName = str_replace($t_search, $t_replace, $table);
111: }
112: else {
113: $t_tableName = $db->prefix($table);
114: }
115:
116: $sql = "DROP TABLE " . $t_tableName;
117:
118: if ($db->query($sql)) {
119: $this->mLog->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_DROP_TABLE, $t_tableName));
120: }
121: else {
122: $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_DROP_TABLE, $t_tableName));
123: }
124: }
125: }
126: }
127:
128: 129: 130: 131:
132: function _uninstallTemplates()
133: {
134: $this->m_fireNotifyUninstallTemplateBegun->call(new XCube_Ref($this->_mXoopsModule));
135: Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates($this->_mXoopsModule, $this->mLog);
136: }
137:
138: 139: 140: 141: 142:
143: function _uninstallBlocks()
144: {
145: Legacy_ModuleInstallUtils::uninstallAllOfBlocks($this->_mXoopsModule, $this->mLog);
146:
147:
148:
149:
150: $tplHandler =& xoops_gethandler('tplfile');
151: $criteria =new Criteria('tpl_module', $this->_mXoopsModule->get('dirname'));
152: if(!$tplHandler->deleteAll($criteria)) {
153: $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_DELETE_BLOCK_TEMPLATES, $tplHandler->db->error()));
154: }
155: }
156:
157: function _uninstallPreferences()
158: {
159: Legacy_ModuleInstallUtils::uninstallAllOfConfigs($this->_mXoopsModule, $this->mLog);
160: Legacy_ModuleInstallUtils::deleteAllOfNotifications($this->_mXoopsModule, $this->mLog);
161: Legacy_ModuleInstallUtils::deleteAllOfComments($this->_mXoopsModule, $this->mLog);
162: }
163:
164: function _processScript()
165: {
166: $installScript = trim($this->_mXoopsModule->getInfo('onUninstall'));
167: if ($installScript != false) {
168: require_once XOOPS_MODULE_PATH . "/" . $this->_mXoopsModule->get('dirname') . "/" . $installScript;
169: $funcName = 'xoops_module_uninstall_' . $this->_mXoopsModule->get('dirname');
170:
171: if (!preg_match("/^[a-zA-Z_][a-zA-Z0-9_]*$/", $funcName)) {
172: $this->mLog->addError(XCUbe_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName));
173: return;
174: }
175:
176: if (function_exists($funcName)) {
177: if (!call_user_func($funcName, $this->_mXoopsModule, new XCube_Ref($this->mLog))) {
178: $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName));
179: }
180: }
181: }
182: }
183:
184: function _processReport()
185: {
186: if (!$this->mLog->hasError()) {
187: $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_MODULE_SUCCESSFUL, $this->_mXoopsModule->get('name')));
188: }
189: else {
190: $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get('name')));
191: }
192: }
193:
194: 195: 196:
197: function executeUninstall()
198: {
199: $this->_uninstallTables();
200: if (!$this->_mForceMode && $this->mLog->hasError()) {
201: $this->_processReport();
202: return false;
203: }
204: if ($this->_mXoopsModule->get('mid') != null) {
205: $this->_uninstallModule();
206: if (!$this->_mForceMode && $this->mLog->hasError()) {
207: $this->_processReport();
208: return false;
209: }
210:
211: $this->_uninstallTemplates();
212: if (!$this->_mForceMode && $this->mLog->hasError()) {
213: $this->_processReport();
214: return false;
215: }
216:
217: $this->_uninstallBlocks();
218: if (!$this->_mForceMode && $this->mLog->hasError()) {
219: $this->_processReport();
220: return false;
221: }
222:
223: $this->_uninstallPreferences();
224: if (!$this->_mForceMode && $this->mLog->hasError()) {
225: $this->_processReport();
226: return false;
227: }
228:
229: $this->_processScript();
230: if (!$this->_mForceMode && $this->mLog->hasError()) {
231: $this->_processReport();
232: return false;
233: }
234: }
235: $this->_processReport();
236:
237: return true;
238: }
239: }
240:
241: ?>
242: