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: * Abstract resource data model
29: *
30: * @category Mage
31: * @package Mage_Install
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: abstract class Mage_Install_Model_Installer_Db_Abstract
35: {
36: /**
37: * Adapter instance
38: *
39: * @var Varien_Db_Adapter_Interface
40: */
41: protected $_connection;
42:
43: /**
44: * Connection configuration
45: *
46: * @var array
47: */
48: protected $_connectionData;
49:
50: /**
51: * Connection configuration
52: *
53: * @var array
54: */
55: protected $_configData;
56:
57:
58: /**
59: * Return the name of DB model from config
60: *
61: * @return string
62: */
63: public function getModel()
64: {
65: return $this->_configData['db_model'];
66: }
67:
68:
69: /**
70: * Return the DB type from config
71: *
72: * @return string
73: */
74: public function getType()
75: {
76: return $this->_configData['db_type'];
77: }
78:
79: /**
80: * Set configuration data
81: *
82: * @param array $config the connection configuration
83: */
84: public function setConfig($config)
85: {
86: $this->_configData = $config;
87: }
88:
89: /**
90: * Retrieve connection data from config
91: *
92: * @return array
93: */
94: public function getConnectionData()
95: {
96: if (!$this->_connectionData) {
97: $connectionData = array(
98: 'host' => $this->_configData['db_host'],
99: 'username' => $this->_configData['db_user'],
100: 'password' => $this->_configData['db_pass'],
101: 'dbname' => $this->_configData['db_name'],
102: 'pdoType' => $this->getPdoType()
103: );
104: $this->_connectionData = $connectionData;
105: }
106: return $this->_connectionData;
107: }
108:
109: /**
110: * Check InnoDB support
111: *
112: * @return bool
113: */
114: public function supportEngine()
115: {
116: return true;
117: }
118:
119: /**
120: * Create new connection with custom config
121: *
122: * @return Varien_Db_Adapter_Interface
123: */
124: protected function _getConnection()
125: {
126: if (!isset($this->_connection)) {
127: $resource = Mage::getSingleton('core/resource');
128: $connection = $resource->createConnection('install', $this->getType(), $this->getConnectionData());
129: $this->_connection = $connection;
130: }
131: return $this->_connection;
132: }
133:
134: /**
135: * Return pdo type
136: *
137: * @return null
138: */
139: public function getPdoType()
140: {
141: return null;
142: }
143:
144: /**
145: * Retrieve required PHP extension list for database
146: *
147: * @return array
148: */
149: public function getRequiredExtensions()
150: {
151: $extensions = array();
152: $configExt = (array)Mage::getConfig()->getNode(sprintf('install/databases/%s/extensions', $this->getModel()));
153: foreach ($configExt as $name=>$value) {
154: $extensions[] = $name;
155: }
156: return $extensions;
157: }
158: }
159: