1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: require_once XOOPS_LEGACY_PATH."/admin/actions/AbstractModuleInstallAction.class.php";
14: require_once XOOPS_LEGACY_PATH . "/admin/class/ModuleInstallUtils.class.php";
15: require_once XOOPS_LEGACY_PATH."/admin/forms/ModuleInstallForm.class.php";
16:
17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64:
65: class Legacy_ModuleInstallAction extends Legacy_Action
66: {
67: 68: 69:
70: var $mInstallSuccess = null;
71:
72: 73: 74:
75: var $mInstallFail = null;
76:
77: 78: 79: 80:
81: var $mXoopsModule = null;
82:
83: 84: 85: 86:
87: var $mInstaller = null;
88:
89: function Legacy_ModuleInstallAction($flag)
90: {
91: parent::Legacy_Action($flag);
92:
93: $this->mInstallSuccess =new XCube_Delegate();
94: $this->mInstallSuccess->register('Legacy_ModuleInstallAction.InstallSuccess');
95:
96: $this->mInstallFail =new XCube_Delegate();
97: $this->mInstallFail->register('Legacy_ModuleInstallAction.InstallFail');
98: }
99:
100: function prepare(&$controller, &$xoopsUser)
101: {
102: $dirname = $controller->mRoot->mContext->mRequest->getRequest('dirname');
103:
104: $handler =& xoops_gethandler('module');
105: $this->mXoopsModule =& $handler->getByDirname($dirname);
106:
107: if (is_object($this->mXoopsModule)) {
108: return false;
109: }
110:
111: $this->mXoopsModule =& $handler->create();
112:
113: $this->mXoopsModule->set('weight', 1);
114: $this->mXoopsModule->loadInfoAsVar($dirname);
115:
116: if ($this->mXoopsModule->get('dirname') == null) {
117: return false;
118: }
119:
120: if ($this->mXoopsModule->get('dirname') == 'system') {
121: $this->mXoopsModule->set('mid', 1);
122: }
123:
124: $this->_setupActionForm();
125:
126: $this->mInstaller =& $this->_getInstaller();
127:
128:
129:
130:
131: $this->mInstaller->setCurrentXoopsModule($this->mXoopsModule);
132:
133: return true;
134: }
135:
136: function &_getInstaller()
137: {
138: $dirname = $this->mXoopsModule->get('dirname');
139: $installer =& Legacy_ModuleInstallUtils::createInstaller($dirname);
140: return $installer;
141: }
142:
143: function _setupActionForm()
144: {
145: $this->mActionForm =new Legacy_ModuleInstallForm();
146: $this->mActionForm->prepare();
147: }
148:
149: function getDefaultView(&$controller, &$xoopsUser)
150: {
151: $this->mActionForm->load($this->mXoopsModule);
152:
153: return LEGACY_FRAME_VIEW_INPUT;
154: }
155:
156: function execute(&$controller, &$xoopsUser)
157: {
158: if (isset($_REQUEST['_form_control_cancel'])) {
159: return LEGACY_FRAME_VIEW_CANCEL;
160: }
161:
162: $this->mActionForm->fetch();
163: $this->mActionForm->validate();
164:
165: if ($this->mActionForm->hasError()) {
166: return $this->getDefaultView($controller, $xoopsUser);
167: }
168:
169: $this->mInstaller->setForceMode($this->mActionForm->get('force'));
170: if (!$this->mInstaller->executeInstall()) {
171: $this->mInstaller->mLog->addReport('Force Uninstallation is started.');
172: $dirname = $this->mXoopsModule->get('dirname');
173: $uninstaller =& Legacy_ModuleInstallUtils::createUninstaller($dirname);
174:
175: $uninstaller->setForceMode(true);
176: $uninstaller->setCurrentXoopsModule($this->mXoopsModule);
177:
178: $uninstaller->executeUninstall();
179: }
180:
181: return LEGACY_FRAME_VIEW_SUCCESS;
182: }
183:
184: 185: 186:
187: function executeViewSuccess(&$controller,&$xoopsUser,&$renderer)
188: {
189: if (!$this->mInstaller->mLog->hasError()) {
190: $this->mInstallSuccess->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
191: XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleInstall.' . ucfirst($this->mXoopsModule->get('dirname') . '.Success'), new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
192: }
193: else {
194: $this->mInstallFail->call(new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
195: XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleInstall.' . ucfirst($this->mXoopsModule->get('dirname') . '.Fail'), new XCube_Ref($this->mXoopsModule), new XCube_Ref($this->mInstaller->mLog));
196: }
197:
198: $renderer->setTemplateName("module_install_success.html");
199: $renderer->setAttribute('module', $this->mXoopsModule);
200: $renderer->setAttribute('log', $this->mInstaller->mLog->mMessages);
201: }
202:
203: 204: 205:
206: function executeViewInput(&$controller,&$xoopsUser,&$renderer)
207: {
208: $renderer->setTemplateName("module_install.html");
209: $renderer->setAttribute('module', $this->mXoopsModule);
210: $renderer->setAttribute('actionForm', $this->mActionForm);
211: $renderer->setAttribute('currentVersion', round($this->mXoopsModule->get('version') / 100, 2));
212: }
213:
214: function executeViewCancel(&$controller, &$xoopsUser, &$render)
215: {
216: $controller->executeForward("./index.php?action=InstallList");
217: }
218: }
219:
220: ?>
221: