1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29:
30: class Mage_Install_WizardController extends Mage_Install_Controller_Action
31: {
32: public function preDispatch()
33: {
34: if (Mage::isInstalled()) {
35: $this->setFlag('', self::FLAG_NO_DISPATCH, true);
36: $this->_redirect('/');
37: return;
38: }
39: $this->setFlag('', self::FLAG_NO_CHECK_INSTALLATION, true);
40: return parent::preDispatch();
41: }
42:
43: 44: 45: 46: 47:
48: protected function _getInstaller()
49: {
50: return Mage::getSingleton('install/installer');
51: }
52:
53: 54: 55: 56: 57:
58: protected function _getWizard()
59: {
60: return Mage::getSingleton('install/wizard');
61: }
62:
63: 64: 65: 66: 67:
68: protected function _prepareLayout()
69: {
70: $this->loadLayout('install_wizard');
71: $step = $this->_getWizard()->getStepByRequest($this->getRequest());
72: if ($step) {
73: $step->setActive(true);
74: }
75:
76: $leftBlock = $this->getLayout()->createBlock('install/state', 'install.state');
77: $this->getLayout()->getBlock('left')->append($leftBlock);
78: return $this;
79: }
80:
81: 82: 83: 84: 85:
86: protected function _checkIfInstalled()
87: {
88: if ($this->_getInstaller()->isApplicationInstalled()) {
89: $this->getResponse()->setRedirect(Mage::getBaseUrl())->sendResponse();
90: exit;
91: }
92: return true;
93: }
94:
95: 96: 97:
98: public function indexAction()
99: {
100: $this->_forward('begin');
101: }
102:
103: 104: 105:
106: public function beginAction()
107: {
108: $this->_checkIfInstalled();
109:
110: $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
111: $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
112:
113: $this->_prepareLayout();
114: $this->_initLayoutMessages('install/session');
115:
116: $this->getLayout()->getBlock('content')->append(
117: $this->getLayout()->createBlock('install/begin', 'install.begin')
118: );
119:
120: $this->renderLayout();
121: }
122:
123: 124: 125:
126: public function beginPostAction()
127: {
128: $this->_checkIfInstalled();
129:
130: $agree = $this->getRequest()->getPost('agree');
131: if ($agree && $step = $this->_getWizard()->getStepByName('begin')) {
132: $this->getResponse()->setRedirect($step->getNextUrl());
133: }
134: else {
135: $this->_redirect('install');
136: }
137: }
138:
139: 140: 141:
142: public function localeAction()
143: {
144: $this->_checkIfInstalled();
145: $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
146: $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
147:
148: $this->_prepareLayout();
149: $this->_initLayoutMessages('install/session');
150: $this->getLayout()->getBlock('content')->append(
151: $this->getLayout()->createBlock('install/locale', 'install.locale')
152: );
153:
154: $this->renderLayout();
155: }
156:
157: 158: 159:
160: public function localeChangeAction()
161: {
162: $this->_checkIfInstalled();
163:
164: $locale = $this->getRequest()->getParam('locale');
165: $timezone = $this->getRequest()->getParam('timezone');
166: $currency = $this->getRequest()->getParam('currency');
167: if ($locale) {
168: Mage::getSingleton('install/session')->setLocale($locale);
169: Mage::getSingleton('install/session')->setTimezone($timezone);
170: Mage::getSingleton('install/session')->setCurrency($currency);
171: }
172:
173: $this->_redirect('*/*/locale');
174: }
175:
176: 177: 178:
179: public function localePostAction()
180: {
181: $this->_checkIfInstalled();
182: $step = $this->_getWizard()->getStepByName('locale');
183:
184: if ($data = $this->getRequest()->getPost('config')) {
185: Mage::getSingleton('install/session')->setLocaleData($data);
186: }
187:
188: $this->getResponse()->setRedirect($step->getNextUrl());
189: }
190:
191: public function downloadAction()
192: {
193: $this->_checkIfInstalled();
194: $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
195: $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
196:
197: $this->_prepareLayout();
198: $this->_initLayoutMessages('install/session');
199: $this->getLayout()->getBlock('content')->append(
200: $this->getLayout()->createBlock('install/download', 'install.download')
201: );
202:
203: $this->renderLayout();
204: }
205:
206: public function downloadPostAction()
207: {
208: $this->_checkIfInstalled();
209: switch ($this->getRequest()->getPost('continue')) {
210: case 'auto':
211: $this->_forward('downloadAuto');
212: break;
213:
214: case 'manual':
215: $this->_forward('downloadManual');
216: break;
217:
218: case 'svn':
219: $step = $this->_getWizard()->getStepByName('download');
220: $this->getResponse()->setRedirect($step->getNextUrl());
221: break;
222:
223: default:
224: $this->_redirect('*/*/download');
225: }
226: }
227:
228: public function downloadAutoAction()
229: {
230: $step = $this->_getWizard()->getStepByName('download');
231: $this->getResponse()->setRedirect($step->getNextUrl());
232: }
233:
234: public function installAction()
235: {
236: $pear = Varien_Pear::getInstance();
237: $params = array('comment'=>Mage::helper('install')->__("Downloading and installing Magento, please wait...") . "\r\n\r\n");
238: if ($this->getRequest()->getParam('do')) {
239: if ($state = $this->getRequest()->getParam('state', 'beta')) {
240: $result = $pear->runHtmlConsole(array(
241: 'comment' => Mage::helper('install')->__("Setting preferred state to: %s", $state) . "\r\n\r\n",
242: 'command' => 'config-set',
243: 'params' => array('preferred_state', $state)
244: ));
245: if ($result instanceof PEAR_Error) {
246: $this->installFailureCallback();
247: exit;
248: }
249: }
250: $params['command'] = 'install';
251: $params['options'] = array('onlyreqdeps'=>1);
252: $params['params'] = Mage::getModel('install/installer_pear')->getPackages();
253: $params['success_callback'] = array($this, 'installSuccessCallback');
254: $params['failure_callback'] = array($this, 'installFailureCallback');
255: }
256: $pear->runHtmlConsole($params);
257: Mage::app()->getFrontController()->getResponse()->clearAllHeaders();
258: }
259:
260: public function installSuccessCallback()
261: {
262: echo 'parent.installSuccess()';
263: }
264:
265: public function installFailureCallback()
266: {
267: echo 'parent.installFailure()';
268: }
269:
270: public function downloadManualAction()
271: {
272: $step = $this->_getWizard()->getStepByName('download');
273:
274:
275:
276: $this->getResponse()->setRedirect($step->getNextUrl());
277:
278: }
279:
280: 281: 282:
283: public function configAction()
284: {
285: $this->_checkIfInstalled();
286: $this->_getInstaller()->checkServer();
287:
288: $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
289: $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
290:
291: if ($data = $this->getRequest()->getQuery('config')) {
292: Mage::getSingleton('install/session')->setLocaleData($data);
293: }
294:
295: $this->_prepareLayout();
296: $this->_initLayoutMessages('install/session');
297: $this->getLayout()->getBlock('content')->append(
298: $this->getLayout()->createBlock('install/config', 'install.config')
299: );
300:
301: $this->renderLayout();
302: }
303:
304: 305: 306:
307: public function configPostAction()
308: {
309: $this->_checkIfInstalled();
310: $step = $this->_getWizard()->getStepByName('config');
311:
312: $config = $this->getRequest()->getPost('config');
313: $connectionConfig = $this->getRequest()->getPost('connection');
314:
315: if ($config && $connectionConfig && isset($connectionConfig[$config['db_model']])) {
316:
317: $data = array_merge($config, $connectionConfig[$config['db_model']]);
318:
319: Mage::getSingleton('install/session')
320: ->setConfigData($data)
321: ->setSkipUrlValidation($this->getRequest()->getPost('skip_url_validation'))
322: ->setSkipBaseUrlValidation($this->getRequest()->getPost('skip_base_url_validation'));
323: try {
324: $this->_getInstaller()->installConfig($data);
325: $this->_redirect('*/*/installDb');
326: return $this;
327: }
328: catch (Exception $e){
329: Mage::getSingleton('install/session')->addError($e->getMessage());
330: $this->getResponse()->setRedirect($step->getUrl());
331: }
332: }
333: $this->getResponse()->setRedirect($step->getUrl());
334: }
335:
336: 337: 338:
339: public function installDbAction()
340: {
341: $this->_checkIfInstalled();
342: $step = $this->_getWizard()->getStepByName('config');
343: try {
344: $this->_getInstaller()->installDb();
345: 346: 347:
348: Mage::getSingleton('install/session')->getConfigData(true);
349:
350: Mage::app()->getStore()->resetConfig();
351:
352: $this->getResponse()->setRedirect(Mage::getUrl($step->getNextUrlPath()));
353: }
354: catch (Exception $e){
355: Mage::getSingleton('install/session')->addError($e->getMessage());
356: $this->getResponse()->setRedirect($step->getUrl());
357: }
358: }
359:
360: 361: 362:
363: public function administratorAction()
364: {
365: $this->_checkIfInstalled();
366:
367: $this->_prepareLayout();
368: $this->_initLayoutMessages('install/session');
369:
370: $this->getLayout()->getBlock('content')->append(
371: $this->getLayout()->createBlock('install/admin', 'install.administrator')
372: );
373: $this->renderLayout();
374: }
375:
376: 377: 378:
379: public function administratorPostAction()
380: {
381: $this->_checkIfInstalled();
382:
383: $step = Mage::getSingleton('install/wizard')->getStepByName('administrator');
384: $adminData = $this->getRequest()->getPost('admin');
385: $encryptionKey = $this->getRequest()->getPost('encryption_key');
386:
387: $errors = array();
388:
389:
390: $user = $this->_getInstaller()->validateAndPrepareAdministrator($adminData);
391: if (is_array($user)) {
392: $errors = $user;
393: }
394:
395:
396: $result = $this->_getInstaller()->validateEncryptionKey($encryptionKey);
397: if (is_array($result)) {
398: $errors = array_merge($errors, $result);
399: }
400:
401: if (!empty($errors)) {
402: Mage::getSingleton('install/session')->setAdminData($adminData);
403: $this->getResponse()->setRedirect($step->getUrl());
404: return false;
405: }
406:
407: try {
408: $this->_getInstaller()->createAdministrator($user);
409: $this->_getInstaller()->installEnryptionKey($encryptionKey);
410: } catch (Exception $e){
411: Mage::getSingleton('install/session')
412: ->setAdminData($adminData)
413: ->addError($e->getMessage());
414: $this->getResponse()->setRedirect($step->getUrl());
415: return false;
416: }
417: $this->getResponse()->setRedirect($step->getNextUrl());
418: }
419:
420: 421: 422:
423: public function endAction()
424: {
425: $this->_checkIfInstalled();
426:
427: $date = (string)Mage::getConfig()->getNode('global/install/date');
428: if ($date !== Mage_Install_Model_Installer_Config::TMP_INSTALL_DATE_VALUE) {
429: $this->_redirect('*/*');
430: return;
431: }
432:
433: $this->_getInstaller()->finish();
434:
435: Mage_AdminNotification_Model_Survey::saveSurveyViewed(true);
436:
437: $this->_prepareLayout();
438: $this->_initLayoutMessages('install/session');
439:
440: $this->getLayout()->getBlock('content')->append(
441: $this->getLayout()->createBlock('install/end', 'install.end')
442: );
443: $this->renderLayout();
444: Mage::getSingleton('install/session')->clear();
445: }
446:
447: 448: 449:
450: public function checkHostAction()
451: {
452: $this->getResponse()->setHeader('Transfer-encoding', '', true);
453: $this->getResponse()->setBody(Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE);
454: }
455:
456: 457: 458:
459: public function checkSecureHostAction()
460: {
461: $this->getResponse()->setHeader('Transfer-encoding', '', true);
462: $this->getResponse()->setBody(Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE);
463: }
464: }
465: