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
00031
00032
00033 class Mage_Install_Model_Installer_Config extends Mage_Install_Model_Installer_Abstract
00034 {
00035 const TMP_INSTALL_DATE_VALUE= 'd-d-d-d-d';
00036 const TMP_ENCRYPT_KEY_VALUE = 'k-k-k-k-k';
00037
00038
00039
00040
00041
00042
00043 protected $_localConfigFile;
00044
00045 protected $_configData = array();
00046
00047 public function __construct()
00048 {
00049 $this->_localConfigFile = Mage::getBaseDir('etc').DS.'local.xml';
00050 }
00051
00052 public function setConfigData($data)
00053 {
00054 if (is_array($data)) {
00055 $this->_configData = $data;
00056 }
00057 return $this;
00058 }
00059
00060 public function getConfigData()
00061 {
00062 return $this->_configData;
00063 }
00064
00065 public function install()
00066 {
00067 $data = $this->getConfigData();
00068 foreach (Mage::getModel('core/config')->getDistroServerVars() as $index=>$value) {
00069 if (!isset($data[$index])) {
00070 $data[$index] = $value;
00071 }
00072 }
00073
00074 if (isset($data['unsecure_base_url'])) {
00075 $data['unsecure_base_url'] .= substr($data['unsecure_base_url'],-1) != '/' ? '/' : '';
00076 if (!$this->_getInstaller()->getDataModel()->getSkipBaseUrlValidation()) {
00077 $this->_checkUrl($data['unsecure_base_url']);
00078 }
00079 }
00080 if (isset($data['secure_base_url'])) {
00081 $data['secure_base_url'] .= substr($data['secure_base_url'],-1) != '/' ? '/' : '';
00082
00083 if (!empty($data['use_secure'])
00084 && !$this->_getInstaller()->getDataModel()->getSkipUrlValidation()) {
00085 $this->_checkUrl($data['secure_base_url']);
00086 }
00087 }
00088
00089 $data['date'] = self::TMP_INSTALL_DATE_VALUE;
00090 $data['key'] = self::TMP_ENCRYPT_KEY_VALUE;
00091 $data['var_dir'] = $data['root_dir'] . '/var';
00092
00093 $data['use_script_name'] = isset($data['use_script_name']) ? 'true' : 'false';
00094
00095 $this->_getInstaller()->getDataModel()->setConfigData($data);
00096
00097 $template = file_get_contents(Mage::getBaseDir('etc').DS.'local.xml.template');
00098 foreach ($data as $index=>$value) {
00099 $template = str_replace('{{'.$index.'}}', '<![CDATA['.$value.']]>', $template);
00100 }
00101 file_put_contents($this->_localConfigFile, $template);
00102 chmod($this->_localConfigFile, 0777);
00103 }
00104
00105 public function getFormData()
00106 {
00107 $uri = Zend_Uri::factory(Mage::getBaseUrl('web'));
00108
00109 $baseUrl = $uri->getUri();
00110 if ($uri->getScheme()!=='https') {
00111 $uri->setPort(null);
00112 $baseSecureUrl = str_replace('http://', 'https://', $uri->getUri());
00113 } else {
00114 $baseSecureUrl = $uri->getUri();
00115 }
00116
00117 $data = Mage::getModel('varien/object')
00118 ->setDbHost('localhost')
00119 ->setDbName('magento')
00120 ->setDbUser('root')
00121 ->setDbPass('')
00122 ->setSecureBaseUrl($baseSecureUrl)
00123 ->setUnsecureBaseUrl($baseUrl)
00124 ->setAdminFrontname('admin')
00125 ;
00126 return $data;
00127 }
00128
00129 protected function _checkHostsInfo($data)
00130 {
00131 $url = $data['protocol'] . '://' . $data['host'] . ':' . $data['port'] . $data['base_path'];
00132 $surl= $data['secure_protocol'] . '://' . $data['secure_host'] . ':' . $data['secure_port'] . $data['secure_base_path'];
00133
00134 $this->_checkUrl($url);
00135 $this->_checkUrl($surl, true);
00136
00137 return $this;
00138 }
00139
00140 protected function _checkUrl($url, $secure=false)
00141 {
00142 $prefix = $secure ? 'install/wizard/checkSecureHost/' : 'install/wizard/checkHost/';
00143 $client = new Varien_Http_Client($url.'index.php/'.$prefix);
00144 try {
00145 $response = $client->request('GET');
00146
00147 $body = $response->getBody();
00148 }
00149 catch (Exception $e){
00150 $this->_getInstaller()->getDataModel()->addError(Mage::helper('install')->__('Url "%s" is not accessible', $url));
00151 throw $e;
00152 }
00153
00154 if ($body != Mage_Install_Model_Installer::INSTALLER_HOST_RESPONSE) {
00155 $this->_getInstaller()->getDataModel()->addError(Mage::helper('install')->__('Url "%s" is invalid', $url));
00156 Mage::throwException(Mage::helper('install')->__('This Url is invalid'));
00157 }
00158 return $this;
00159 }
00160
00161 public function replaceTmpInstallDate($date = null)
00162 {
00163 if (is_null($date)) {
00164 $date = date('r');
00165 }
00166 $localXml = file_get_contents($this->_localConfigFile);
00167 $localXml = str_replace(self::TMP_INSTALL_DATE_VALUE, date('r'), $localXml);
00168 file_put_contents($this->_localConfigFile, $localXml);
00169
00170 return $this;
00171 }
00172
00173 public function replaceTmpEncryptKey($key = null)
00174 {
00175 if (!$key) {
00176 $key = md5(time());
00177 }
00178 $localXml = file_get_contents($this->_localConfigFile);
00179 $localXml = str_replace(self::TMP_ENCRYPT_KEY_VALUE, $key, $localXml);
00180 file_put_contents($this->_localConfigFile, $localXml);
00181
00182 return $this;
00183 }
00184 }