Minahito
minah****@users*****
2006年 10月 27日 (金) 20:45:38 JST
Index: xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php diff -u xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php:1.1.2.4 xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php:1.1.2.5 --- xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php:1.1.2.4 Thu Oct 26 00:27:37 2006 +++ xoops2jp/html/modules/legacy/admin/class/ModuleUpdater.class.php Fri Oct 27 20:45:38 2006 @@ -4,6 +4,172 @@ require_once XOOPS_LEGACY_PATH."/admin/class/AbstractModuleInstaller.class.php"; +/** + * This class is a framework for phased updating. + */ +class Legacy_ModulePhasedUpgrader +{ + var $mLog; + + /** + * @var XoopsModule + */ + var $_mCurrentXoopsModule; + + /** + * @var int + */ + var $_mCurrentVersion; + + /** + * @var XoopsModule + */ + var $_mTargetXoopsModule; + + /** + * @var int + */ + var $_mTargetVersion; + + var $_mMilestone = array(); + + function Legacy_ModulePhasedUpgrader() + { + $this->mLog =& new Legacy_ModuleUtilsSimpleLog(); + } + + /** + * Sets the current XoopsModule. This method creates the clone of this + * object to prevent cache of the module handler, and then keep it to the + * property. Plus, this method copies the version value of this object to + * the _mCurrentVersion as backup for the case where the value of this + * object is changed for updating. + * + * @param XoopsModule $xoopsModule + */ + function setCurrentXoopsModule(&$xoopsModule) + { + $handler =& xoops_gethandler('module'); + $cloneModule =& $handler->create(); + + $cloneModule->set('mid', $xoopsModule->get('mid')); + $cloneModule->set('name', $xoopsModule->get('name')); + $cloneModule->set('version', $xoopsModule->get('version')); + $cloneModule->set('last_update', $xoopsModule->get('last_update')); + $cloneModule->set('weight', $xoopsModule->get('weight')); + $cloneModule->set('isactive', $xoopsModule->get('isactive')); + $cloneModule->set('dirname', $xoopsModule->get('dirname')); + $cloneModule->set('hasmain', $xoopsModule->get('hasmain')); + $cloneModule->set('hasadmin', $xoopsModule->get('hasadmin')); + $cloneModule->set('hassearch', $xoopsModule->get('hassearch')); + $cloneModule->set('hasconfig', $xoopsModule->get('hasconfig')); + $cloneModule->set('hascomments', $xoopsModule->get('hascomments')); + $cloneModule->set('hasnotification', $xoopsModule->get('hasnotification')); + + $this->_mCurrentXoopsModule =& $cloneModule; + } + + /** + * Sets the target XoopsModule. + */ + function setTargetXoopsModule(&$xoopsModule) + { + $this->_mTargetXoopsModule =& $xoopsModule; + $this->_mTargetVersion = $this->getTargetPhase(); + } + + function doUpdate() + { + if ($this->hasUpgradeMethod()) { + $this->_callUpgradeMethod(); + } + else { + $this->executeAutomaticUpgrade(); + } + } + + function executeAutomaticUpgrade() + { + die('MADADAYO! --- This is not implemeted yet!'); + } + + /** + * Saves the current XoopsModule object to DB. + */ + function saveXoopsModule() + { + $handler =& xoops_gethandler('module'); + if ($handler->insert($this->_mCurrentXoopsModule)) { + $this->mLog->addReport("XoopsModule is updated."); + } + else { + $this->mLog->addError("*Could not install module information*"); + } + } + + /** + * Gets the target varsion number at this time. In the case where there are + * milestones, gets the nearest value from the current version. + * + * Of course, this class is good to override by the sub-class. + */ + function getTargetPhase() + { + ksort($this->_mMilestone); + + foreach ($this->_mMilestone as $t_version => $t_value) { + if ($t_version > $this->_mCurrentVersion) { + return $t_version; + } + } + + return $this->_mTargetXoopsModule->get('version'); + } + + /** + * Gets the valude indicating whether this class + */ + function hasUpgradeMethod() + { + ksort($this->_mMilestone); + + foreach ($this->_mMilestone as $t_version => $t_value) { + if ($t_version > $this->_mCurrentVersion) { + if (is_callable(array($this, $t_value))) { + return true; + } + } + } + + return false; + } + + /** + * Dispatches the callback upgrade program. + * + * @access protected + * @return bool The value indicating whether this method can call the + * upgrade-method. + */ + function _callUpgradeMethod() + { + ksort($this->_mMilestone); + + foreach ($this->_mMilestone as $t_version => $t_value) { + if ($t_version > $this->_mCurrentVersion) { + if (is_callable(array($this, $t_value))) { + $this->$t_value(); + return true; + } + } + } + + return false; + } + +} + + class Legacy_ModuleUpdater extends Legacy_AbstractModuleInstaller { var $mPreVersion = 0;