PageRenderTime 74ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/andrewjleavitt/magestudy
PHP | 330 lines | 171 code | 37 blank | 122 comment | 19 complexity | 805cacf26c5e9a13aee46a33ed243fe0 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  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@magentocommerce.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.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Install
  23. * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Installer model
  28. *
  29. * @category Mage
  30. * @package Mage_Install
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Install_Model_Installer extends Varien_Object
  34. {
  35. /**
  36. * Installer host response used to check urls
  37. *
  38. */
  39. const INSTALLER_HOST_RESPONSE = 'MAGENTO';
  40. /**
  41. * Installer data model used to store data between installation steps
  42. *
  43. * @var Varien_Object
  44. */
  45. protected $_dataModel;
  46. /**
  47. * Checking install status of application
  48. *
  49. * @return bool
  50. */
  51. public function isApplicationInstalled()
  52. {
  53. return Mage::isInstalled();
  54. }
  55. /**
  56. * Get data model
  57. *
  58. * @return Varien_Object
  59. */
  60. public function getDataModel()
  61. {
  62. if (is_null($this->_dataModel)) {
  63. $this->setDataModel(Mage::getSingleton('install/session'));
  64. }
  65. return $this->_dataModel;
  66. }
  67. /**
  68. * Set data model to store data between installation steps
  69. *
  70. * @param Varien_Object $model
  71. * @return Mage_Install_Model_Installer
  72. */
  73. public function setDataModel(Varien_Object $model)
  74. {
  75. $this->_dataModel = $model;
  76. return $this;
  77. }
  78. /**
  79. * Check packages (pear) downloads
  80. *
  81. * @return boolean
  82. */
  83. public function checkDownloads()
  84. {
  85. try {
  86. $result = Mage::getModel('install/installer_pear')->checkDownloads();
  87. $result = true;
  88. } catch (Exception $e) {
  89. $result = false;
  90. }
  91. $this->setDownloadCheckStatus($result);
  92. return $result;
  93. }
  94. /**
  95. * Check server settings
  96. *
  97. * @return bool
  98. */
  99. public function checkServer()
  100. {
  101. try {
  102. Mage::getModel('install/installer_filesystem')->install();
  103. Mage::getModel('install/installer_env')->install();
  104. $result = true;
  105. } catch (Exception $e) {
  106. $result = false;
  107. }
  108. $this->setData('server_check_status', $result);
  109. return $result;
  110. }
  111. /**
  112. * Retrieve server checking result status
  113. *
  114. * @return unknown
  115. */
  116. public function getServerCheckStatus()
  117. {
  118. $status = $this->getData('server_check_status');
  119. if (is_null($status)) {
  120. $status = $this->checkServer();
  121. }
  122. return $status;
  123. }
  124. /**
  125. * Installation config data
  126. *
  127. * @param array $data
  128. * @return Mage_Install_Model_Installer
  129. */
  130. public function installConfig($data)
  131. {
  132. $data['db_active'] = true;
  133. Mage::getSingleton('install/installer_db')->checkDatabase($data);
  134. Mage::getSingleton('install/installer_config')
  135. ->setConfigData($data)
  136. ->install();
  137. return $this;
  138. }
  139. /**
  140. * Database installation
  141. *
  142. * @return Mage_Install_Model_Installer
  143. */
  144. public function installDb()
  145. {
  146. Mage_Core_Model_Resource_Setup::applyAllUpdates();
  147. $data = $this->getDataModel()->getConfigData();
  148. /**
  149. * Saving host information into DB
  150. */
  151. $setupModel = new Mage_Core_Model_Resource_Setup('core_setup');
  152. if (!empty($data['use_rewrites'])) {
  153. $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_USE_REWRITES, 1);
  154. }
  155. if (!empty($data['enable_charts'])) {
  156. $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 1);
  157. } else {
  158. $setupModel->setConfigData(Mage_Adminhtml_Block_Dashboard::XML_PATH_ENABLE_CHARTS, 0);
  159. }
  160. $unsecureBaseUrl = Mage::getBaseUrl('web');
  161. if (!empty($data['unsecure_base_url'])) {
  162. $unsecureBaseUrl = $data['unsecure_base_url'];
  163. $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL, $unsecureBaseUrl);
  164. }
  165. if (!empty($data['use_secure'])) {
  166. $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_FRONTEND, 1);
  167. $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $data['secure_base_url']);
  168. if (!empty($data['use_secure_admin'])) {
  169. $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_IN_ADMINHTML, 1);
  170. }
  171. }
  172. elseif (!empty($data['unsecure_base_url'])) {
  173. $setupModel->setConfigData(Mage_Core_Model_Store::XML_PATH_SECURE_BASE_URL, $unsecureBaseUrl);
  174. }
  175. /**
  176. * Saving locale information into DB
  177. */
  178. $locale = $this->getDataModel()->getLocaleData();
  179. if (!empty($locale['locale'])) {
  180. $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $locale['locale']);
  181. }
  182. if (!empty($locale['timezone'])) {
  183. $setupModel->setConfigData(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $locale['timezone']);
  184. }
  185. if (!empty($locale['currency'])) {
  186. $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE, $locale['currency']);
  187. $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_DEFAULT, $locale['currency']);
  188. $setupModel->setConfigData(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_ALLOW, $locale['currency']);
  189. }
  190. return $this;
  191. }
  192. /**
  193. * Prepare admin user data in model and validate it.
  194. * Returns TRUE or array of error messages.
  195. *
  196. * @param array $data
  197. * @return mixed
  198. */
  199. public function validateAndPrepareAdministrator($data)
  200. {
  201. $user = Mage::getModel('admin/user')
  202. ->load($data['username'], 'username');
  203. $user->addData($data);
  204. $result = $user->validate();
  205. if (is_array($result)) {
  206. foreach ($result as $error) {
  207. $this->getDataModel()->addError($error);
  208. }
  209. return $result;
  210. }
  211. return $user;
  212. }
  213. /**
  214. * Create admin user.
  215. * Paramater can be prepared user model or array of data.
  216. * Returns TRUE or throws exception.
  217. *
  218. * @param mixed $data
  219. * @return bool
  220. */
  221. public function createAdministrator($data)
  222. {
  223. $user = Mage::getModel('admin/user')
  224. ->load('admin', 'username');
  225. if ($user && $user->getPassword()=='4297f44b13955235245b2497399d7a93') {
  226. $user->delete();
  227. }
  228. //to support old logic checking if real data was passed
  229. if (is_array($data)) {
  230. $data = $this->validateAndPrepareAdministrator($data);
  231. if (is_array(data)) {
  232. throw new Exception(Mage::helper('install')->__('Please correct the user data and try again.'));
  233. }
  234. }
  235. //run time flag to force saving entered password
  236. $data->setForceNewPassword(true);
  237. $data->save();
  238. $data->setRoleIds(array(1))->saveRelations();
  239. /*Mage::getModel("permissions/user")->setRoleId(1)
  240. ->setUserId($user->getId())
  241. ->setFirstname($user->getFirstname())
  242. ->add();*/
  243. return true;
  244. }
  245. /**
  246. * Validating encryption key.
  247. * Returns TRUE or array of error messages.
  248. *
  249. * @param $key
  250. * @return unknown_type
  251. */
  252. public function validateEncryptionKey($key)
  253. {
  254. $errors = array();
  255. try {
  256. if ($key) {
  257. Mage::helper('core')->validateKey($key);
  258. }
  259. } catch (Exception $e) {
  260. $errors[] = $e->getMessage();
  261. $this->getDataModel()->addError($e->getMessage());
  262. }
  263. if (!empty($errors)) {
  264. return $errors;
  265. }
  266. return true;
  267. }
  268. /**
  269. * Set encryption key
  270. *
  271. * @param string $key
  272. * @return Mage_Install_Model_Installer
  273. */
  274. public function installEnryptionKey($key)
  275. {
  276. if ($key) {
  277. Mage::helper('core')->validateKey($key);
  278. }
  279. Mage::getSingleton('install/installer_config')->replaceTmpEncryptKey($key);
  280. return $this;
  281. }
  282. public function finish()
  283. {
  284. Mage::getSingleton('install/installer_config')->replaceTmpInstallDate();
  285. Mage::app()->cleanCache();
  286. $cacheData = array();
  287. foreach (Mage::helper('core')->getCacheTypes() as $type=>$label) {
  288. $cacheData[$type] = 1;
  289. }
  290. Mage::app()->saveUseCache($cacheData);
  291. return $this;
  292. }
  293. }