[xoops-cvslog 5516] CVS update: xoops2jp/html/modules/legacy/admin/actions

Back to archive index

Minahito minah****@users*****
2006年 10月 30日 (月) 18:52:32 JST


Index: xoops2jp/html/modules/legacy/admin/actions/ModuleUpdateAction.class.php
diff -u xoops2jp/html/modules/legacy/admin/actions/ModuleUpdateAction.class.php:1.1.2.4 xoops2jp/html/modules/legacy/admin/actions/ModuleUpdateAction.class.php:1.1.2.5
--- xoops2jp/html/modules/legacy/admin/actions/ModuleUpdateAction.class.php:1.1.2.4	Thu Oct 26 00:27:03 2006
+++ xoops2jp/html/modules/legacy/admin/actions/ModuleUpdateAction.class.php	Mon Oct 30 18:52:32 2006
@@ -8,10 +8,9 @@
 
 require_once XOOPS_LEGACY_PATH . "/admin/actions/AbstractModuleInstallAction.class.php";
 require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUpdater.class.php";
-require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleUpdateFramework.class.php";
 require_once XOOPS_LEGACY_PATH . "/admin/forms/ModuleUpdateForm.class.php";
 
-class Legacy_ModuleUpdateAction extends Legacy_AbstractModuleInstallAction
+class Legacy_ModuleUpdateAction extends Legacy_Action
 {
 	/**
 	 * @var XCube_Delegate
@@ -22,10 +21,14 @@
 	 * @var XCube_Delegate
 	 */
 	var $mUpdateFail = null;
-
+	
+	var $mXoopsModule = null;
+	
+	var $mInstaller = null;
+	
 	function Legacy_ModuleUpdateAction($flag)
 	{
-		parent::Legacy_AbstractModuleInstallAction($flag);
+		parent::Legacy_Action($flag);
 		
 		$this->mUpdateSuccess =& new XCube_Delegate();
 		$this->mUpdateSuccess->register('Legacy_ModuleUpdateAction.UpdateSuccess');
@@ -33,73 +36,136 @@
 		$this->mUpdateFail =& new XCube_Delegate();
 		$this->mUpdateFail->register('Legacy_ModuleUpdateAction.UpdateFail');
 	}
-
-	function &_getInstaller($dirname)
+	
+	function prepare(&$controller, &$xoopsUser)
 	{
+		$dirname = $controller->mRoot->mContext->mRequest->getRequest('dirname');
+		
+		$handler =& xoops_gethandler('module');
+		$this->mXoopsModule =& $handler->getByDirname($dirname);
+		
+		if (!is_object($this->mXoopsModule)) {
+			return false;
+		}
+		
+		$this->_setupActionForm();
+		
+		$this->mInstaller =& $this->_getInstaller();
+		
 		//
-		// Umm...
+		// Set the current object.
 		//
-		$handler =& xoops_gethandler('module');
-		$module =& $handler->getByDirname($dirname);
+		$this->mInstaller->setCurrentXoopsModule($this->mXoopsModule);
 		
-		if ($module != null) {
-			$module->loadInfo($dirname, false);
-			
-			$info = $module->modinfo;
+		//
+		// Load the manifesto, and set it as the target object.
+		//
+        $name = $this->mXoopsModule->get('name');
+		$this->mXoopsModule->loadInfoAsVar($dirname);
+		$this->mXoopsModule->set('name', $name);
+		$this->mInstaller->setTargetXoopsModule($this->mXoopsModule);
+		
+		return true;
+	}
+
+	function _setupActionForm()
+	{
+		$this->mActionForm =& new Legacy_ModuleUpdateForm();
+		$this->mActionForm->prepare();
+	}
+
+	/**
+	 * Creates a instance of the upgrade installer to mInstaller. And returns
+	 * it.
+	 * 
+	 * The precondition is the existence of mXoopsModule.
+	 */
+	function _getInstaller()
+	{
+		$dirname = $this->mXoopsModule->get('dirname');
+		$this->mXoopsModule->loadInfo($dirname, false);
+
+		$info = $this->mXoopsModule->modinfo;
 			
-			if (isset($info['legacy_installer']) && is_array($info['legacy_installer']) && isset($info['legacy_installer']['updater'])) {
-				$updateInfo = $info['legacy_installer']['updater'];
+		if (isset($info['legacy_installer']) && is_array($info['legacy_installer']) && isset($info['legacy_installer']['updater'])) {
+			$updateInfo = $info['legacy_installer']['updater'];
 				
-				$className = $updateInfo['class'];
-				$filePath = isset($updateInfo['filepath']) ? $updateInfo['filepath'] : XOOPS_MODULE_PATH . "/${dirname}/admin/class/${className}.class.php";
-				$namespace = isset($updateInfo['namespace']) ? $updateInfo['namespace'] : ucfirst($dirname);
+			$className = $updateInfo['class'];
+			$filePath = isset($updateInfo['filepath']) ? $updateInfo['filepath'] : XOOPS_MODULE_PATH . "/${dirname}/admin/class/${className}.class.php";
+			$namespace = isset($updateInfo['namespace']) ? $updateInfo['namespace'] : ucfirst($dirname);
 				
-				if ($namespace != null) {
-					$className = "${namespace}_${className}";
-				}
+			if ($namespace != null) {
+				$className = "${namespace}_${className}";
+			}
 				
-				if (!class_exists($className) && file_exists($filePath)) {
-					require_once $filePath;
-				}
+			if (!class_exists($className) && file_exists($filePath)) {
+				require_once $filePath;
+			}
 				
-				if (class_exists($className)) {
-					$installer =& new $className($dirname);
-					return $installer;
-				}
+			if (class_exists($className)) {
+				$installer =& new $className();
+				return $installer;
 			}
 		}
 		
-		$installer =& new Legacy_ModuleUpdater($dirname);
+		$installer =& new Legacy_ModulePhasedUpgrader();
 		return $installer;
 	}
 	
-	function _setupActionForm()
+	function getDefaultView(&$controller, &$xoopsUser)
 	{
-		$this->mActionForm =& new Legacy_ModuleUpdateForm();
-		$this->mActionForm->prepare();
+		$this->mActionForm->load($this->mXoopsModule);
+		
+		return LEGACY_FRAME_VIEW_INPUT;
 	}
-	
+
+	function execute(&$controller, &$xoopsUser)
+	{
+		if (isset($_REQUEST['_form_control_cancel'])) {
+			return LEGACY_FRAME_VIEW_CANCEL;
+		}
+		
+		$this->mActionForm->fetch();
+		$this->mActionForm->validate();
+		
+		if ($this->mActionForm->hasError()) {
+			return $this->getDefaultView($controller, $xoopsUser);
+		}
+		
+		$this->mInstaller->setForceMode($this->mActionForm->get('force'));
+		$this->mInstaller->executeUpgrade();
+
+		return LEGACY_FRAME_VIEW_SUCCESS;
+	}
+
 	function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
 	{
-		if (!$this->mLog->hasError()) {
-			$this->mUpdateSuccess->call(new XCube_Ref($this->mModuleObject), new XCube_Ref($this->mLog));
-			XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($this->mModuleObject->get('dirname') . '.Success'), new XCube_Ref($this->mModuleObject), new XCube_Ref($this->mLog));
+		if (!$this->mInstaller->mLog->hasError()) {
+			$this->mUpdateSuccess->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
+			XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($this->mXoopsModule->get('dirname') . '.Success'), new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
 		}
 		else {
-			$this->mUpdateFail->call(new XCube_Ref($this->mModuleObject), new XCube_Ref($this->mLog));
-			XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($this->mModuleObject->get('dirname') . '.Fail'), new XCube_Ref($this->mModuleObject), new XCube_Ref($this->mLog));
+			$this->mUpdateFail->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
+			XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($this->mXoopsModule->get('dirname') . '.Fail'), new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
 		}
 		
 		$renderer->setTemplateName("module_update_success.html");
-		$renderer->setAttribute('module', $this->mModuleObject);
-		$renderer->setAttribute('log', $this->mLog->mMessages);
+		$renderer->setAttribute('module', $this->mXoopsModule);
+		$renderer->setAttribute('log', $this->mInstaller->mLog->mMessages);
+		$renderer->setAttribute('currentVersion', round($this->mInstaller->getCurrentVersion() / 100, 2));
+		$renderer->setAttribute('targetVersion', round($this->mInstaller->getTargetPhase() / 100, 2));
+		$renderer->setAttribute('isPhasedMode', $this->mInstaller->hasUpgradeMethod());
+		$renderer->setAttribute('isLatestUpgrade', $this->mInstaller->isLatestUpgrade());
 	}
 
-	function executeViewIndex(&$controller, &$xoopsUser, &$renderer)
+	function executeViewInput(&$controller, &$xoopsUser, &$renderer)
 	{
 		$renderer->setTemplateName("module_update.html");
-		$renderer->setAttribute('module', $this->mModuleObject);
+		$renderer->setAttribute('module', $this->mXoopsModule);
 		$renderer->setAttribute('actionForm', $this->mActionForm);
+		$renderer->setAttribute('currentVersion', round($this->mInstaller->getCurrentVersion() / 100, 2));
+		$renderer->setAttribute('targetVersion', round($this->mInstaller->getTargetPhase() / 100, 2));
+		$renderer->setAttribute('isPhasedMode', $this->mInstaller->hasUpgradeMethod());
 	}
 	
 	function executeViewCancel(&$controller, &$xoopsUser, &$renderer)


xoops-cvslog メーリングリストの案内
Back to archive index