Minahito
minah****@users*****
2006年 9月 10日 (日) 14:55:19 JST
Index: xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php diff -u xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.22 xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.23 --- xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php:1.1.2.22 Mon Aug 21 18:59:02 2006 +++ xoops2jp/html/modules/base/admin/class/ModuleUtils.class.php Sun Sep 10 14:55:19 2006 @@ -8,6 +8,8 @@ define("MODINSTALL_LOGTYPE_WARNING", "warning"); define("MODINSTALL_LOGTYPE_ERROR", "error"); +define("MODINSTALL_THRESHOLD_ORDER", 255); + /** * A temporary log class. */ @@ -382,8 +384,38 @@ function insertAllConfigs(&$module, &$log) { - $configInfos = $module->getInfo('config'); + $configInfos = Legacy_ModuleUtils::getConfigInfosFromManifesto($module); + + $count = 0; + if (is_array($configInfos)) { + $configHandler =& xoops_gethandler('config'); + + foreach ($configInfos as $configInfo) { + $config =& $configHandler->createConfig(); + + $config->loadFromConfigInfo($module->get('mid'), $configInfo, $count++); + + if ($configHandler->insertConfig($config)) { + $log->addReport(XCube_Utils::formatMessage(_AD_BASE_MESSAGE_INSERT_CONFIG, $configInfo['name'])); + } + else { + $log->addError(XCube_Utils::formatMessage(_AD_BASE_ERROR_COULD_NOT_INSERT_CONFIG, $configInfo['name'])); + } + + unset($config); + } + } + } + /** + * Get & build config items from Manifesto by specific module object. + */ + function &getConfigInfosFromManifesto(&$module) + { + $configInfos = $module->getInfo('config'); + + $order = MODINSTALL_THRESHOLD_ORDER + 1; + // // Insert comment config by old style. // @@ -396,7 +428,8 @@ 'formtype' => 'select', 'valuetype' => 'int', 'default' => 1, - 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN) + 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN), + 'order' => $order++ ); $configInfos[] = array('name' => 'com_anonpost', @@ -404,14 +437,15 @@ 'description' => '', 'formtype' => 'yesno', 'valuetype' => 'int', - 'default' => 0 + 'default' => 0, + 'order' => $order++ ); } // // Insert comment config by old style. // - if ($this->mModule->get('hasnotification') != 0) { + if ($module->get('hasnotification') != 0) { require_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; require_once XOOPS_ROOT_PATH . '/include/notification_functions.php'; @@ -428,7 +462,8 @@ 'formtype' => 'select', 'valuetype' => 'int', 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, - 'options' => $t_options + 'options' => $t_options, + 'order' => $order++ ); // @@ -439,7 +474,7 @@ unset ($t_options); $t_options = array(); - $t_categoryArr =& notificationCategoryInfo('', $this->mModule->get('mid')); + $t_categoryArr =& notificationCategoryInfo('', $module->get('mid')); foreach ($t_categoryArr as $t_category) { $t_eventArr =& notificationEvents($t_category['name'], false, $module->get('mid')); foreach ($t_eventArr as $t_event) { @@ -457,51 +492,15 @@ 'formtype' => 'select_multi', 'valuetype' => 'array', 'default' => array_values($t_options), - 'options' => $t_options + 'options' => $t_options, + 'order' => $order++ ); } } - - $configHandler =& xoops_gethandler('config'); - - $count = 0; - if (is_array($configInfos)) { - foreach ($configInfos as $configInfo) { - $config =& $configHandler->createConfig(); - - $config->setVar('conf_modid', $module->getVar('mid')); - $config->setVar('conf_catid', 0); - $config->setVar('conf_name', $configInfo['name']); - $config->setVar('conf_title', $configInfo['title'], true); - if (isset($configInfo['description'])) { - $config->setVar('conf_desc', $configInfo['description'], true); - } - $config->setVar('conf_formtype', $configInfo['formtype'], true); - $config->setVar('conf_valuetype', $configInfo['valuetype'], true); - $config->setConfValueForInput($configInfo['default'], true); - $config->setVar('conf_order', $count++); - - if (isset($configInfo['options']) && is_array($configInfo['options'])) { - foreach ($configInfo['options'] as $key => $value) { - $configOption =& $configHandler->createConfigOption(); - $configOption->setVar('confop_name', $key, true); - $configOption->setVar('confop_value', $value, true); - $config->setConfOptions($configOption); - unset($configOption); - } - } - - if ($configHandler->insertConfig($config)) { - $log->addReport(XCube_Utils::formatMessage(_AD_BASE_MESSAGE_INSERT_CONFIG, $configInfo['name'])); - } - else { - $log->addError(XCube_Utils::formatMessage(_AD_BASE_ERROR_COULD_NOT_INSERT_CONFIG, $configInfo['name'])); - } - - unset($config); - } - } + + return $configInfos; } + /** * Delete all configs of $module. Index: xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php diff -u xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php:1.1.2.11 xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php:1.1.2.12 --- xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php:1.1.2.11 Mon Aug 21 18:59:02 2006 +++ xoops2jp/html/modules/base/admin/class/ModuleUpdater.class.php Sun Sep 10 14:55:19 2006 @@ -177,8 +177,83 @@ function _installPreference() { - Legacy_ModuleUtils::deleteAllConfigs($this->mModule, $this->mLog); - Legacy_ModuleUtils::insertAllConfigs($this->mModule, $this->mLog); + // Legacy_ModuleUtils::deleteAllConfigs($this->mModule, $this->mLog); + + $configHandler =& xoops_gethandler('config'); + + // + // At the start, load config items of this time. + // + $criteria =& new Criteria('conf_modid', $this->mModule->get('mid')); + $criteria =& new Criteria('conf_catid', 0); + + $activeConfigArr =& $configHandler->getConfigs($criteria); + + // + // Next, load config item from xoops_version.php. + // + $newConfigArr = array(); + $t_configInfoArr = Legacy_ModuleUtils::getConfigInfosFromManifesto($this->mModule); + + $count = 0; + if (is_array($t_configInfoArr)) { + foreach ($t_configInfoArr as $t_configInfo) { + $config =& $configHandler->createConfig(); + $config->loadFromConfigInfo($this->mModule->get('mid'), $t_configInfo, $count++); + $newConfigArr[] =& $config; + unset($config); + } + } + + // + // If some active configs were deleted, remove them form database. + // + foreach (array_keys($activeConfigArr) as $t_actkey) { + $keepFlag = false; + foreach (array_keys($newConfigArr) as $t_newkey) { + if ($activeConfigArr[$t_actkey]->isEqual($newConfigArr[$t_newkey])) { + $keepFlag = true; + break; + } + } + + if (!$keepFlag) { + $configHandler->deleteConfig($activeConfigArr[$t_actkey]); + unset($activeConfigArr[$t_actkey]); + } + } + + // + // If some new configs were registered, insert them into database. + // + $maxOrder = 0; + foreach (array_keys($activeConfigArr) as $t_actkey) { + if ($activeConfigArr[$t_actkey]->get('conf_order') > $maxOrder && $activeConfigArr[$t_actkey]->get('conf_order') <= MODINSTALL_THRESHOLD_ORDER) { + $maxOrder = $activeConfigArr[$t_actkey]->get('conf_order'); + } + } + + $order = $maxOrder + 1; + + foreach (array_keys($newConfigArr) as $t_newkey) { + $newFlag = true; + foreach (array_keys($activeConfigArr) as $t_actkey) { + if ($newConfigArr[$t_newkey]->isEqual($activeConfigArr[$t_actkey])) { + $newFlag = false; + break; + } + } + + if ($newFlag) { + $newConfigArr[$t_newkey]->set('conf_order', $order); + if ($configHandler->insertConfig($newConfigArr[$t_newkey])) { + $this->mLog->addReport(XCube_Utils::formatMessage(_AD_BASE_MESSAGE_INSERT_CONFIG, $newConfigArr[$t_newkey]->get('conf_name'))); + } + else { + $this->mLog->addError(XCube_Utils::formatMessage(_AD_BASE_ERROR_COULD_NOT_INSERT_CONFIG, $newConfigArr[$t_newkey]->get('conf_name'))); + } + } + } } function _processScript(&$module, &$log)