PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/app/code/core/Mage/Install/controllers/WizardController.php

https://github.com/rgranadino/magento-mirror
PHP | 464 lines | 300 code | 66 blank | 98 comment | 20 complexity | 689f343c7defaec6ad76555922a6a063 MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Install
  23. * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Installation wizard controller
  28. */
  29. class Mage_Install_WizardController extends Mage_Install_Controller_Action
  30. {
  31. public function preDispatch()
  32. {
  33. if (Mage::isInstalled()) {
  34. $this->setFlag('', self::FLAG_NO_DISPATCH, true);
  35. $this->_redirect('/');
  36. return;
  37. }
  38. $this->setFlag('', self::FLAG_NO_CHECK_INSTALLATION, true);
  39. return parent::preDispatch();
  40. }
  41. /**
  42. * Retrieve installer object
  43. *
  44. * @return Mage_Install_Model_Installer
  45. */
  46. protected function _getInstaller()
  47. {
  48. return Mage::getSingleton('install/installer');
  49. }
  50. /**
  51. * Retrieve wizard
  52. *
  53. * @return Mage_Install_Model_Wizard
  54. */
  55. protected function _getWizard()
  56. {
  57. return Mage::getSingleton('install/wizard');
  58. }
  59. /**
  60. * Prepare layout
  61. *
  62. * @return unknown
  63. */
  64. protected function _prepareLayout()
  65. {
  66. $this->loadLayout('install_wizard');
  67. $step = $this->_getWizard()->getStepByRequest($this->getRequest());
  68. if ($step) {
  69. $step->setActive(true);
  70. }
  71. $leftBlock = $this->getLayout()->createBlock('install/state', 'install.state');
  72. $this->getLayout()->getBlock('left')->append($leftBlock);
  73. return $this;
  74. }
  75. /**
  76. * Checking installation status
  77. *
  78. * @return unknown
  79. */
  80. protected function _checkIfInstalled()
  81. {
  82. if ($this->_getInstaller()->isApplicationInstalled()) {
  83. $this->getResponse()->setRedirect(Mage::getBaseUrl())->sendResponse();
  84. exit;
  85. }
  86. return true;
  87. }
  88. /**
  89. * Index action
  90. */
  91. public function indexAction()
  92. {
  93. $this->_forward('begin');
  94. }
  95. /**
  96. * Begin installation action
  97. */
  98. public function beginAction()
  99. {
  100. $this->_checkIfInstalled();
  101. $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
  102. $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
  103. $this->_prepareLayout();
  104. $this->_initLayoutMessages('install/session');
  105. $this->getLayout()->getBlock('content')->append(
  106. $this->getLayout()->createBlock('install/begin', 'install.begin')
  107. );
  108. $this->renderLayout();
  109. }
  110. /**
  111. * Process begin step POST data
  112. */
  113. public function beginPostAction()
  114. {
  115. $this->_checkIfInstalled();
  116. $agree = $this->getRequest()->getPost('agree');
  117. if ($agree && $step = $this->_getWizard()->getStepByName('begin')) {
  118. $this->getResponse()->setRedirect($step->getNextUrl());
  119. }
  120. else {
  121. $this->_redirect('install');
  122. }
  123. }
  124. /**
  125. * Localization settings
  126. */
  127. public function localeAction()
  128. {
  129. $this->_checkIfInstalled();
  130. $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
  131. $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
  132. $this->_prepareLayout();
  133. $this->_initLayoutMessages('install/session');
  134. $this->getLayout()->getBlock('content')->append(
  135. $this->getLayout()->createBlock('install/locale', 'install.locale')
  136. );
  137. $this->renderLayout();
  138. }
  139. /**
  140. * Change current locale
  141. */
  142. public function localeChangeAction()
  143. {
  144. $this->_checkIfInstalled();
  145. $locale = $this->getRequest()->getParam('locale');
  146. $timezone = $this->getRequest()->getParam('timezone');
  147. $currency = $this->getRequest()->getParam('currency');
  148. if ($locale) {
  149. Mage::getSingleton('install/session')->setLocale($locale);
  150. Mage::getSingleton('install/session')->setTimezone($timezone);
  151. Mage::getSingleton('install/session')->setCurrency($currency);
  152. }
  153. $this->_redirect('*/*/locale');
  154. }
  155. /**
  156. * Saving localization settings
  157. */
  158. public function localePostAction()
  159. {
  160. $this->_checkIfInstalled();
  161. $step = $this->_getWizard()->getStepByName('locale');
  162. if ($data = $this->getRequest()->getPost('config')) {
  163. Mage::getSingleton('install/session')->setLocaleData($data);
  164. }
  165. $this->getResponse()->setRedirect($step->getNextUrl());
  166. }
  167. public function downloadAction()
  168. {
  169. $this->_checkIfInstalled();
  170. $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
  171. $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
  172. $this->_prepareLayout();
  173. $this->_initLayoutMessages('install/session');
  174. $this->getLayout()->getBlock('content')->append(
  175. $this->getLayout()->createBlock('install/download', 'install.download')
  176. );
  177. $this->renderLayout();
  178. }
  179. public function downloadPostAction()
  180. {
  181. $this->_checkIfInstalled();
  182. switch ($this->getRequest()->getPost('continue')) {
  183. case 'auto':
  184. $this->_forward('downloadAuto');
  185. break;
  186. case 'manual':
  187. $this->_forward('downloadManual');
  188. break;
  189. case 'svn':
  190. $step = $this->_getWizard()->getStepByName('download');
  191. $this->getResponse()->setRedirect($step->getNextUrl());
  192. break;
  193. default:
  194. $this->_redirect('*/*/download');
  195. }
  196. }
  197. public function downloadAutoAction()
  198. {
  199. $step = $this->_getWizard()->getStepByName('download');
  200. $this->getResponse()->setRedirect($step->getNextUrl());
  201. }
  202. public function installAction()
  203. {
  204. $pear = Varien_Pear::getInstance();
  205. $params = array('comment'=>Mage::helper('install')->__("Downloading and installing Magento, please wait...") . "\r\n\r\n");
  206. if ($this->getRequest()->getParam('do')) {
  207. if ($state = $this->getRequest()->getParam('state', 'beta')) {
  208. $result = $pear->runHtmlConsole(array(
  209. 'comment' => Mage::helper('install')->__("Setting preferred state to: %s", $state) . "\r\n\r\n",
  210. 'command' => 'config-set',
  211. 'params' => array('preferred_state', $state)
  212. ));
  213. if ($result instanceof PEAR_Error) {
  214. $this->installFailureCallback();
  215. exit;
  216. }
  217. }
  218. $params['command'] = 'install';
  219. $params['options'] = array('onlyreqdeps'=>1);
  220. $params['params'] = Mage::getModel('install/installer_pear')->getPackages();
  221. $params['success_callback'] = array($this, 'installSuccessCallback');
  222. $params['failure_callback'] = array($this, 'installFailureCallback');
  223. }
  224. $pear->runHtmlConsole($params);
  225. Mage::app()->getFrontController()->getResponse()->clearAllHeaders();
  226. }
  227. public function installSuccessCallback()
  228. {
  229. echo 'parent.installSuccess()';
  230. }
  231. public function installFailureCallback()
  232. {
  233. echo 'parent.installFailure()';
  234. }
  235. public function downloadManualAction()
  236. {
  237. $step = $this->_getWizard()->getStepByName('download');
  238. #if (!$this->_getInstaller()->checkDownloads()) {
  239. # $this->getResponse()->setRedirect($step->getUrl());
  240. #} else {
  241. $this->getResponse()->setRedirect($step->getNextUrl());
  242. #}
  243. }
  244. /**
  245. * Configuration data installation
  246. */
  247. public function configAction()
  248. {
  249. $this->_checkIfInstalled();
  250. $this->_getInstaller()->checkServer();
  251. $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
  252. $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
  253. if ($data = $this->getRequest()->getQuery('config')) {
  254. Mage::getSingleton('install/session')->setLocaleData($data);
  255. }
  256. $this->_prepareLayout();
  257. $this->_initLayoutMessages('install/session');
  258. $this->getLayout()->getBlock('content')->append(
  259. $this->getLayout()->createBlock('install/config', 'install.config')
  260. );
  261. $this->renderLayout();
  262. }
  263. /**
  264. * Process configuration POST data
  265. */
  266. public function configPostAction()
  267. {
  268. $this->_checkIfInstalled();
  269. $step = $this->_getWizard()->getStepByName('config');
  270. $config = $this->getRequest()->getPost('config');
  271. $connectionConfig = $this->getRequest()->getPost('connection');
  272. if ($config && $connectionConfig && isset($connectionConfig[$config['db_model']])) {
  273. $data = array_merge($config, $connectionConfig[$config['db_model']]);
  274. Mage::getSingleton('install/session')
  275. ->setConfigData($data)
  276. ->setSkipUrlValidation($this->getRequest()->getPost('skip_url_validation'))
  277. ->setSkipBaseUrlValidation($this->getRequest()->getPost('skip_base_url_validation'));
  278. try {
  279. $this->_getInstaller()->installConfig($data);
  280. $this->_redirect('*/*/installDb');
  281. return $this;
  282. }
  283. catch (Exception $e){
  284. Mage::getSingleton('install/session')->addError($e->getMessage());
  285. $this->getResponse()->setRedirect($step->getUrl());
  286. }
  287. }
  288. $this->getResponse()->setRedirect($step->getUrl());
  289. }
  290. /**
  291. * Install DB
  292. */
  293. public function installDbAction()
  294. {
  295. $this->_checkIfInstalled();
  296. $step = $this->_getWizard()->getStepByName('config');
  297. try {
  298. $this->_getInstaller()->installDb();
  299. /**
  300. * Clear session config data
  301. */
  302. Mage::getSingleton('install/session')->getConfigData(true);
  303. Mage::app()->getStore()->resetConfig();
  304. $this->getResponse()->setRedirect(Mage::getUrl($step->getNextUrlPath()));
  305. }
  306. catch (Exception $e){
  307. Mage::getSingleton('install/session')->addError($e->getMessage());
  308. $this->getResponse()->setRedirect($step->getUrl());
  309. }
  310. }
  311. /**
  312. * Install administrator account
  313. */
  314. public function administratorAction()
  315. {
  316. $this->_checkIfInstalled();
  317. $this->_prepareLayout();
  318. $this->_initLayoutMessages('install/session');
  319. $this->getLayout()->getBlock('content')->append(
  320. $this->getLayout()->createBlock('install/admin', 'install.administrator')
  321. );
  322. $this->renderLayout();
  323. }
  324. /**
  325. * Process administrator instalation POST data
  326. */
  327. public function administratorPostAction()
  328. {
  329. $this->_checkIfInstalled();
  330. $step = Mage::getSingleton('install/wizard')->getStepByName('administrator');
  331. $adminData = $this->getRequest()->getPost('admin');
  332. $encryptionKey = $this->getRequest()->getPost('encryption_key');
  333. $errors = array();
  334. //preparing admin user model with data and validate it
  335. $user = $this->_getInstaller()->validateAndPrepareAdministrator($adminData);
  336. if (is_array($user)) {
  337. $errors = $user;
  338. }
  339. //checking if valid encryption key was entered
  340. $result = $this->_getInstaller()->validateEncryptionKey($encryptionKey);
  341. if (is_array($result)) {
  342. $errors = array_merge($errors, $result);
  343. }
  344. if (!empty($errors)) {
  345. Mage::getSingleton('install/session')->setAdminData($adminData);
  346. $this->getResponse()->setRedirect($step->getUrl());
  347. return false;
  348. }
  349. try {
  350. $this->_getInstaller()->createAdministrator($user);
  351. $this->_getInstaller()->installEnryptionKey($encryptionKey);
  352. } catch (Exception $e){
  353. Mage::getSingleton('install/session')
  354. ->setAdminData($adminData)
  355. ->addError($e->getMessage());
  356. $this->getResponse()->setRedirect($step->getUrl());
  357. return false;
  358. }
  359. $this->getResponse()->setRedirect($step->getNextUrl());
  360. }
  361. /**
  362. * End installation
  363. */
  364. public function endAction()
  365. {
  366. $this->_checkIfInstalled();
  367. $date = (string)Mage::getConfig()->getNode('global/install/date');
  368. if ($date !== Mage_Install_Model_Installer_Config::TMP_INSTALL_DATE_VALUE) {
  369. $this->_redirect('*/*');
  370. return;
  371. }
  372. $this->_getInstaller()->finish();
  373. Mage_AdminNotification_Model_Survey::saveSurveyViewed(true);
  374. $this->_prepareLayout();
  375. $this->_initLayoutMessages('install/session');
  376. $this->getLayout()->getBlock('content')->append(
  377. $this->getLayout()->createBlock('install/end', 'install.end')
  378. );
  379. $this->renderLayout();
  380. Mage::getSingleton('install/session')->clear();
  381. }
  382. /**
  383. * Host validation response
  384. */
  385. public function checkHostAction()
  386. {
  387. $this->getResponse()->setHeader('Transfer-encoding', '', true);
  388. $this->getResponse()->setBody(Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE);
  389. }
  390. /**
  391. * Host validation response
  392. */
  393. public function checkSecureHostAction()
  394. {
  395. $this->getResponse()->setHeader('Transfer-encoding', '', true);
  396. $this->getResponse()->setBody(Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE);
  397. }
  398. }