00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class Mage_Install_WizardController extends Mage_Install_Controller_Action
00031 {
00032 public function preDispatch()
00033 {
00034 $this->setFlag('', self::FLAG_NO_CHECK_INSTALLATION, true);
00035 return parent::preDispatch();
00036 }
00037
00038
00039
00040
00041
00042
00043 protected function _getInstaller()
00044 {
00045 return Mage::getSingleton('install/installer');
00046 }
00047
00048
00049
00050
00051
00052
00053 protected function _getWizard()
00054 {
00055 return Mage::getSingleton('install/wizard');
00056 }
00057
00058
00059
00060
00061
00062
00063 protected function _prepareLayout()
00064 {
00065 $this->loadLayout('install_wizard');
00066 $step = $this->_getWizard()->getStepByRequest($this->getRequest());
00067 if ($step) {
00068 $step->setActive(true);
00069 }
00070
00071 $leftBlock = $this->getLayout()->createBlock('install/state', 'install.state');
00072 $this->getLayout()->getBlock('left')->append($leftBlock);
00073 return $this;
00074 }
00075
00076
00077
00078
00079
00080
00081 protected function _checkIfInstalled()
00082 {
00083 if ($this->_getInstaller()->isApplicationInstalled()) {
00084 $this->getResponse()->setRedirect(Mage::getBaseUrl())->sendResponse();
00085 exit;
00086 }
00087 return true;
00088 }
00089
00090
00091
00092
00093 public function indexAction()
00094 {
00095 $this->_forward('begin');
00096 }
00097
00098
00099
00100
00101 public function beginAction()
00102 {
00103 $this->_checkIfInstalled();
00104
00105 $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
00106 $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
00107
00108 $this->_prepareLayout();
00109 $this->_initLayoutMessages('install/session');
00110
00111 $this->getLayout()->getBlock('content')->append(
00112 $this->getLayout()->createBlock('install/begin', 'install.begin')
00113 );
00114
00115 $this->renderLayout();
00116 }
00117
00118
00119
00120
00121 public function beginPostAction()
00122 {
00123 $this->_checkIfInstalled();
00124
00125 $agree = $this->getRequest()->getPost('agree');
00126 if ($agree && $step = $this->_getWizard()->getStepByName('begin')) {
00127 $this->getResponse()->setRedirect($step->getNextUrl());
00128 }
00129 else {
00130 $this->_redirect('install');
00131 }
00132 }
00133
00134
00135
00136
00137 public function localeAction()
00138 {
00139 $this->_checkIfInstalled();
00140 $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
00141 $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
00142
00143 $this->_prepareLayout();
00144 $this->_initLayoutMessages('install/session');
00145 $this->getLayout()->getBlock('content')->append(
00146 $this->getLayout()->createBlock('install/locale', 'install.locale')
00147 );
00148
00149 $this->renderLayout();
00150 }
00151
00152
00153
00154
00155 public function localeChangeAction()
00156 {
00157 $this->_checkIfInstalled();
00158
00159 $locale = $this->getRequest()->getParam('locale');
00160 $timezone = $this->getRequest()->getParam('timezone');
00161 $currency = $this->getRequest()->getParam('currency');
00162 if ($locale) {
00163 Mage::getSingleton('install/session')->setLocale($locale);
00164 Mage::getSingleton('install/session')->setTimezone($timezone);
00165 Mage::getSingleton('install/session')->setCurrency($currency);
00166 }
00167
00168 $this->_redirect('*/*/locale');
00169 }
00170
00171
00172
00173
00174 public function localePostAction()
00175 {
00176 $this->_checkIfInstalled();
00177 $step = $this->_getWizard()->getStepByName('locale');
00178
00179 if ($data = $this->getRequest()->getPost('config')) {
00180 Mage::getSingleton('install/session')->setLocaleData($data);
00181 }
00182
00183 $this->getResponse()->setRedirect($step->getNextUrl());
00184 }
00185
00186 public function downloadAction()
00187 {
00188 $this->_checkIfInstalled();
00189 $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
00190 $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
00191
00192 $this->_prepareLayout();
00193 $this->_initLayoutMessages('install/session');
00194 $this->getLayout()->getBlock('content')->append(
00195 $this->getLayout()->createBlock('install/download', 'install.download')
00196 );
00197
00198 $this->renderLayout();
00199 }
00200
00201 public function downloadPostAction()
00202 {
00203 $this->_checkIfInstalled();
00204 switch ($this->getRequest()->getPost('continue')) {
00205 case 'auto':
00206 $this->_forward('downloadAuto');
00207 break;
00208
00209 case 'manual':
00210 $this->_forward('downloadManual');
00211 break;
00212
00213 case 'svn':
00214 $step = $this->_getWizard()->getStepByName('download');
00215 $this->getResponse()->setRedirect($step->getNextUrl());
00216 break;
00217
00218 default:
00219 $this->_redirect('*/*/download');
00220 }
00221 }
00222
00223 public function downloadAutoAction()
00224 {
00225 $step = $this->_getWizard()->getStepByName('download');
00226 $this->getResponse()->setRedirect($step->getNextUrl());
00227 }
00228
00229 public function installAction()
00230 {
00231 $pear = Varien_Pear::getInstance();
00232 $params = array('comment'=>Mage::helper('install')->__("Downloading and installing Magento, please wait...")."\r\n\r\n");
00233 if ($this->getRequest()->getParam('do')) {
00234 if ($state = $this->getRequest()->getParam('state', 'beta')) {
00235 $result = $pear->runHtmlConsole(array(
00236 'comment' => Mage::helper('install')->__("Setting preferred state to: %s", $state)."\r\n\r\n",
00237 'command' => 'config-set',
00238 'params' => array('preferred_state', $state)
00239 ));
00240 if ($result instanceof PEAR_Error) {
00241 $this->installFailureCallback();
00242 exit;
00243 }
00244 }
00245 $params['command'] = 'install';
00246 $params['options'] = array('onlyreqdeps'=>1);
00247 $params['params'] = Mage::getModel('install/installer_pear')->getPackages();
00248 $params['success_callback'] = array($this, 'installSuccessCallback');
00249 $params['failure_callback'] = array($this, 'installFailureCallback');
00250 }
00251 $pear->runHtmlConsole($params);
00252 Mage::app()->getFrontController()->getResponse()->clearAllHeaders();
00253 }
00254
00255 public function installSuccessCallback()
00256 {
00257 echo 'parent.installSuccess()';
00258 }
00259
00260 public function installFailureCallback()
00261 {
00262 echo 'parent.installFailure()';
00263 }
00264
00265 public function downloadManualAction()
00266 {
00267 $step = $this->_getWizard()->getStepByName('download');
00268 #if (!$this->_getInstaller()->checkDownloads()) {
00269 # $this->getResponse()->setRedirect($step->getUrl());
00270 #} else {
00271 $this->getResponse()->setRedirect($step->getNextUrl());
00272 #}
00273 }
00274
00275
00276
00277
00278 public function configAction()
00279 {
00280 $this->_checkIfInstalled();
00281 $this->_getInstaller()->checkServer();
00282
00283 $this->setFlag('', self::FLAG_NO_DISPATCH_BLOCK_EVENT, true);
00284 $this->setFlag('', self::FLAG_NO_POST_DISPATCH, true);
00285
00286 if ($data = $this->getRequest()->getQuery('config')) {
00287 Mage::getSingleton('install/session')->setLocaleData($data);
00288 }
00289
00290 $this->_prepareLayout();
00291 $this->_initLayoutMessages('install/session');
00292 $this->getLayout()->getBlock('content')->append(
00293 $this->getLayout()->createBlock('install/config', 'install.config')
00294 );
00295
00296 $this->renderLayout();
00297 }
00298
00299
00300
00301
00302 public function configPostAction()
00303 {
00304 $this->_checkIfInstalled();
00305 $step = $this->_getWizard()->getStepByName('config');
00306
00307 if ($data = $this->getRequest()->getPost('config')) {
00308
00309 if ($data['db_prefix'] !='') {
00310 $data['db_prefix'] = strtolower($data['db_prefix']);
00311 }
00312
00313 Mage::getSingleton('install/session')
00314 ->setConfigData($data)
00315 ->setSkipUrlValidation($this->getRequest()->getPost('skip_url_validation'))
00316 ->setSkipBaseUrlValidation($this->getRequest()->getPost('skip_base_url_validation'));
00317 try {
00318 if($data['db_prefix']!='') {
00319 if(!preg_match('/^[a-z]+[a-z0-9_]*$/',$data['db_prefix'])) {
00320 Mage::throwException(
00321 Mage::helper('install')->__('Table prefix should contain only letters (a-z), numbers (0-9) or underscore(_), first character should be a letter'));
00322 }
00323 }
00324 $this->_getInstaller()->installConfig($data);
00325 $this->_redirect('*/*/installDb');
00326 return $this;
00327 }
00328 catch (Exception $e){
00329 Mage::getSingleton('install/session')->addError($e->getMessage());
00330 $this->getResponse()->setRedirect($step->getUrl());
00331 }
00332 }
00333 $this->getResponse()->setRedirect($step->getUrl());
00334 }
00335
00336
00337
00338
00339 public function installDbAction()
00340 {
00341 $this->_checkIfInstalled();
00342 $step = $this->_getWizard()->getStepByName('config');
00343 try {
00344 $this->_getInstaller()->installDb();
00345
00346
00347
00348 Mage::getSingleton('install/session')->getConfigData(true);
00349
00350 Mage::app()->getStore()->resetConfig();
00351
00352 $this->getResponse()->setRedirect(Mage::getUrl($step->getNextUrlPath()));
00353 }
00354 catch (Exception $e){
00355 Mage::getSingleton('install/session')->addError($e->getMessage());
00356 $this->getResponse()->setRedirect($step->getUrl());
00357 }
00358 }
00359
00360
00361
00362
00363 public function administratorAction()
00364 {
00365 $this->_checkIfInstalled();
00366
00367 $this->_prepareLayout();
00368 $this->_initLayoutMessages('install/session');
00369
00370 $this->getLayout()->getBlock('content')->append(
00371 $this->getLayout()->createBlock('install/admin', 'install.administrator')
00372 );
00373 $this->renderLayout();
00374 }
00375
00376
00377
00378
00379 public function administratorPostAction()
00380 {
00381 $this->_checkIfInstalled();
00382
00383 $step = Mage::getSingleton('install/wizard')->getStepByName('administrator');
00384 $adminData = $this->getRequest()->getPost('admin');
00385 $encryptionKey = $this->getRequest()->getPost('encryption_key');
00386
00387 try {
00388 $this->_getInstaller()->createAdministrator($adminData)
00389 ->installEnryptionKey($encryptionKey);
00390 }
00391 catch (Exception $e){
00392 Mage::getSingleton('install/session')
00393 ->setAdminData($adminData)
00394 ->addError($e->getMessage());
00395 $this->getResponse()->setRedirect($step->getUrl());
00396 return false;
00397 }
00398 $this->getResponse()->setRedirect($step->getNextUrl());
00399 }
00400
00401
00402
00403
00404 public function endAction()
00405 {
00406 $this->_checkIfInstalled();
00407
00408 $date = (string)Mage::getConfig()->getNode('global/install/date');
00409 if ($date !== Mage_Install_Model_Installer_Config::TMP_INSTALL_DATE_VALUE) {
00410 $this->_redirect('*/*');
00411 return;
00412 }
00413
00414 $this->_getInstaller()->finish();
00415
00416 $this->_prepareLayout();
00417 $this->_initLayoutMessages('install/session');
00418
00419 $this->getLayout()->getBlock('content')->append(
00420 $this->getLayout()->createBlock('install/end', 'install.end')
00421 );
00422 $this->renderLayout();
00423 Mage::getSingleton('install/session')->clear();
00424 }
00425
00426
00427
00428
00429 public function checkHostAction()
00430 {
00431 $this->getResponse()->setHeader('Transfer-encoding', '', true);
00432 $this->getResponse()->setBody(Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE);
00433 }
00434
00435
00436
00437
00438 public function checkSecureHostAction()
00439 {
00440 $this->getResponse()->setHeader('Transfer-encoding', '', true);
00441 $this->getResponse()->setBody(Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE);
00442 }
00443 }