PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Install/Model/Installer/Config.php

https://gitlab.com/LisovyiEvhenii/ismextensions
PHP | 191 lines | 130 code | 26 blank | 35 comment | 14 complexity | 6d712ce39c557e7170d3450401a66bad 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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Install
  23. * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Config installer
  28. * @category Mage
  29. * @package Mage_Install
  30. */
  31. class Mage_Install_Model_Installer_Config extends Mage_Install_Model_Installer_Abstract
  32. {
  33. const TMP_INSTALL_DATE_VALUE= 'd-d-d-d-d';
  34. const TMP_ENCRYPT_KEY_VALUE = 'k-k-k-k-k';
  35. /**
  36. * Path to local configuration file
  37. *
  38. * @var string
  39. */
  40. protected $_localConfigFile;
  41. protected $_configData = array();
  42. public function __construct()
  43. {
  44. $this->_localConfigFile = Mage::getBaseDir('etc') . DS . 'local.xml';
  45. }
  46. public function setConfigData($data)
  47. {
  48. if (is_array($data)) {
  49. $this->_configData = $data;
  50. }
  51. return $this;
  52. }
  53. public function getConfigData()
  54. {
  55. return $this->_configData;
  56. }
  57. public function install()
  58. {
  59. $data = $this->getConfigData();
  60. foreach (Mage::getModel('core/config')->getDistroServerVars() as $index=>$value) {
  61. if (!isset($data[$index])) {
  62. $data[$index] = $value;
  63. }
  64. }
  65. if (isset($data['unsecure_base_url'])) {
  66. $data['unsecure_base_url'] .= substr($data['unsecure_base_url'], -1) != '/' ? '/' : '';
  67. if (strpos($data['unsecure_base_url'], 'http') !== 0) {
  68. $data['unsecure_base_url'] = 'http://' . $data['unsecure_base_url'];
  69. }
  70. if (!$this->_getInstaller()->getDataModel()->getSkipBaseUrlValidation()) {
  71. $this->_checkUrl($data['unsecure_base_url']);
  72. }
  73. }
  74. if (isset($data['secure_base_url'])) {
  75. $data['secure_base_url'] .= substr($data['secure_base_url'], -1) != '/' ? '/' : '';
  76. if (strpos($data['secure_base_url'], 'http') !== 0) {
  77. $data['secure_base_url'] = 'https://' . $data['secure_base_url'];
  78. }
  79. if (!empty($data['use_secure'])
  80. && !$this->_getInstaller()->getDataModel()->getSkipUrlValidation()) {
  81. $this->_checkUrl($data['secure_base_url']);
  82. }
  83. }
  84. $data['date'] = self::TMP_INSTALL_DATE_VALUE;
  85. $data['key'] = self::TMP_ENCRYPT_KEY_VALUE;
  86. $data['var_dir'] = $data['root_dir'] . '/var';
  87. $data['use_script_name'] = isset($data['use_script_name']) ? 'true' : 'false';
  88. $this->_getInstaller()->getDataModel()->setConfigData($data);
  89. $template = file_get_contents(Mage::getBaseDir('etc') . DS . 'local.xml.template');
  90. foreach ($data as $index => $value) {
  91. $template = str_replace('{{' . $index . '}}', '<![CDATA[' . $value . ']]>', $template);
  92. }
  93. file_put_contents($this->_localConfigFile, $template);
  94. chmod($this->_localConfigFile, 0777);
  95. }
  96. public function getFormData()
  97. {
  98. $baseUrl = Mage::helper('core/url')->decodePunycode(Mage::getBaseUrl('web'));
  99. $uri = explode(':', $baseUrl, 2);
  100. $scheme = strtolower($uri[0]);
  101. $baseSecureUrl = ($scheme !== 'https') ? str_replace('http://', 'https://', $baseUrl) : $baseUrl;
  102. $connectDefault = Mage::getConfig()
  103. ->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_SETUP_RESOURCE);
  104. $data = Mage::getModel('varien/object')
  105. ->setDbHost($connectDefault->host)
  106. ->setDbName($connectDefault->dbname)
  107. ->setDbUser($connectDefault->username)
  108. ->setDbModel($connectDefault->model)
  109. ->setDbPass('')
  110. ->setSecureBaseUrl($baseSecureUrl)
  111. ->setUnsecureBaseUrl($baseUrl)
  112. ->setAdminFrontname('admin')
  113. ->setEnableCharts('1')
  114. ;
  115. return $data;
  116. }
  117. protected function _checkHostsInfo($data)
  118. {
  119. $url = $data['protocol'] . '://' . $data['host'] . ':' . $data['port'] . $data['base_path'];
  120. $surl = $data['secure_protocol'] . '://' . $data['secure_host'] . ':' . $data['secure_port']
  121. . $data['secure_base_path'];
  122. $this->_checkUrl($url);
  123. $this->_checkUrl($surl, true);
  124. return $this;
  125. }
  126. protected function _checkUrl($url, $secure = false)
  127. {
  128. $prefix = $secure ? 'install/wizard/checkSecureHost/' : 'install/wizard/checkHost/';
  129. try {
  130. $client = new Varien_Http_Client($url . 'index.php/' . $prefix);
  131. $response = $client->request('GET');
  132. /* @var $responce Zend_Http_Response */
  133. $body = $response->getBody();
  134. }
  135. catch (Exception $e){
  136. $this->_getInstaller()->getDataModel()
  137. ->addError(Mage::helper('install')->__('The URL "%s" is not accessible.', $url));
  138. throw $e;
  139. }
  140. if ($body != Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE) {
  141. $this->_getInstaller()->getDataModel()
  142. ->addError(Mage::helper('install')->__('The URL "%s" is invalid.', $url));
  143. Mage::throwException(Mage::helper('install')->__('Response from server isn\'t valid.'));
  144. }
  145. return $this;
  146. }
  147. public function replaceTmpInstallDate($date = null)
  148. {
  149. $stamp = strtotime((string) $date);
  150. $localXml = file_get_contents($this->_localConfigFile);
  151. $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, date('r', $stamp ? $stamp : time()), $localXml);
  152. file_put_contents($this->_localConfigFile, $localXml);
  153. return $this;
  154. }
  155. public function replaceTmpEncryptKey($key = null)
  156. {
  157. if (!$key) {
  158. $key = md5(Mage::helper('core')->getRandomString(10));
  159. }
  160. $localXml = file_get_contents($this->_localConfigFile);
  161. $localXml = str_replace(self::TMP_ENCRYPT_KEY_VALUE, $key, $localXml);
  162. file_put_contents($this->_localConfigFile, $localXml);
  163. return $this;
  164. }
  165. }