1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Install_Model_Installer extends Varien_Object
36: {
37:
38: 39: 40: 41:
42: const INSTALLER_HOST_RESPONSE = 'MAGENTO';
43:
44: 45: 46: 47: 48:
49: protected $_dataModel;
50:
51: 52: 53: 54: 55:
56: public function isApplicationInstalled()
57: {
58: return Mage::isInstalled();
59: }
60:
61: 62: 63: 64: 65:
66: public function getDataModel()
67: {
68: if (is_null($this->_dataModel)) {
69: $this->setDataModel(Mage::getSingleton('install/session'));
70: }
71: return $this->_dataModel;
72: }
73:
74: 75: 76: 77: 78: 79:
80: public function setDataModel(Varien_Object $model)
81: {
82: $this->_dataModel = $model;
83: return $this;
84: }
85:
86: 87: 88: 89: 90:
91: public function checkDownloads()
92: {
93: try {
94: $result = Mage::getModel('install/installer_pear')->checkDownloads();
95: $result = true;
96: } catch (Exception $e) {
97: $result = false;
98: }
99: $this->setDownloadCheckStatus($result);
100: return $result;
101: }
102:
103: 104: 105: 106: 107:
108: public function checkServer()
109: {
110: try {
111: Mage::getModel('install/installer_filesystem')->install();
112:
113: Mage::getModel('install/installer_env')->install();
114: $result = true;
115: } catch (Exception $e) {
116: $result = false;
117: }
118: $this->setData('server_check_status', $result);
119: return $result;
120: }
121:
122: 123: 124: 125: 126:
127: public function getServerCheckStatus()
128: {
129: $status = $this->getData('server_check_status');
130: if (is_null($status)) {
131: $status = $this->checkServer();
132: }
133: return $status;
134: }
135:
136: 137: 138: 139: 140: 141:
142: public function installConfig($data)
143: {
144: $data['db_active'] = true;
145:
146: $data = Mage::getSingleton('install/installer_db')->checkDbConnectionData($data);
147:
148: Mage::getSingleton('install/installer_config')
149: ->setConfigData($data)
150: ->install();
151: return $this;
152: }
153:
154: 155: 156: 157: 158:
159: public function installDb()
160: {
161: Mage_Core_Model_Resource_Setup::applyAllUpdates();
162: $data = $this->getDataModel()->getConfigData();
163:
164: 165: 166:
167: $setupModel = new Mage_Core_Model_Resource_Setup('core_setup');
168:
169: if (!empty($data['use_rewrites'])) {
170: $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_USE_REWRITES, 1);
171: }
172:
173: if (!empty($data['enable_charts'])) {
174: $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 1);
175: } else {
176: $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 0);
177: }
178:
179:
180: $unsecureBaseUrl = Mage::getBaseUrl('web');
181: if (!empty($data['unsecure_base_url'])) {
182: $unsecureBaseUrl = $data['unsecure_base_url'];
183: $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL, $unsecureBaseUrl);
184: }
185:
186: if (!empty($data['use_secure'])) {
187: $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND, 1);
188: $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $data['secure_base_url']);
189: if (!empty($data['use_secure_admin'])) {
190: $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_ADMINHTML, 1);
191: }
192: }
193: elseif (!empty($data['unsecure_base_url'])) {
194: $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $unsecureBaseUrl);
195: }
196:
197: 198: 199:
200: $locale = $this->getDataModel()->getLocaleData();
201: if (!empty($locale['locale'])) {
202: $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $locale['locale']);
203: }
204: if (!empty($locale['timezone'])) {
205: $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $locale['timezone']);
206: }
207: if (!empty($locale['currency'])) {
208: $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE, $locale['currency']);
209: $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT, $locale['currency']);
210: $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_ALLOW, $locale['currency']);
211: }
212:
213: return $this;
214: }
215:
216: 217: 218: 219: 220: 221: 222:
223: public function validateAndPrepareAdministrator($data)
224: {
225: $user = Mage::getModel('admin/user')
226: ->load($data['username'], 'username');
227: $user->addData($data);
228:
229: $result = $user->validate();
230: if (is_array($result)) {
231: foreach ($result as $error) {
232: $this->getDataModel()->addError($error);
233: }
234: return $result;
235: }
236: return $user;
237: }
238:
239: 240: 241: 242: 243: 244: 245: 246:
247: public function createAdministrator($data)
248: {
249: $user = Mage::getModel('admin/user')
250: ->load('admin', 'username');
251: if ($user && $user->getPassword() == '4297f44b13955235245b2497399d7a93') {
252: $user->delete();
253: }
254:
255:
256: if (is_array($data)) {
257: $data = $this->validateAndPrepareAdministrator($data);
258: if (is_array(data)) {
259: throw new Exception(Mage::helper('install')->__('Please correct the user data and try again.'));
260: }
261: }
262:
263:
264: $data->setForceNewPassword(true);
265:
266: $data->save();
267: $data->setRoleIds(array(1))->saveRelations();
268:
269: 270: 271: 272:
273:
274: return true;
275: }
276:
277: 278: 279: 280: 281: 282: 283:
284: public function validateEncryptionKey($key)
285: {
286: $errors = array();
287:
288: try {
289: if ($key) {
290: Mage::helper('core')->validateKey($key);
291: }
292: } catch (Exception $e) {
293: $errors[] = $e->getMessage();
294: $this->getDataModel()->addError($e->getMessage());
295: }
296:
297: if (!empty($errors)) {
298: return $errors;
299: }
300:
301: return true;
302: }
303:
304: 305: 306: 307: 308: 309:
310: public function installEnryptionKey($key)
311: {
312: if ($key) {
313: Mage::helper('core')->validateKey($key);
314: }
315: Mage::getSingleton('install/installer_config')->replaceTmpEncryptKey($key);
316: return $this;
317: }
318:
319: public function finish()
320: {
321: Mage::getSingleton('install/installer_config')->replaceTmpInstallDate();
322: Mage::app()->cleanCache();
323:
324: $cacheData = array();
325: foreach (Mage::helper('core')->getCacheTypes() as $type => $label) {
326: $cacheData[$type] = 1;
327: }
328: Mage::app()->saveUseCache($cacheData);
329: return $this;
330: }
331:
332: }
333: