Minahito
minah****@users*****
2006年 11月 15日 (水) 18:11:08 JST
Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php diff -u xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php:1.1.2.2 xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php:1.1.2.3 --- xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php:1.1.2.2 Wed Nov 15 15:17:50 2006 +++ xoops2jp/html/modules/legacy/admin/class/ModuleInstallInformation.class.php Wed Nov 15 18:11:08 2006 @@ -5,10 +5,10 @@ * @version $Id$ */ -define('LEGACY_BLOCKINFOMATION_STATUS_LOADED', "loaded"); -define('LEGACY_BLOCKINFOMATION_STATUS_UPDATED', "updated"); -define('LEGACY_BLOCKINFOMATION_STATUS_NEW', "new"); -define('LEGACY_BLOCKINFOMATION_STATUS_DELETED', "deleted"); +define('LEGACY_INSTALLINFO_STATUS_LOADED', "loaded"); +define('LEGACY_INSTALLINFO_STATUS_UPDATED', "updated"); +define('LEGACY_INSTALLINFO_STATUS_NEW', "new"); +define('LEGACY_INSTALLINFO_STATUS_DELETED', "deleted"); /** * The structure which is able to keep block's informations without DB. This @@ -16,7 +16,7 @@ */ class Legacy_BlockInformation { - var $mStatus = LEGACY_BLOCKINFOMATION_STATUS_LOADED; + var $mStatus = LEGACY_INSTALLINFO_STATUS_LOADED; var $mFuncNum = 0; @@ -74,7 +74,7 @@ function update(&$block) { - $this->mStatus = LEGACY_BLOCKINFOMATION_STATUS_UPDATED; + $this->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED; $this->mName = $block->mName; $this->mFuncFile = $block->mFuncFile; @@ -128,9 +128,9 @@ $t_block =& $collection->get($this->mBlocks[$idx]->mFuncNum); if ($t_block == null) { if (!$collection->funcExists($this->mBlocks[$idx])) { - $this->mBlocks[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; + $this->mBlocks[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; } else { - $this->mBlocks[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_UPDATED; // No Action. + $this->mBlocks[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED; // No Action. } } elseif (!$this->mBlocks[$idx]->isEqual($t_block)) { @@ -142,7 +142,7 @@ $func_num = $collection->mBlocks[$idx]->mFuncNum; if (!isset($this->mBlocks[$func_num])) { $this->add($collection->mBlocks[$idx]); - $this->mBlocks[$func_num]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_NEW; + $this->mBlocks[$func_num]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; } } } @@ -160,7 +160,7 @@ */ class Legacy_PreferenceInformation { - var $mStatus = LEGACY_BLOCKINFOMATION_STATUS_LOADED; + var $mStatus = LEGACY_INSTALLINFO_STATUS_LOADED; var $mOrder = 0; @@ -178,15 +178,15 @@ var $mOption = null; - function Legacy_PreferenceInformation($order, $name, $title, $description, $formType, $valueType, $default) + function Legacy_PreferenceInformation($name, $title, $description, $formType, $valueType, $default, $order = 0) { - $this->mOrder = intval($order); $this->mName = $name; $this->mTitle = $title; $this->mDescription = $description; $this->mFormType = $formType; $this->mValueType = $valueType; $this->mDefault = $default; + $this->mOrder = intval($order); $this->mOption =& new Legacy_PreferenceOptionInfoCollection(); } @@ -196,10 +196,6 @@ */ function isEqual(&$preference) { - if ($this->mOrder != $preference->mOrder) { - return false; - } - if ($this->mName != $preference->mName) { return false; } @@ -229,7 +225,7 @@ function update(&$preference) { - $this->mStatus = LEGACY_BLOCKINFOMATION_STATUS_UPDATED; + $this->mStatus = LEGACY_INSTALLINFO_STATUS_UPDATED; $this->mName = $preference->mName; $this->mTitle = $preference->mTitle; @@ -258,78 +254,59 @@ function add(&$preference) { if ($preference->mName == 'com_rule' || $preference->mName == 'com_anonpost') { - if (isset($this->mComments[$preference->mOrder])) { + if (isset($this->mComments[$preference->mName])) { return false; } - $this->mComments[$preference->mOrder] =& $preference; + $this->mComments[$preference->mName] =& $preference; $this->_sort(); return true; } if ($preference->mName == 'notification_enabled' || $preference->mName == 'notification_events') { - if (isset($this->mNotifications[$preference->mOrder])) { + if (isset($this->mNotifications[$preference->mName])) { return false; } - $this->mNotifications[$preference->mOrder] =& $preference; + $this->mNotifications[$preference->mName] =& $preference; $this->_sort(); return true; } - if (isset($this->mPreferences[$preference->mOrder])) { + if (isset($this->mPreferences[$preference->mName])) { return false; } - $this->mPreferences[$preference->mOrder] =& $preference; + $this->mPreferences[$preference->mName] =& $preference; $this->_sort(); return true; } + /** + * @private + * Renumbers orders of preferences. + */ function _sort() { - $maxOrder = 0; + $currentOrder = 0; foreach (array_keys($this->mPreferences) as $idx) { - if ($this->mPreferences[$idx]->mOrder > $maxOrder) { - $maxOrder = $this->mPreferences[$idx]->mOrder; - } + $this->mPreferences[$idx]->mOrder = $currentOrder++; } - $maxOrder++; - - $t_comments = array(); foreach (array_keys($this->mComments) as $idx) { - if ($this->mComments[$idx]->mOrder != $maxOrder) { - $this->mComments[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_UPDATED; - $this->mComments[$idx]->mOrder = $maxOrder; - } - $t_comments[$maxOrder++] =& $this->mComments[$idx]; + $this->mComments[$idx]->mOrder = $currentOrder++; } - unset($this->mComments); - $this->mComments =& $t_comments; - - // - // Sort notifications - // - $t_notifications = array(); foreach (array_keys($this->mNotifications) as $idx) { - if ($this->mNotifications[$idx]->mOrder != $maxOrder) { - $this->mNotifications[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_UPDATED; - $this->mNotifications[$idx]->mOrder = $maxOrder; - } - $t_notifications[$maxOrder++] =& $this->mNotifications[$idx]; + $this->mNotifications[$idx]->mOrder = $currentOrder++; } - - unset($this->mNotifications); - $this->mNotifications =& $t_notifications; } - function &get($order) + function &get($name) { $ret = null; - if (isset($this->mPreferences[$order])) { - return $this->mPreferences[$order]; + if (isset($this->mPreferences[$name])) { + return $this->mPreferences[$name]; } return $ret; @@ -346,9 +323,9 @@ // Preferences // foreach (array_keys($this->mPreferences) as $idx) { - $t_preference =& $collection->get($this->mPreferences[$idx]->mOrder); + $t_preference =& $collection->get($this->mPreferences[$idx]->mName); if ($t_preference == null) { - $this->mPreferences[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; + $this->mPreferences[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; } elseif (!$this->mPreferences[$idx]->isEqual($t_preference)) { $this->mPreferences[$idx]->update($t_preference); @@ -356,10 +333,10 @@ } foreach (array_keys($collection->mPreferences) as $idx) { - $order = $collection->mPreferences[$idx]->mOrder; - if (!isset($this->mPreferences[$order])) { - $this->add($collection->mPreferences[$idx]); - $this->mPreferences[$order]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_NEW; + $name = $collection->mPreferences[$idx]->mName; + if (!isset($this->mPreferences[$name])) { + $this->add($collection->mPreferences[$name]); + $this->mPreferences[$name]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; } } @@ -368,13 +345,13 @@ // if (count($this->mComments) > 0 && count($collection->mComments) == 0) { foreach (array_keys($this->mComments) as $idx) { - $this->mComments[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; + $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; } } elseif (count($this->mComments) == 0 && count($collection->mComments) > 0) { $this->mComments =& $collection->mComments; foreach (array_keys($this->mComments) as $idx) { - $this->mComments[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_NEW; + $this->mComments[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; } } @@ -383,13 +360,13 @@ // if (count($this->mNotifications) > 0 && count($collection->mNotifications) == 0) { foreach (array_keys($this->mNotifications) as $idx) { - $this->mNotifications[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; + $this->mNotifications[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_DELETED; } } elseif (count($this->mNotifications) == 0 && count($collection->mNotifications) > 0) { $this->mNotifications =& $collection->mNotifications; foreach (array_keys($this->mNotifications) as $idx) { - $this->mNotifications[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_NEW; + $this->mNotifications[$idx]->mStatus = LEGACY_INSTALLINFO_STATUS_NEW; } } } @@ -589,10 +566,10 @@ return $collection; } - function &_createPreferenceInformation($order, $arr) + function &_createPreferenceInformation($arr) { $arr['description'] = isset($arr['description']) ? $arr['description'] : null; - $info =& new Legacy_PreferenceInformation($order, $arr['name'], $arr['title'], $arr['description'], $arr['formtype'], $arr['valuetype'], $arr['default']); + $info =& new Legacy_PreferenceInformation($arr['name'], $arr['title'], $arr['description'], $arr['formtype'], $arr['valuetype'], $arr['default']); if (isset($arr['options'])) { foreach ($arr['options'] as $name => $value) { $option =& new Legacy_PreferenceOptionInformation($name, $value); @@ -616,10 +593,8 @@ 'default' => 1, 'options' => array('_CM_COMNOCOM' => XOOPS_COMMENT_APPROVENONE, '_CM_COMAPPROVEALL' => XOOPS_COMMENT_APPROVEALL, '_CM_COMAPPROVEUSER' => XOOPS_COMMENT_APPROVEUSER, '_CM_COMAPPROVEADMIN' => XOOPS_COMMENT_APPROVEADMIN) ); - $info =& $this->_createPreferenceInformation(0, $comRule); - while (!$collection->add($info)) { - $info->mOrder++; - } + $info =& $this->_createPreferenceInformation($comRule); + $collection->add($info); unset($info); $comAnonpost = array('name' => 'com_anonpost', @@ -629,10 +604,8 @@ 'valuetype' => 'int', 'default' => 0 ); - $info =& $this->_createPreferenceInformation(1, $comAnonpost); - while (!$collection->add($info)) { - $info->mOrder++; - } + $info =& $this->_createPreferenceInformation($comAnonpost); + $collection->add($info); unset($info); } } @@ -658,10 +631,8 @@ 'default' => XOOPS_NOTIFICATION_ENABLEBOTH, 'options' => $t_options ); - $info =& $this->_createPreferenceInformation(0, $notifyEnable); - while (!$collection->add($info)) { - $info->mOrder++; - } + $info =& $this->_createPreferenceInformation($notifyEnable); + $collection->add($info); unset($info); // @@ -699,10 +670,8 @@ 'default' => array_values($t_options), 'options' => $t_options ); - $info =& $this->_createPreferenceInformation(1, $notifyEvents); - while (!$collection->add($info)) { - $info->mOrder++; - } + $info =& $this->_createPreferenceInformation($notifyEvents); + $collection->add($info); unset($info); } } @@ -730,13 +699,13 @@ $preferenceArr = $modversion['config']; // - // Try (1) --- index pattern + // Try (1) --- name index pattern // - $successFlag = true; foreach ($preferenceArr as $idx => $preference) { - if (is_int($idx)) { - $info =& $this->_createPreferenceInformation($idx, $preference); + if (is_string($idx)) { + $preference['name'] = $idx; + $info =& $this->_createPreferenceInformation($preference); $successFlag &= $collection->add($info); unset($info); } @@ -746,15 +715,14 @@ } } + // + // Try (2) --- auto number + // if (!$successFlag) { - // - // Try (2) --- automatic - // $collection->reset(); - $idx = 1; foreach ($preferenceArr as $preference) { - $info =& $this->_createPreferenceInformation($idx++, $preference); + $info =& $this->_createPreferenceInformation($preference); $collection->add($info); unset($info); } @@ -808,7 +776,7 @@ function &_createPreferenceInformation(&$config) { - $info =& new Legacy_PreferenceInformation($config->get('conf_order'), $config->get('conf_name'), $config->get('conf_title'), $config->get('conf_desc'), $config->get('conf_formtype'), $config->get('conf_valuetype'), $config->get('conf_value')); + $info =& new Legacy_PreferenceInformation($config->get('conf_name'), $config->get('conf_title'), $config->get('conf_desc'), $config->get('conf_formtype'), $config->get('conf_valuetype'), $config->get('conf_value')); $configOptionArr =& $config->getOptionItems(); @@ -829,13 +797,13 @@ $module =& $handler->getByDirname($this->_mDirname); $handler =& xoops_gethandler('config'); - $configArr =& $handler->getConfigs(new Criteria('conf_modid', $module->get('mid'))); + $criteria =& new Criteria('conf_modid', $module->get('mid')); + $criteria->setOrder('conf_order'); + $configArr =& $handler->getConfigs($criteria); foreach (array_keys($configArr) as $idx) { $info =& $this->_createPreferenceInformation($configArr[$idx]); - while (!$collection->add($info)) { - $info->mOrder++; - } + $collection->add($info); } return $collection; Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php diff -u xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.12 xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.13 --- xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.12 Wed Nov 15 00:39:30 2006 +++ xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php Wed Nov 15 18:11:08 2006 @@ -847,19 +847,19 @@ foreach (array_keys($currentBlocks->mBlocks) as $idx) { switch ($currentBlocks->mBlocks[$idx]->mStatus) { - case LEGACY_BLOCKINFOMATION_STATUS_LOADED: + case LEGACY_INSTALLINFO_STATUS_LOADED: Legacy_ModuleInstallUtils::updateBlockTemplateByInfo($currentBlocks->mBlocks[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_UPDATED: + case LEGACY_INSTALLINFO_STATUS_UPDATED: Legacy_ModuleInstallUtils::updateBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_NEW: + case LEGACY_INSTALLINFO_STATUS_NEW: Legacy_ModuleInstallUtils::installBlockByInfo($currentBlocks->mBlocks[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_DELETED: + case LEGACY_INSTALLINFO_STATUS_DELETED: Legacy_ModuleInstallUtils::uninstallBlockByFuncNum($currentBlocks->mBlocks[$idx]->mFuncNum, $module, $log); break; } @@ -883,18 +883,19 @@ // foreach (array_keys($currentPreferences->mPreferences) as $idx) { switch ($currentPreferences->mPreferences[$idx]->mStatus) { - case LEGACY_BLOCKINFOMATION_STATUS_LOADED: + case LEGACY_INSTALLINFO_STATUS_LOADED: + Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mPreferences[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_UPDATED: + case LEGACY_INSTALLINFO_STATUS_UPDATED: Legacy_ModuleInstallUtils::updatePreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_NEW: + case LEGACY_INSTALLINFO_STATUS_NEW: Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mPreferences[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_DELETED: + case LEGACY_INSTALLINFO_STATUS_DELETED: Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mPreferences[$idx]->mOrder, $module, $log); break; } @@ -905,18 +906,16 @@ // foreach (array_keys($currentPreferences->mComments) as $idx) { switch ($currentPreferences->mComments[$idx]->mStatus) { - case LEGACY_BLOCKINFOMATION_STATUS_LOADED: - break; - - case LEGACY_BLOCKINFOMATION_STATUS_UPDATED: + case LEGACY_INSTALLINFO_STATUS_LOADED: + case LEGACY_INSTALLINFO_STATUS_UPDATED: Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mComments[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_NEW: + case LEGACY_INSTALLINFO_STATUS_NEW: Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mComments[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_DELETED: + case LEGACY_INSTALLINFO_STATUS_DELETED: Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mComments[$idx]->mOrder, $module, $log); break; } @@ -927,18 +926,18 @@ // foreach (array_keys($currentPreferences->mNotifications) as $idx) { switch ($currentPreferences->mNotifications[$idx]->mStatus) { - case LEGACY_BLOCKINFOMATION_STATUS_LOADED: + case LEGACY_INSTALLINFO_STATUS_LOADED: break; - case LEGACY_BLOCKINFOMATION_STATUS_UPDATED: + case LEGACY_INSTALLINFO_STATUS_UPDATED: Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mNotifications[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_NEW: + case LEGACY_INSTALLINFO_STATUS_NEW: Legacy_ModuleInstallUtils::installPreferenceByInfo($currentPreferences->mNotifications[$idx], $module, $log); break; - case LEGACY_BLOCKINFOMATION_STATUS_DELETED: + case LEGACY_INSTALLINFO_STATUS_DELETED: Legacy_ModuleInstallUtils::uninstallPreferenceByOrder($currentPreferences->mNotifications[$idx]->mOrder, $module, $log); break; } @@ -996,7 +995,7 @@ $criteria =& new CriteriaCompo(); $criteria->add(new Criteria('conf_modid', $module->get('mid'))); $criteria->add(new Criteria('conf_catid', 0)); - $criteria->add(new Criteria('conf_order', $info->mOrder)); + $criteria->add(new Criteria('conf_name', $info->mName)); $configArr =& $handler->getConfigs($criteria); @@ -1006,12 +1005,23 @@ $config =& $configArr[0]; - $config->set('conf_name', $info->mName); $config->set('conf_title', $info->mTitle); $config->set('conf_desc', $info->mDescription); - $config->set('conf_formtype', $info->mFormType); - $config->set('conf_valuetype', $info->mValueType); - $config->setConfValueForInput($info->mDefault); + + // + // Decide whether it changes values. + // + if ($config->get('conf_formtype') != $info->mFormType && $config->get('conf_valuetype') != $info->mValueType) { + $config->set('conf_formtype', $info->mFormType); + $config->set('conf_valuetype', $info->mValueType); + $config->setConfValueForInput($info->mDefault); + } + else { + $config->set('conf_formtype', $info->mFormType); + $config->set('conf_valuetype', $info->mValueType); + } + + $config->set('conf_order', $info->mOrder); $optionArr =& $handler->getConfigOptions(new Criteria('conf_id', $config->get('conf_id'))); if (is_array($optionArr)) { @@ -1046,11 +1056,11 @@ $criteria =& new CriteriaCompo(); $criteria->add(new Criteria('conf_modid', $module->get('mid'))); $criteria->add(new Criteria('conf_catid', 0)); - $criteria->add(new Criteria('conf_order', $info->mOrder)); + $criteria->add(new Criteria('conf_name', $info->mName)); $configArr =& $handler->getConfigs($criteria); - if (count($configArr) > 0 && !is_object($configArr[0])) { + if (!(count($configArr) > 0 && is_object($configArr[0]))) { $log->addError('Execption Error: Could not find config.'); } @@ -1058,11 +1068,8 @@ $config->set('conf_order', $info->mOrder); - if ($handler->insertConfig($config)) { - $log->addReport(XCube_Utils::formatMessage("Preference '{0}' is updateded.", $config->get('conf_name'))); - } - else { - $log->addError(XCube_Utils::formatMessage("Could not update preference '{0}'.", $config->get('conf_name'))); + if (!$handler->insertConfig($config)) { + $log->addError(XCube_Utils::formatMessage("Could not update the order of preference '{0}'.", $config->get('conf_name'))); } }