Minahito
minah****@users*****
2006年 11月 1日 (水) 20:55:09 JST
Index: xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php diff -u xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php:1.1.2.2 xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php:1.1.2.3 --- xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php:1.1.2.2 Sun Oct 15 01:00:51 2006 +++ xoops2jp/html/modules/legacy/admin/class/ModuleUninstaller.class.php Wed Nov 1 20:55:09 2006 @@ -2,58 +2,62 @@ if (!defined('XOOPS_ROOT_PATH')) exit(); -require_once XOOPS_LEGACY_PATH."/admin/class/AbstractModuleInstaller.class.php"; +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUtils.class.php"; +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallUtils.class.php"; -class Legacy_ModuleUninstaller extends Legacy_AbstractModuleInstaller +class Legacy_ModuleUninstaller { - function Legacy_ModuleUninstaller($dirname) + /** + * This instance is prepared automatically in the constructor. + * + * @public + * @var Legacy_ModuleUtilsSimpleLog + */ + var $mLog = null; + + var $_mForceMode = false; + + /** + * @protected + * @var XoopsModule + */ + var $_mXoopsModule = null; + + function Legacy_ModuleUninstaller() { - parent::Legacy_AbstractModuleInstaller($dirname); - - $this->mProcessScript->register('Legacy_ModuleUninstaller.ProcessScript'); - $this->mProcessScript->add('Legacy_ModuleUninstaller::_processScript'); - - $this->mInstallTable->register('Legacy_ModuleInstaller.InstallTable'); - $this->mInstallTable->add('Legacy_ModuleUninstaller::_uninstallTable'); - - $this->mInstallTemplate->register('Legacy_ModuleUninstaller.InstallTemplate'); - $this->mInstallTemplate->add('Legacy_ModuleUninstaller::_uninstallTemplate'); + $this->mLog =& new Legacy_ModuleUtilsSimpleLog(); } /** - * Load xoops module object that isn't installed and return it. - * @static - * @access public - * @param $dirname string - * @return XoopsModule + * Sets the current XoopsModule. + * + * @public + * @param XoopsModule $xoopsModule */ - function &loadModuleObject($dirname) + function setCurrentXoopsModule(&$xoopsModule) { - $error = null; - - $moduleHandler =& xoops_gethandler('module'); - $module =& $moduleHandler->getByDirname($dirname); - - if (!is_object($module)) { - $this->mLog->addError(_AD_LEGACY_ERROR_MODULE_NOT_FOUND); - return $error; - } - - if ($module->getVar('isactive') != 0) { - $this->mLog->addError(_AD_LEGACY_ERROR_CASE_OF_ACTIVE_MODULE); - return $error; - } - - return $module; + $this->_mXoopsModule =& $xoopsModule; + } + + /** + * Sets a value indicating whether the force mode is on. + * @param bool $isForceMode + */ + function setForceMode($isForceMode) + { + $this->_mForceMode = $isForceMode; } /** - * Delete module information from XOOPS database because this class is uninstaller. + * Deletes module information from XOOPS database because this class is + * uninstaller. + * + * @protected */ - function _installModule() + function _uninstallModule() { $moduleHandler =& xoops_gethandler('module'); - if (!$moduleHandler->delete($this->mModule)) { + if (!$moduleHandler->delete($this->_mXoopsModule)) { $this->mLog->addError(_AD_LEGACY_ERROR_DELETE_MODULEINFO_FROM_DB); } else { @@ -63,13 +67,15 @@ /** * Drop table because this class is uninstaller. + * + * @protected */ - function _uninstallTable(&$module, &$log) + function _uninstallTables() { $root =& XCube_Root::getSingleton(); $db =& $root->mController->getDB(); - $tables = $module->getInfo('tables'); + $tables = $this->_mXoopsModule->getInfo('tables'); if ($tables != false && is_array($tables)) { foreach($tables as $table) { // @@ -77,10 +83,10 @@ // $sql = "DROP TABLE " . $db->prefix($table); if ($db->query($sql)) { - $log->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_DROP_TABLE, $db->prefix($table))); + $this->mLog->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_DROP_TABLE, $db->prefix($table))); } else { - $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_DROP_TABLE, $db->prefix($table))); + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_DROP_TABLE, $db->prefix($table))); } } } @@ -88,66 +94,46 @@ /** * Delete template because this class is uninstaller. + * @protected */ - function _uninstallTemplate(&$module, &$log) + function _uninstallTemplates() { - $tplHandler =& xoops_gethandler('tplfile'); - - $deleteTemplates =& $tplHandler->find(null, 'module', $module->getVar('mid')); - - foreach($deleteTemplates as $tpl) { - if (!$tplHandler->delete($tpl)) { - $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_TEMPLATE_UNINSTALLED, $tpl->getVar('tpl_file'))); - } - } + Legacy_ModuleInstallUtils::uninstallAllOfModuleTemplates($this->_mXoopsModule, $this->mLog, false); } /** * Delete all of module's blocks. + * + * @note Templates Delete is move into Legacy_ModuleInstallUtils. */ - function _installBlock() + function _uninstallBlocks() { - $blockHandler =& xoops_gethandler('block'); - $criteria = new Criteria('mid', $this->mModule->getVar('mid')); - - $blocks =& $blockHandler->getObjectsDirectly($criteria); - - $gpermHandler =& xoops_gethandler('groupperm'); - foreach ($blocks as $block) { - $blockHandler->delete($block); - $this->mLog->addReport(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_BLOCK_HAS_BEEN_UNINSTALLED, $block->get('name'))); - - // - // delete permission - // - $criteria =& new CriteriaCompo(); - $criteria->add(new Criteria('gperm_name', 'block_read')); - $criteria->add(new Criteria('gperm_itemid', $block->getVar('bid'))); - $criteria->add(new Criteria('gperm_modid', 1)); - $gpermHandler->deleteAll($criteria); - } + Legacy_ModuleInstallUtils::uninstallAllOfBlocks($this->_mXoopsModule, $this->mLog); + // + // Additional + // $tplHandler =& xoops_gethandler('tplfile'); - $criteria =& new Criteria('tpl_module', $this->mModule->getVar('dirname')); + $criteria =& new Criteria('tpl_module', $this->_mXoopsModule->get('dirname')); if(!$tplHandler->deleteAll($criteria)) { $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_DELETE_BLOCK_TEMPLATES, $tplHandler->db->error())); } } - function _installPreference() + function _uninstallPreferences() { Legacy_ModuleUtils::deleteAllConfigs($this->mModule, $this->mLog); } - function _processScript(&$module, &$log) + function _processScript() { - $installScript = trim($module->getInfo('onUninstall')); + $installScript = trim($this->_mXoopsModule->getInfo('onUninstall')); if ($installScript != false) { - require_once XOOPS_MODULE_PATH . "/" . $module->getVar('dirname') . "/" . $installScript; - $funcName = 'xoops_module_uninstall_' . $module->getVar('dirname'); + require_once XOOPS_MODULE_PATH . "/" . $this->_mXoopsModule->get('dirname') . "/" . $installScript; + $funcName = 'xoops_module_uninstall_' . $this->_mXoopsModule->get('dirname'); if (function_exists($funcName)) { - if (!call_user_func($funcName, $module)) { - $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName)); + if (!call_user_func($funcName, $this->_mXoopsModule)) { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName)); } } } @@ -156,17 +142,59 @@ function _processReport() { if (!$this->mLog->hasError()) { - $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_MODULE_SUCCESSFUL, $this->mModule->get('name'))); + $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_UNINSTALLATION_MODULE_SUCCESSFUL, $this->_mXoopsModule->get('name'))); } else { - if (is_object($this->mModule)) { - $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->mModule->get('name'))); + if (is_object($this->_mXoopsModule)) { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get('name'))); } else { - $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->mDirname)); + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_UNINSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get('dirname'))); } } } + + /** + * @todo Check whether $this->_mXoopsObject is ready. + */ + function executeUninstall() + { + $this->_uninstallTables(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_uninstallModule(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_uninstallTemplates(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_uninstallBlocks(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_uninstallPreferences(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_processScript(); + + $this->_processReport(); + + return true; + } } ?> \ No newline at end of file Index: xoops2jp/html/modules/legacy/admin/class/ModuleUtils.class.php diff -u xoops2jp/html/modules/legacy/admin/class/ModuleUtils.class.php:1.1.2.4 xoops2jp/html/modules/legacy/admin/class/ModuleUtils.class.php:1.1.2.5 --- xoops2jp/html/modules/legacy/admin/class/ModuleUtils.class.php:1.1.2.4 Tue Oct 31 16:21:47 2006 +++ xoops2jp/html/modules/legacy/admin/class/ModuleUtils.class.php Wed Nov 1 20:55:09 2006 @@ -44,8 +44,12 @@ } /** + * @brief Old utility class with static methods for installation. + * * This provides static methods for the module installation. Methods of this * class may move to base class of installers. + * + * @deprecated see Legacy_ModuleInstallUtils */ class Legacy_ModuleUtils { @@ -574,12 +578,12 @@ */ function deleteAllConfigs(&$module, &$log) { - if ($this->mModule->getVar('hasconfig') == 0) { + if ($module->get('hasconfig') == 0) { return; } $configHandler =& xoops_gethandler('config'); - $configs =& $configHandler->getConfigs(new Criteria('conf_modid', $this->mModule->getVar('mid'))); + $configs =& $configHandler->getConfigs(new Criteria('conf_modid', $module->get('mid'))); if (count($configs) == 0) { return;