Minahito
minah****@users*****
2006年 11月 2日 (木) 00:01:42 JST
Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php diff -u xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php:1.1.2.3 xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php:1.1.2.4 --- xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php:1.1.2.3 Tue Oct 31 16:21:21 2006 +++ xoops2jp/html/modules/legacy/admin/class/ModuleInstaller.class.php Thu Nov 2 00:01:42 2006 @@ -1,141 +1,146 @@ <?php +/** + * @package Legacy + * @version $Id$ + */ 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"; /** * This class extends a base class for the process of install module. This is added * some private functions. + * + * @todo It seems possibility to abstract with other installer classes. */ -class Legacy_ModuleInstaller extends Legacy_AbstractModuleInstaller +class Legacy_ModuleInstaller { - var $mAgree = false; + /** + * @public + * @var Legacy_ModuleUtilsSimpleLog + */ + var $mLog = null; + + var $_mForceMode = false; - function Legacy_ModuleInstaller($dirname) + /** + * @var XoopsModule + */ + var $_mXoopsModule = null; + + function Legacy_ModuleInstaller() { - parent::Legacy_AbstractModuleInstaller($dirname); - - $this->mProcessScript->register('Legacy_ModuleInstaller.ProcessScript'); - $this->mProcessScript->add('Legacy_ModuleInstaller::_processScript'); - - $this->mInstallTable->register('Legacy_ModuleInstaller.InstallTable'); - $this->mInstallTable->add('Legacy_ModuleUtils::installTable'); - - $this->mInstallTemplate->register('Legacy_ModuleInstaller.InstallTemplate'); - $this->mInstallTemplate->add('Legacy_ModuleInstaller::_installTemplate'); + $this->mLog =& new Legacy_ModuleUtilsSimpleLog(); } - /** - * Load xoops module object that isn't installed and return it. - * @static - * @access public - * @param $dirname string - * @return XoopsModule - */ - function &loadModuleObject($dirname) - { - $ret = null; - - $moduleHandler =& xoops_gethandler('module'); - $module =& $moduleHandler->getByDirname($dirname); - - if (is_object($module)) - return $ret; - - $module =& $moduleHandler->create(); - $module->setVar('weight', 1); - $module->loadInfoAsVar($this->mDirname); - - if ($module->get('dirname') == null) { - return $ret; - } - - if ($module->get('dirname') == 'system') { - $module->setVar('mid', 1); - } - - if (isset($module->modinfo['installer']) && isset($module->modinfo['installer']['licence']) ) { - $this->mAgree = true; - } - - return $module; - } - + /** + * Sets the current XoopsModule. + * + * @public + * @param XoopsModule $xoopsModule + */ + function setCurrentXoopsModule(&$xoopsModule) + { + $this->_mXoopsModule =& $xoopsModule; + } + + /** + * Sets a value indicating whether the force mode is on. + * @param bool $isForceMode + */ + function setForceMode($isForceMode) + { + $this->_mForceMode = $isForceMode; + } + + function _installTables() + { + Legacy_ModuleInstallUtils::installSQLAutomatically($this->_mXoopsModule, $this->mLog); + } + + /** + * @todo Do rewrite. + */ function _installModule() { - if (parent::_installModule()) { - $gpermHandler =& xoops_gethandler('groupperm'); + $moduleHandler =& xoops_gethandler('module'); + if (!$moduleHandler->insert($this->_mXoopsModule)) { + $this->mLog->addError("*Could not install module information*"); + return false; + } + + $gpermHandler =& xoops_gethandler('groupperm'); - // - // Add a permission which administrators can manage. - // - if ($this->mModule->getInfo('hasAdmin')) { - $adminPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); - $adminPerm->setVar('gperm_name', 'module_admin'); + // + // Add a permission which administrators can manage. + // + if ($this->_mXoopsModule->getInfo('hasAdmin')) { + $adminPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); + $adminPerm->setVar('gperm_name', 'module_admin'); - if (!$gpermHandler->insert($adminPerm)) { - $log->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_ADMIN_PERMISSION); - } + if (!$gpermHandler->insert($adminPerm)) { + $this->mLog->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_ADMIN_PERMISSION); } + } - // - // Add a permission which administrators can manage. (Special for Legacy System Module) - // - if ($this->mModule->getVar('dirname') == 'system') { - $root =& XCube_Root::getSingleton(); - $root->mLanguageManager->loadModuleAdminMessageCatalog('system'); - - require_once XOOPS_ROOT_PATH . "/modules/system/constants.php"; - - $fileHandler = opendir(XOOPS_ROOT_PATH . "/modules/system/admin"); - while ($file = readdir($fileHandler)) { - $infoFile = XOOPS_ROOT_PATH . "/modules/system/admin/" . $file . "/xoops_version.php"; - if (file_exists($infoFile)) { - require_once $infoFile; - if (!empty($modversion['category'])) { - $sysAdminPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); - $adminPerm->setVar('gperm_itemid', $modversion['category']); - $adminPerm->setVar('gperm_name', 'system_admin'); - if (!$gpermHandler->insert($adminPerm)) { - $log->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_SYSTEM_PERMISSION); - } - unset($sysAdminPerm); + // + // Add a permission which administrators can manage. (Special for Legacy System Module) + // + if ($this->_mXoopsModule->getVar('dirname') == 'system') { + $root =& XCube_Root::getSingleton(); + $root->mLanguageManager->loadModuleAdminMessageCatalog('system'); + + require_once XOOPS_ROOT_PATH . "/modules/system/constants.php"; + + $fileHandler = opendir(XOOPS_ROOT_PATH . "/modules/system/admin"); + while ($file = readdir($fileHandler)) { + $infoFile = XOOPS_ROOT_PATH . "/modules/system/admin/" . $file . "/xoops_version.php"; + if (file_exists($infoFile)) { + require_once $infoFile; + if (!empty($modversion['category'])) { + $sysAdminPerm =& $this->_createPermission(XOOPS_GROUP_ADMIN); + $adminPerm->setVar('gperm_itemid', $modversion['category']); + $adminPerm->setVar('gperm_name', 'system_admin'); + if (!$gpermHandler->insert($adminPerm)) { + $this->mLog->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_SYSTEM_PERMISSION); } - unset($modversion); + unset($sysAdminPerm); } + unset($modversion); } } - - if ($this->mModule->getInfo('hasMain')) { - $read_any = $this->mModule->getInfo('read_any'); - if ($read_any) { - $memberHandler =& xoops_gethandler('member'); - $groupObjects =& $memberHandler->getGroups(); - // - // Add a permission all group members and guest can read. - // - foreach($groupObjects as $group) { - $readPerm =& $this->_createPermission($group->getVar('groupid')); - $readPerm->setVar('gperm_name', 'module_read'); + } + + if ($this->_mXoopsModule->getInfo('hasMain')) { + $read_any = $this->_mXoopsModule->getInfo('read_any'); + if ($read_any) { + $memberHandler =& xoops_gethandler('member'); + $groupObjects =& $memberHandler->getGroups(); + // + // Add a permission all group members and guest can read. + // + foreach($groupObjects as $group) { + $readPerm =& $this->_createPermission($group->getVar('groupid')); + $readPerm->setVar('gperm_name', 'module_read'); - if (!$gpermHandler->insert($readPerm)) { - $log->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_READ_PERMISSION); - } + if (!$gpermHandler->insert($readPerm)) { + $log->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_READ_PERMISSION); } - } else { - // - // Add a permission which administrators can read. - // - $root =& XCube_Root::getSingleton(); - $groups = $root->mContext->mXoopsUser->getGroups(); - foreach($groups as $mygroup) { - $readPerm =& $this->_createPermission($mygroup); - $readPerm->setVar('gperm_name', 'module_read'); + } + } else { + // + // Add a permission which administrators can read. + // + $root =& XCube_Root::getSingleton(); + $groups = $root->mContext->mXoopsUser->getGroups(); + foreach($groups as $mygroup) { + $readPerm =& $this->_createPermission($mygroup); + $readPerm->setVar('gperm_name', 'module_read'); - if (!$gpermHandler->insert($readPerm)) { - $log->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_READ_PERMISSION); - } + if (!$gpermHandler->insert($readPerm)) { + $this->mLog->addError(_AD_LEGACY_ERROR_COULD_NOT_SET_READ_PERMISSION); } } } @@ -155,7 +160,7 @@ $perm =& $gpermHandler->create(); $perm->setVar('gperm_groupid', $group); - $perm->setVar('gperm_itemid', $this->mModule->getVar('mid')); + $perm->setVar('gperm_itemid', $this->_mXoopsModule->getVar('mid')); $perm->setVar('gperm_modid', 1); return $perm; @@ -164,46 +169,30 @@ /** * @static */ - function _installTemplate(&$module, &$log) + function _installTemplates() { - Legacy_ModuleUtils::installAllModuleTemplates($module, $log); + Legacy_ModuleInstallUtils::installAllOfModuleTemplates($this->_mXoopsModule, $this->mLog); } - function _installBlock() + function _installBlocks() { - $definedBlocks = $this->mModule->getInfo('blocks'); - if($definedBlocks == false) - return true; - - $blockHandler =& xoops_gethandler('block'); - - $func_num=0; - foreach ($definedBlocks as $block) { - $func_num++; - $newBlock =& Legacy_ModuleUtils::createBlockByInfo($this->mModule, $block, $func_num); - - Legacy_ModuleUtils::installBlock($this->mModule, $newBlock, $block, $this->mLog); - } + Legacy_ModuleInstallUtils::installAllOfBlocks($this->_mXoopsModule, $this->mLog); } - function _installNotification() - { - } - - function _installPreference() + function _installPreferences() { - Legacy_ModuleUtils::insertAllConfigs($this->mModule, $this->mLog); + Legacy_ModuleInstallUtils::installAllOfConfigs($this->_mXoopsModule, $this->mLog); } - function _processScript(&$module, &$log) + function _processScript() { - $installScript = trim($module->getInfo('onInstall')); + $installScript = trim($this->_mXoopsModule->getInfo('onInstall')); if ($installScript != false) { - require_once XOOPS_MODULE_PATH . "/" . $module->getVar('dirname') . "/" . $installScript; - $funcName = 'xoops_module_install_' . $module->getVar('dirname'); + require_once XOOPS_MODULE_PATH . "/" . $this->_mXoopsModule->get('dirname') . "/" . $installScript; + $funcName = 'xoops_module_install_' . $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)); + $this->mLog->addError(XCUbe_Utils::formatMessage(_AD_LEGACY_ERROR_FAILED_TO_EXECUTE_CALLBACK, $funcName)); } } } @@ -212,11 +201,11 @@ function _processReport() { if (!$this->mLog->hasError()) { - $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_INSTALLATION_MODULE_SUCCESSFUL, $this->mModule->get('name'))); + $this->mLog->add(XCube_Utils::formatMessage(_AD_LEGACY_MESSAGE_INSTALLATION_MODULE_SUCCESSFUL, $this->_mXoopsModule->get('name'))); } else { - if (is_object($this->mModule)) { - $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_INSTALLATION_MODULE_FAILURE, $this->mModule->get('name'))); + if (is_object($this->_mXoopsModule)) { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_INSTALLATION_MODULE_FAILURE, $this->_mXoopsModule->get('name'))); } else { $this->mLog->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_INSTALLATION_MODULE_FAILURE, $this->mDirname)); @@ -224,10 +213,47 @@ } } - function hasAgree() - { - return $this->mAgree; - } + /** + * @todo Check whether $this->_mXoopsObject is ready. + */ + function executeInstall() + { + $this->_installTables(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installModule(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installTemplates(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installBlocks(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_installPreferences(); + if (!$this->_mForceMode && $this->mLog->hasError()) { + $this->_processReport(); + return false; + } + + $this->_processScript(); + + $this->_processReport(); + + return true; + } } ?> \ No newline at end of file