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
00034
00035 class Mage_Install_Model_Installer extends Varien_Object
00036 {
00037
00038
00039
00040
00041
00042 const INSTALLER_HOST_RESPONSE = 'MAGENTO';
00043
00044
00045
00046
00047
00048
00049 protected $_dataModel;
00050
00051
00052
00053
00054
00055
00056 public function isApplicationInstalled()
00057 {
00058 return Mage::isInstalled();
00059 }
00060
00061
00062
00063
00064
00065
00066 public function getDataModel()
00067 {
00068 if (is_null($this->_dataModel)) {
00069 $this->setDataModel(Mage::getSingleton('install/session'));
00070 }
00071 return $this->_dataModel;
00072 }
00073
00074
00075
00076
00077
00078
00079
00080 public function setDataModel(Varien_Object $model)
00081 {
00082 $this->_dataModel = $model;
00083 return $this;
00084 }
00085
00086
00087
00088
00089
00090
00091 public function checkDownloads()
00092 {
00093 try {
00094 $result = Mage::getModel('install/installer_pear')->checkDownloads();
00095 $result = true;
00096 } catch (Exception $e) {
00097 $result = false;
00098 }
00099 $this->setDownloadCheckStatus($result);
00100 return $result;
00101 }
00102
00103
00104
00105
00106
00107
00108 public function checkServer()
00109 {
00110 try {
00111 Mage::getModel('install/installer_filesystem')->install();
00112
00113 Mage::getModel('install/installer_env')->install();
00114 $result = true;
00115 } catch (Exception $e) {
00116 $result = false;
00117 }
00118 $this->setData('server_check_status', $result);
00119 return $result;
00120 }
00121
00122
00123
00124
00125
00126
00127 public function getServerCheckStatus()
00128 {
00129 $status = $this->getData('server_check_status');
00130 if (is_null($status)) {
00131 $status = $this->checkServer();
00132 }
00133 return $status;
00134 }
00135
00136
00137
00138
00139
00140
00141
00142 public function installConfig($data)
00143 {
00144 $data['db_active'] = true;
00145 Mage::getSingleton('install/installer_db')->checkDatabase($data);
00146 Mage::getSingleton('install/installer_config')
00147 ->setConfigData($data)
00148 ->install();
00149 return $this;
00150 }
00151
00152
00153
00154
00155
00156
00157 public function installDb()
00158 {
00159 Mage_Core_Model_Resource_Setup::applyAllUpdates();
00160 $data = $this->getDataModel()->getConfigData();
00161
00162
00163
00164
00165 $setupModel = new Mage_Core_Model_Resource_Setup('core_setup');
00166
00167 if (!empty($data['use_rewrites'])) {
00168 $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_USE_REWRITES, 1);
00169 }
00170
00171 $unsecureBaseUrl = Mage::getBaseUrl('web');
00172 if (!empty($data['unsecure_base_url'])) {
00173 $unsecureBaseUrl = $data['unsecure_base_url'];
00174 $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL, $unsecureBaseUrl);
00175 }
00176
00177 if (!empty($data['use_secure'])) {
00178 $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND, 1);
00179 $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $data['secure_base_url']);
00180 if (!empty($data['use_secure_admin'])) {
00181 $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_ADMINHTML, 1);
00182 }
00183 }
00184 elseif (!empty($data['unsecure_base_url'])) {
00185 $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $unsecureBaseUrl);
00186 }
00187
00188
00189
00190
00191 $locale = $this->getDataModel()->getLocaleData();
00192 if (!empty($locale['locale'])) {
00193 $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $locale['locale']);
00194 }
00195 if (!empty($locale['timezone'])) {
00196 $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $locale['timezone']);
00197 }
00198 if (!empty($locale['currency'])) {
00199 $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE, $locale['currency']);
00200 $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT, $locale['currency']);
00201 $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_ALLOW, $locale['currency']);
00202 }
00203
00204 return $this;
00205 }
00206
00207
00208
00209
00210
00211
00212
00213 public function createAdministrator($data)
00214 {
00215 $user = Mage::getModel('admin/user')
00216 ->load('admin', 'username');
00217 if ($user && $user->getPassword()=='4297f44b13955235245b2497399d7a93') {
00218 $user->delete();
00219 }
00220
00221 $user = Mage::getModel('admin/user')
00222 ->load($data['username'], 'username');
00223 $user->addData($data)->save();
00224 $user->setRoleIds(array(1))->saveRelations();
00225
00226
00227
00228
00229
00230
00231 return $this;
00232 }
00233
00234
00235
00236
00237
00238
00239
00240 public function installEnryptionKey($key)
00241 {
00242 if ($key) {
00243 Mage::helper('core')->validateKey($key);
00244 }
00245 Mage::getSingleton('install/installer_config')->replaceTmpEncryptKey($key);
00246 return $this;
00247 }
00248
00249 public function finish()
00250 {
00251 Mage::getSingleton('install/installer_config')->replaceTmpInstallDate();
00252 Mage::app()->cleanCache();
00253
00254 $cacheData = array();
00255 foreach (Mage::helper('core')->getCacheTypes() as $type=>$label) {
00256 $cacheData[$type] = 1;
00257 }
00258 Mage::app()->saveUseCache($cacheData);
00259 return $this;
00260 }
00261
00262 }