XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ModuleUpdateAction.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_LEGACY_PATH . '/admin/actions/AbstractModuleInstallAction.class.php';
17require_once XOOPS_LEGACY_PATH . '/admin/class/ModuleInstallUtils.class.php';
18require_once XOOPS_LEGACY_PATH . '/admin/forms/ModuleUpdateForm.class.php';
19
70class Legacy_ModuleUpdateAction extends Legacy_Action
71{
75 public $mUpdateSuccess = null;
76
80 public $mUpdateFail = null;
81
82 public $mXoopsModule = null;
83
84 public $mInstaller = null;
85
89 protected $mActionForm;
90
94 protected $mErrorMessages;
95
99 protected $mModuleObjects;
100 public function __construct()
101 {
102 parent::__construct();
103 $this->mActionForm = null;
104 $this->mErrorMessages = [];
105 $this->mModuleObjects = [];
106
107 $this->mUpdateSuccess =new XCube_Delegate();
108 $this->mUpdateSuccess->register('Legacy_ModuleUpdateAction.UpdateSuccess');
109
110 $this->mUpdateFail =new XCube_Delegate();
111 $this->mUpdateFail->register('Legacy_ModuleUpdateAction.UpdateFail');
112 }
113
114 public function prepare(&$controller, &$xoopsUser)
115 {
116 $dirname = $controller->mRoot->mContext->mRequest->getRequest('dirname');
117
118 $handler =& xoops_gethandler('module');
119 $this->mXoopsModule =& $handler->getByDirname($dirname);
120
121 if (!is_object($this->mXoopsModule)) {
122 return false;
123 }
124
125 $this->_setupActionForm();
126
127 $this->mInstaller =& $this->_getInstaller();
128
129 //
130 // Set the current object.
131 //
132 $this->mInstaller->setCurrentXoopsModule($this->mXoopsModule);
133
134 //
135 // Load the manifesto, and set it as the target object.
136 //
137 $name = $this->mXoopsModule->get('name');
138 $this->mXoopsModule->loadInfoAsVar($dirname);
139 $this->mXoopsModule->set('name', $name);
140 $this->mInstaller->setTargetXoopsModule($this->mXoopsModule);
141
142 return true;
143 }
144
145 public function _setupActionForm()
146 {
147 $this->mActionForm =new Legacy_ModuleUpdateForm();
148 $this->mActionForm->prepare();
149 }
150
157 public function &_getInstaller()
158 {
159 $dirname = $this->mXoopsModule->get('dirname');
160 $installer =& Legacy_ModuleInstallUtils::createUpdater($dirname);
161 return $installer;
162 }
163
164 public function getDefaultView(&$controller, &$xoopsUser)
165 {
166 $this->mActionForm->load($this->mXoopsModule);
167
168 return LEGACY_FRAME_VIEW_INPUT;
169 }
170
171 public function execute(&$controller, &$xoopsUser)
172 {
173 if (isset($_REQUEST['_form_control_cancel'])) {
174 return LEGACY_FRAME_VIEW_CANCEL;
175 }
176
177 $this->mActionForm->fetch();
178 $this->mActionForm->validate();
179
180 if ($this->mActionForm->hasError()) {
181 return $this->getDefaultView($controller, $xoopsUser);
182 }
183
184 $this->mInstaller->setForceMode($this->mActionForm->get('force'));
185 $this->mInstaller->executeUpgrade();
186
187 return LEGACY_FRAME_VIEW_SUCCESS;
188 }
189
190 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
191 {
192 if (!$this->mInstaller->mLog->hasError()) {
193 $this->mUpdateSuccess->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
194 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($this->mXoopsModule->get('dirname')) . '.Success', new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
195 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.Success', new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
196 } else {
197 $this->mUpdateFail->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
198 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.' . ucfirst($this->mXoopsModule->get('dirname')) . '.Fail', new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
199 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleUpdate.Fail', new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
200 }
201
202 $renderer->setTemplateName('module_update_success.html');
203 $renderer->setAttribute('module', $this->mXoopsModule);
204 $renderer->setAttribute('log', $this->mInstaller->mLog->mMessages);
205 $renderer->setAttribute('currentVersion', round($this->mInstaller->getCurrentVersion() / 100, 2));
206 $renderer->setAttribute('targetVersion', round($this->mInstaller->getTargetPhase() / 100, 2));
207 $renderer->setAttribute('isPhasedMode', $this->mInstaller->hasUpgradeMethod());
208 $renderer->setAttribute('isLatestUpgrade', $this->mInstaller->isLatestUpgrade());
209 }
210
211 public function executeViewInput(&$controller, &$xoopsUser, &$renderer)
212 {
213 $renderer->setTemplateName('module_update.html');
214 $renderer->setAttribute('module', $this->mXoopsModule);
215 $renderer->setAttribute('actionForm', $this->mActionForm);
216 $renderer->setAttribute('currentVersion', round($this->mInstaller->getCurrentVersion() / 100, 2));
217 $renderer->setAttribute('targetVersion', round($this->mInstaller->getTargetPhase() / 100, 2));
218 $renderer->setAttribute('isPhasedMode', $this->mInstaller->hasUpgradeMethod());
219 }
220
221 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
222 {
223 $controller->executeForward('./index.php?action=ModuleList');
224 }
225}
Module Update function having possibility to extend by module developers.
[Final] Used for the simple mechanism for common delegation in XCube.