Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Install_Block_Abstract
  • Mage_Install_Block_Admin
  • Mage_Install_Block_Begin
  • Mage_Install_Block_Config
  • Mage_Install_Block_Db_Main
  • Mage_Install_Block_Db_Type
  • Mage_Install_Block_Db_Type_Mysql4
  • Mage_Install_Block_Download
  • Mage_Install_Block_End
  • Mage_Install_Block_Locale
  • Mage_Install_Block_State
  • Mage_Install_Controller_Action
  • Mage_Install_Helper_Data
  • Mage_Install_IndexController
  • Mage_Install_Model_Config
  • Mage_Install_Model_Installer
  • Mage_Install_Model_Installer_Abstract
  • Mage_Install_Model_Installer_Config
  • Mage_Install_Model_Installer_Console
  • Mage_Install_Model_Installer_Data
  • Mage_Install_Model_Installer_Db
  • Mage_Install_Model_Installer_Db_Abstract
  • Mage_Install_Model_Installer_Db_Mysql4
  • Mage_Install_Model_Installer_Env
  • Mage_Install_Model_Installer_Filesystem
  • Mage_Install_Model_Installer_Pear
  • Mage_Install_Model_Observer
  • Mage_Install_Model_Session
  • Mage_Install_Model_Wizard
  • Mage_Install_WizardController
  • Overview
  • Package
  • Class
  • Tree
  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) 2012 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: /**
 28:  * DB Installer
 29:  *
 30:  * @category   Mage
 31:  * @package    Mage_Install
 32:  * @author      Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Install_Model_Installer_Db extends Mage_Install_Model_Installer_Abstract
 35: {
 36:     /**
 37:      * @var database resource
 38:      */
 39:     protected $_dbResource;
 40: 
 41:     /**
 42:      * Check database connection
 43:      * and return checked connection data
 44:      *
 45:      * @param array $data
 46:      * @return array
 47:      */
 48:     public function checkDbConnectionData($data)
 49:     {
 50:         $data = $this->_getCheckedData($data);
 51: 
 52:         try {
 53:             $dbModel = ($data['db_model']);
 54: 
 55:             if (!$resource = $this->_getDbResource($dbModel)) {
 56:                 Mage::throwException(Mage::helper('install')->__('No resource for %s DB model.', $dbModel));
 57:             }
 58: 
 59:             $resource->setConfig($data);
 60: 
 61:             // check required extensions
 62:             $absenteeExtensions = array();
 63:             $extensions = $resource->getRequiredExtensions();
 64:             foreach ($extensions as $extName) {
 65:                 if (!extension_loaded($extName)) {
 66:                     $absenteeExtensions[] = $extName;
 67:                 }
 68:             }
 69:             if (!empty($absenteeExtensions)) {
 70:                 Mage::throwException(
 71:                     Mage::helper('install')->__('PHP Extensions "%s" must be loaded.', implode(',', $absenteeExtensions))
 72:                 );
 73:             }
 74: 
 75:             $version    = $resource->getVersion();
 76:             $requiredVersion = (string) Mage::getConfig()
 77:                 ->getNode(sprintf('install/databases/%s/min_version', $dbModel));
 78: 
 79:             // check DB server version
 80:             if (version_compare($version, $requiredVersion) == -1) {
 81:                 Mage::throwException(
 82:                     Mage::helper('install')->__('The database server version doesn\'t match system requirements (required: %s, actual: %s).', $requiredVersion, $version)
 83:                 );
 84:             }
 85: 
 86:             // check InnoDB support
 87:             if (!$resource->supportEngine()) {
 88:                 Mage::throwException(
 89:                     Mage::helper('install')->__('Database server does not support the InnoDB storage engine.')
 90:                 );
 91:             }
 92: 
 93:             // TODO: check user roles
 94:         }
 95:         catch (Mage_Core_Exception $e) {
 96:             Mage::logException($e);
 97:             Mage::throwException(Mage::helper('install')->__($e->getMessage()));
 98:         }
 99:         catch (Exception $e) {
100:             Mage::logException($e);
101:             Mage::throwException(Mage::helper('install')->__('Database connection error.'));
102:         }
103: 
104:         return $data;
105:     }
106: 
107:     /**
108:      * Check database connection data
109:      *
110:      * @param  array $data
111:      * @return array
112:      */
113:     protected function _getCheckedData($data)
114:     {
115:         if (!isset($data['db_name']) || empty($data['db_name'])) {
116:             Mage::throwException(Mage::helper('install')->__('Database Name cannot be empty.'));
117:         }
118:         //make all table prefix to lower letter
119:         if ($data['db_prefix'] != '') {
120:            $data['db_prefix'] = strtolower($data['db_prefix']);
121:         }
122:         //check table prefix
123:         if ($data['db_prefix'] != '') {
124:             if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $data['db_prefix'])) {
125:                 Mage::throwException(
126:                     Mage::helper('install')->__('The table prefix should contain only letters (a-z), numbers (0-9) or underscores (_), the first character should be a letter.')
127:                 );
128:             }
129:         }
130:         //set default db model
131:         if (!isset($data['db_model']) || empty($data['db_model'])) {
132:             $data['db_model'] = Mage::getConfig()
133:                 ->getResourceConnectionConfig(Mage_Core_Model_Resource::DEFAULT_SETUP_RESOURCE)->model;
134:         }
135:         //set db type according the db model
136:         if (!isset($data['db_type'])) {
137:             $data['db_type'] = (string) Mage::getConfig()
138:                 ->getNode(sprintf('install/databases/%s/type', $data['db_model']));
139:         }
140: 
141:         $dbResource = $this->_getDbResource($data['db_model']);
142:         $data['db_pdo_type'] = $dbResource->getPdoType();
143: 
144:         if (!isset($data['db_init_statemants'])) {
145:             $data['db_init_statemants'] = (string) Mage::getConfig()
146:                 ->getNode(sprintf('install/databases/%s/initStatements', $data['db_model']));
147:         }
148: 
149:         return $data;
150:     }
151: 
152:     /**
153:      * Retrieve the database resource
154:      *
155:      * @param  string $model database type
156:      * @return Mage_Install_Model_Installer_Db_Abstract
157:      */
158:     protected function _getDbResource($model)
159:     {
160:         if (!isset($this->_dbResource)) {
161:             $resource =  Mage::getSingleton(sprintf('install/installer_db_%s', $model));
162:             if (!$resource) {
163:                 Mage::throwException(
164:                     Mage::helper('install')->__('Installer does not exist for %s database type', $model)
165:                 );
166:             }
167:             $this->_dbResource = $resource;
168:         }
169:         return $this->_dbResource;
170:     }
171: 
172:     /**
173:      * Retrieve Connection Type
174:      *
175:      * @return string
176:      *
177:      * @deprecated since 1.5.0.0
178:      */
179:     protected function _getConnenctionType()
180:     {
181:         return (string) Mage::getConfig()->getNode('global/resources/default_setup/connection/type');
182:     }
183: 
184: 
185:     /**
186:      * Check database connection
187:      *
188:      * @param array $data
189:      *
190:      * @deprecated since 1.5.0.0
191:      */
192:     public function checkDatabase($data)
193:     {
194:         $this->checkDbConnectionData($data);
195:     }
196: }
197: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0