XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ModuleInstallAction.class.php
1<?php
10
11 if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13 }
14
15require_once XOOPS_LEGACY_PATH . '/admin/actions/AbstractModuleInstallAction.class.php';
16require_once XOOPS_LEGACY_PATH . '/admin/class/ModuleInstallUtils.class.php';
17require_once XOOPS_LEGACY_PATH . '/admin/forms/ModuleInstallForm.class.php';
18
67class Legacy_ModuleInstallAction extends Legacy_Action
68{
72 public $mInstallSuccess = null;
73
77 public $mInstallFail = null;
78
83 public $mXoopsModule = null;
84
89 public $mInstaller = null;
90
95 public $mActionForm = null;
96
97 public function __construct($flag)
98 {
99 parent::__construct($flag);
100
101 $this->mInstallSuccess =new XCube_Delegate();
102 $this->mInstallSuccess->register('Legacy_ModuleInstallAction.InstallSuccess');
103
104 $this->mInstallFail =new XCube_Delegate();
105 $this->mInstallFail->register('Legacy_ModuleInstallAction.InstallFail');
106 }
107
108 public function prepare(&$controller, &$xoopsUser)
109 {
110 $dirname = $controller->mRoot->mContext->mRequest->getRequest('dirname');
111
112 $handler =& xoops_gethandler('module');
113 $this->mXoopsModule =& $handler->getByDirname($dirname);
114
115 if (is_object($this->mXoopsModule)) {
116 return false;
117 }
118
119 $this->mXoopsModule =& $handler->create();
120
121 $this->mXoopsModule->set('weight', 1);
122 $this->mXoopsModule->loadInfoAsVar($dirname);
123
124 if (null == $this->mXoopsModule->get('dirname')) {
125 return false;
126 }
127
128 if ('system' == $this->mXoopsModule->get('dirname')) {
129 $this->mXoopsModule->set('mid', 1);
130 }
131
132 $this->_setupActionForm();
133
134 $this->mInstaller =& $this->_getInstaller();
135
136 //
137 // Set the current object.
138 //
139 $this->mInstaller->setCurrentXoopsModule($this->mXoopsModule);
140
141 return true;
142 }
143
144 public function &_getInstaller()
145 {
146 $dirname = $this->mXoopsModule->get('dirname');
147 $installer =& Legacy_ModuleInstallUtils::createInstaller($dirname);
148 return $installer;
149 }
150
151 public function _setupActionForm()
152 {
153 $this->mActionForm =new Legacy_ModuleInstallForm();
154 $this->mActionForm->prepare();
155 }
156
157 public function getDefaultView(&$controller, &$xoopsUser)
158 {
159 $this->mActionForm->load($this->mXoopsModule);
160
161 return LEGACY_FRAME_VIEW_INPUT;
162 }
163
164 public function execute(&$controller, &$xoopsUser)
165 {
166 if (isset($_REQUEST['_form_control_cancel'])) {
167 return LEGACY_FRAME_VIEW_CANCEL;
168 }
169
170 $this->mActionForm->fetch();
171 $this->mActionForm->validate();
172
173 if ($this->mActionForm->hasError()) {
174 return $this->getDefaultView($controller, $xoopsUser);
175 }
176
177 $this->mInstaller->setForceMode($this->mActionForm->get('force'));
178 if (!$this->mInstaller->executeInstall()) {
179 $this->mInstaller->mLog->addReport('Force Uninstallation is started.');
180 $dirname = $this->mXoopsModule->get('dirname');
181 $uninstaller =& Legacy_ModuleInstallUtils::createUninstaller($dirname);
182
183 $uninstaller->setForceMode(true);
184 $uninstaller->setCurrentXoopsModule($this->mXoopsModule);
185
186 $uninstaller->executeUninstall();
187 }
188
189 return LEGACY_FRAME_VIEW_SUCCESS;
190 }
191
198 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
199 {
200 if (!$this->mInstaller->mLog->hasError()) {
201 $this->mInstallSuccess->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
202 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleInstall.' . ucfirst($this->mXoopsModule->get('dirname') . '.Success'), new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
203 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleInstall.Success', new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
204 } else {
205 $this->mInstallFail->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
206 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleInstall.' . ucfirst($this->mXoopsModule->get('dirname') . '.Fail'), new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
207 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleInstall.Fail', new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
208 }
209
210 $renderer->setTemplateName('module_install_success.html');
211 $renderer->setAttribute('module', $this->mXoopsModule);
212 $renderer->setAttribute('log', $this->mInstaller->mLog->mMessages);
213 }
214
221 public function executeViewInput(&$controller, &$xoopsUser, &$renderer)
222 {
223 $renderer->setTemplateName('module_install.html');
224 $renderer->setAttribute('module', $this->mXoopsModule);
225 $renderer->setAttribute('actionForm', $this->mActionForm);
226 $renderer->setAttribute('currentVersion', round($this->mXoopsModule->get('version') / 100, 2));
227 }
228
229 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
230 {
231 $controller->executeForward('./index.php?action=InstallList');
232 }
233}
Module Install function having possibility to extend by module developers.
executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
executeViewInput(&$controller, &$xoopsUser, &$renderer)
[Final] Used for the simple mechanism for common delegation in XCube.