Minahito
minah****@users*****
2006年 11月 15日 (水) 00:39:30 JST
Index: xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php diff -u xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php:1.1.2.11 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.11 Tue Nov 14 20:53:23 2006 +++ xoops2jp/html/modules/legacy/admin/class/ModuleInstallUtils.class.php Wed Nov 15 00:39:30 2006 @@ -2,6 +2,7 @@ if (!defined('XOOPS_ROOT_PATH')) exit(); +require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallInformation.class.php"; require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstaller.class.php"; require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUpdater.class.php"; require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUninstaller.class.php"; @@ -662,26 +663,30 @@ function installAllOfConfigs(&$module, &$log) { - $configInfos = Legacy_ModuleInstallUtils::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_LEGACY_MESSAGE_INSERT_CONFIG, $configInfo['name'])); - } - else { - $log->addError(XCube_Utils::formatMessage(_AD_LEGACY_ERROR_COULD_NOT_INSERT_CONFIG, $configInfo['name'])); - } - - unset($config); - } + $dirname = $module->get('dirname'); + + $fileReader =& new Legacy_ModinfoX2FileReader($dirname); + $preferences =& $fileReader->loadPreferenceInformations(); + + // + // Preferences + // + foreach (array_keys($preferences->mPreferences) as $idx) { + Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mPreferences[$idx], $module, $log); + } + + // + // Comments + // + foreach (array_keys($preferences->mComments) as $idx) { + Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mComments[$idx], $module, $log); + } + + // + // Notifications + // + foreach (array_keys($preferences->mNotifications) as $idx) { + Legacy_ModuleInstallUtils::installPreferenceByInfo($preferences->mNotifications[$idx], $module, $log); } } @@ -701,7 +706,7 @@ if (count($info->mOption->mOptions) > 0) { foreach (array_keys($info->mOption->mOptions) as $idx) { - $option =& $handler->createOption(); + $option =& $handler->createConfigOption(); $option->set('confop_name', $info->mOption->mOptions[$idx]->mName); $option->set('confop_value', $info->mOption->mOptions[$idx]->mValue); $config->setConfOptions($option); @@ -904,7 +909,7 @@ break; case LEGACY_BLOCKINFOMATION_STATUS_UPDATED: - Legacy_ModuleInstallUtils::updateCommentByInfo($currentPreferences->mComments[$idx], $module, $log); + Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mComments[$idx], $module, $log); break; case LEGACY_BLOCKINFOMATION_STATUS_NEW: @@ -926,7 +931,7 @@ break; case LEGACY_BLOCKINFOMATION_STATUS_UPDATED: - Legacy_ModuleInstallUtils::updateCommentByInfo($currentPreferences->mNotifications[$idx], $module, $log); + Legacy_ModuleInstallUtils::updatePreferenceOrderByInfo($currentPreferences->mNotifications[$idx], $module, $log); break; case LEGACY_BLOCKINFOMATION_STATUS_NEW: @@ -1034,7 +1039,7 @@ } } - function updateCommentByInfo(&$info, &$module, &$log) + function updatePreferenceOrderByInfo(&$info, &$module, &$log) { $handler =& xoops_gethandler('config'); @@ -1045,7 +1050,7 @@ $configArr =& $handler->getConfigs($criteria); - if (count($configArr) == 0) { + if (count($configArr) > 0 && !is_object($configArr[0])) { $log->addError('Execption Error: Could not find config.'); } @@ -1194,708 +1199,4 @@ } } -define('LEGACY_BLOCKINFOMATION_STATUS_LOADED', "loaded"); -define('LEGACY_BLOCKINFOMATION_STATUS_UPDATED', "updated"); -define('LEGACY_BLOCKINFOMATION_STATUS_NEW', "new"); -define('LEGACY_BLOCKINFOMATION_STATUS_DELETED', "deleted"); - -/** - * The structure which is able to keep block's informations without DB. This - * is installer only. - */ -class Legacy_BlockInformation -{ - var $mStatus = LEGACY_BLOCKINFOMATION_STATUS_LOADED; - - var $mFuncNum = 0; - - var $mName = ""; - - var $mOptions = ""; - - var $mFuncFile = ""; - var $mShowFunc = ""; - var $mEditFunc = ""; - var $mTemplate = ""; - - function Legacy_BlockInformation($funcNum, $name, $funcFile, $showFunc, $editFunc, $template, $options = null) - { - $this->mFuncNum = intval($funcNum); - $this->mName = $name; - $this->mFuncFile = $funcFile; - $this->mShowFunc = $showFunc; - $this->mEditFunc = $editFunc; - $this->mTemplate = $template; - $this->mOptions = $options; - } - - /** - * @return bool - */ - function isEqual(&$block) - { - if ($this->mFuncNum != $block->mFuncNum) { - return false; - } - - if ($this->mName != $block->mName) { - return false; - } - - if ($this->mFuncFile != $block->mFuncFile) { - return false; - } - - if ($this->mShowFunc != $block->mShowFunc) { - return false; - } - - if ($this->mEditFunc != $block->mEditFunc) { - return false; - } - - if ($this->mTemplate != $block->mTemplate) { - return false; - } - - return true; - } - - function update(&$block) - { - $this->mStatus = LEGACY_BLOCKINFOMATION_STATUS_UPDATED; - - $this->mName = $block->mName; - $this->mFuncFile = $block->mFuncFile; - $this->mShowFunc = $block->mShowFunc; - $this->mEditFunc = $block->mEditFunc; - $this->mTemplate = $block->mTemplate; - } -} - -class Legacy_BlockInfoCollection -{ - var $mBlocks = array(); - - function add(&$info) - { - if (isset($this->mBlocks[$info->mFuncNum])) { - return false; - } - - $this->mBlocks[$info->mFuncNum] =& $info; - - ksort($this->mBlocks); - - return true; - } - - function &get($funcNum) - { - if (isset($this->mBlocks[$funcNum])) { - return $this->mBlocks[$funcNum]; - } - - $ret = null; - return $ret; - } - - /** - * Updates the list of blocks by comparing with $collection. - */ - function update(&$collection) - { - foreach (array_keys($this->mBlocks) as $idx) { - $t_block =& $collection->get($this->mBlocks[$idx]->mFuncNum); - if ($t_block == null) { - $this->mBlocks[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; - } - elseif (!$this->mBlocks[$idx]->isEqual($t_block)) { - $this->mBlocks[$idx]->update($t_block); - } - } - - foreach (array_keys($collection->mBlocks) as $idx) { - $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; - } - } - } - - function reset() - { - unset($this->mBlocks); - $this->mBlocks = array(); - } -} - -/** - * The structure which is able to keep preference's informations without DB. - * This is installer only. - */ -class Legacy_PreferenceInformation -{ - var $mStatus = LEGACY_BLOCKINFOMATION_STATUS_LOADED; - - var $mOrder = 0; - - var $mName = ""; - - var $mTitle = ""; - - var $mDescription = ""; - - var $mFormType = ""; - - var $mValueType = ""; - - var $mDefault = null; - - var $mOption = null; - - function Legacy_PreferenceInformation($order, $name, $title, $description, $formType, $valueType, $default) - { - $this->mOrder = intval($order); - $this->mName = $name; - $this->mTitle = $title; - $this->mDescription = $description; - $this->mFormType = $formType; - $this->mValueType = $valueType; - $this->mDefault = $default; - - $this->mOption =& new Legacy_PreferenceOptionInfoCollection(); - } - - /** - * @return bool - */ - function isEqual(&$preference) - { - if ($this->mOrder != $preference->mOrder) { - return false; - } - - if ($this->mName != $preference->mName) { - return false; - } - - if ($this->mTitle != $preference->mTitle) { - return false; - } - - if ($this->mDescription != $preference->mDescription) { - return false; - } - - if ($this->mFormType != $preference->mFormType) { - return false; - } - - if ($this->mValueType != $preference->mValueType) { - return false; - } - - if (!$this->mOption->isEqual($preference->mOption)) { - return false; - } - - return true; - } - - function update(&$preference) - { - $this->mStatus = LEGACY_BLOCKINFOMATION_STATUS_UPDATED; - - $this->mName = $preference->mName; - $this->mTitle = $preference->mTitle; - $this->mDescription = $preference->mDescription; - $this->mFormType = $preference->mFormType; - $this->mValueType = $preference->mValueType; - $this->mDefault = $preference->mDefault; - - unset($this->mOption); - $this->mOption =& $preference->mOption; - } -} - -class Legacy_PreferenceInfoCollection -{ - var $mPreferences = array(); - - var $mComments = array(); - - var $mNotifications = array(); - - function Legacy_PreferenceInfoCollection() - { - } - - function add(&$preference) - { - if ($preference->mName == 'com_rule' || $preference->mName == 'com_anonpost') { - $this->mComments[$preference->mOrder] =& $preference; - $this->_sort(); - return true; - } - - if ($preference->mName == 'notification_enabled' || $preference->mName == 'notification_events') { - $this->mNotifications[$preference->mOrder] =& $preference; - $this->_sort(); - return true; - } - - if (isset($this->mPreferences[$preference->mOrder])) { - return false; - } - - $this->mPreferences[$preference->mOrder] =& $preference; - $this->_sort(); - - return true; - } - - function _sort() - { - $maxOrder = 0; - foreach (array_keys($this->mPreferences) as $idx) { - if ($this->mPreferences[$idx]->mOrder > $maxOrder) { - $maxOrder = $this->mPreferences[$idx]->mOrder; - } - } - - $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]; - } - - 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]; - } - - unset($this->mNotifications); - $this->mNotifications =& $t_notifications; - } - - function &get($order) - { - $ret = null; - - if (isset($this->mPreferences[$order])) { - return $this->mPreferences[$order]; - } - - return $ret; - } - - /** - * Updates the list of blocks by comparing with $collection. - * @todo need delete comments' data - * @todo need delete notifications' data - */ - function update(&$collection) - { - // - // Preferences - // - foreach (array_keys($this->mPreferences) as $idx) { - $t_preference =& $collection->get($this->mPreferences[$idx]->mOrder); - if ($t_preference == null) { - $this->mPreferences[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; - } - elseif (!$this->mPreferences[$idx]->isEqual($t_preference)) { - $this->mPreferences[$idx]->update($t_preference); - } - } - - 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; - } - } - - // - // Comments - // - if (count($this->mComments) > 0 && count($collection->mComments) == 0) { - foreach (array_keys($this->mComments) as $idx) { - $this->mComments[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; - } - } - elseif (count($this->mComments) == 0 && count($collection->mComments) > 0) { - $this->mComments =& $collection->mComments; - } - - // - // Notifications - // - if (count($this->mNotifications) > 0 && count($collection->mNotifications) == 0) { - foreach (array_keys($this->mNotifications) as $idx) { - $this->mNotifications[$idx]->mStatus = LEGACY_BLOCKINFOMATION_STATUS_DELETED; - } - } - elseif (count($this->mNotifications) == 0 && count($collection->mNotifications) > 0) { - $this->mNotifications =& $collection->mNotifications; - } - } - - function reset() - { - unset($this->mPreferences); - $this->mPreferences = array(); - } -} - -class Legacy_PreferenceOptionInformation -{ - var $mName = ""; - var $mValue = ""; - - function Legacy_PreferenceOptionInformation($name, $value) - { - $this->mName = $name; - $this->mValue = $value; - } - - function isEqual($option) - { - return (($this->mName == $option->mName) && ($this->mValue == $option->mValue)); - } -} - -class Legacy_PreferenceOptionInfoCollection -{ - var $mOptions = array(); - - function Legacy_PreferenceOptionInfoCollection() - { - } - - function add(&$option) - { - $this->mOptions[] =& $option; - return true; - } - - function isEqual(&$collection) - { - if (count($this->mOptions) != count($collection->mOptions)) { - return false; - } - - foreach (array_keys($this->mOptions) as $idx) { - if (!$this->mOptions[$idx]->isEqual($collection->mOptions[$idx])) { - return false; - } - } - - return true; - } - - function reset() - { - unset($this->mOptions); - $this->mOptions = array(); - } -} - -class Legacy_AbstractModinfoReader -{ - function Legacy_AbstractModinfoReader() - { - } - - /** - * @return Legacy_BlockInfoCollection - */ - function &loadBlockInformations() - { - } - - /** - * @return Legacy_PreferenceInfoCollection - */ - function &loadPreferenceInformations() - { - } -} - -/** - * @note final class - */ -class Legacy_ModinfoX2FileReader extends Legacy_AbstractModinfoReader -{ - /** - * @protected - */ - var $_mDirname = null; - - function Legacy_ModinfoX2FileReader($dirname) - { - $this->_mDirname = $dirname; - } - - /** - * @private - */ - function &_createBlockInformation($funcNum, $arr) - { - $showFunc = ""; - if (isset($arr['class'])) { - $showFunc = 'cl::' . $arr['class']; - } - else { - $showFunc = $arr['show_func']; - } - - $editFunc = isset($arr['edit_func']) ? $arr['edit_func'] : null; - $template = isset($arr['template']) ? $arr['template'] : null; - $options = isset($arr['options']) ? $arr['options'] : null; - - $info =& new Legacy_BlockInformation($funcNum, $arr['name'], $arr['file'], $arr['show_func'], $editFunc, $template, $options); - - return $info; - } - - /** - * @todo Need guarantee of global variables. - */ - function &loadBlockInformations() - { - $collection =& new Legacy_BlockInfoCollection(); - - $t_filePath = XOOPS_ROOT_PATH . '/modules/' . $this->_mDirname . '/xoops_version.php'; - if (!file_exists($t_filePath)) { - return $collection; - } - - include $t_filePath; - - if (!isset($modversion['blocks'])) { - return $collection; - } - - $blockArr = $modversion['blocks']; - - // - // Try (1) --- func_num - // - $successFlag = true; - foreach ($blockArr as $idx => $block) { - if (isset($block['func_num'])) { - $info =& $this->_createBlockInformation($block['func_num'], $block); - $successFlag &= $collection->add($info); - unset($info); - } - else { - $successFlag = false; - break; - } - } - - if ($successFlag) { - return $collection; - } - - // - // Try (2) --- index pattern - // - $collection->reset(); - - $successFlag = true; - foreach ($blockArr as $idx => $block) { - if (is_int($idx)) { - $info =& $this->_createBlockInformation($idx, $block); - $successFlag &= $collection->add($info); - unset($info); - } - else { - $successFlag = false; - break; - } - } - - if ($successFlag) { - return $collection; - } - - // - // Try (3) --- automatic - // - $collection->reset(); - - $idx = 1; - foreach ($blockArr as $block) { - $info =& $this->_createBlockInformation($idx++, $block); - $successFlag &= $collection->add($info); - unset($info); - } - - return $collection; - } - - function &_createPreferenceInformation($order, $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']); - if (isset($arr['options'])) { - foreach ($arr['options'] as $name => $value) { - $option =& new Legacy_PreferenceOptionInformation($name, $value); - $info->mOption->add($option); - } - } - - return $info; - } - - /** - * @todo Need guarantee of global variables. - */ - function &loadPreferenceInformations() - { - $collection =& new Legacy_PreferenceInfoCollection(); - - $t_filePath = XOOPS_ROOT_PATH . '/modules/' . $this->_mDirname . '/xoops_version.php'; - if (!file_exists($t_filePath)) { - return $collection; - } - - include $t_filePath; - - if (!isset($modversion['config'])) { - return $collection; - } - - $preferenceArr = $modversion['config']; - - // - // Try (1) --- index pattern - // - - $successFlag = true; - foreach ($preferenceArr as $idx => $preference) { - if (is_int($idx)) { - $info =& $this->_createPreferenceInformation($idx, $preference); - $successFlag &= $collection->add($info); - unset($info); - } - else { - $successFlag = false; - break; - } - } - - if ($successFlag) { - return $collection; - } - - // - // Try (2) --- automatic - // - $collection->reset(); - - $idx = 1; - foreach ($preferenceArr as $preference) { - $info =& $this->_createPreferenceInformation($idx++, $preference); - $successFlag &= $collection->add($info); - unset($info); - } - - return $collection; - } -} - -class Legacy_ModinfoX2DBReader extends Legacy_AbstractModinfoReader -{ - /** - * @protected - */ - var $_mDirname = null; - - function Legacy_ModinfoX2DBReader($dirname) - { - $this->_mDirname = $dirname; - } - - function &_createBlockInformation(&$block) - { - $info =& new Legacy_BlockInformation($block->get('func_num'), $block->get('name'), $block->get('func_file'), $block->get('show_func'), $block->get('edit_func'), $block->get('template'), $block->get('options')); - return $info; - } - - function &loadBlockInformations() - { - $collection =& new Legacy_BlockInfoCollection(); - - $handler =& xoops_getmodulehandler('newblocks', 'legacy'); - $criteria =& new Criteria('dirname', $this->_mDirname); - $blockArr =& $handler->getObjects($criteria); - - foreach (array_keys($blockArr) as $idx) { - $info =& $this->_createBlockInformation($blockArr[$idx]); - while (!$collection->add($info)) { - $info->mFuncNum++; - } - } - - return $collection; - } - - 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')); - - $configOptionArr =& $config->getOptionItems(); - - foreach (array_keys($configOptionArr) as $idx) { - $option =& new Legacy_PreferenceOptionInformation($configOptionArr[$idx]->get('confop_name'), $configOptionArr[$idx]->get('confop_value')); - $info->mOption->add($option); - unset($option); - } - - return $info; - } - - function &loadPreferenceInformations() - { - $collection =& new Legacy_PreferenceInfoCollection(); - - $handler =& xoops_gethandler('module'); - $module =& $handler->getByDirname($this->_mDirname); - - $handler =& xoops_gethandler('config'); - $configArr =& $handler->getConfigs(new Criteria('conf_modid', $module->get('mid'))); - - foreach (array_keys($configArr) as $idx) { - $info =& $this->_createPreferenceInformation($configArr[$idx]); - while (!$collection->add($info)) { - $info->mOrder++; - } - } - - return $collection; - } -} - - ?> \ No newline at end of file