ttt_external_db - Version 1.0.0

Version Notes

Developed and Tested on Magento 1.5.x

Download this release

Release Info

Developer Magento Core Team
Extension ttt_external_db
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/TTT/Edb/Helper/Data.php ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ class TTT_Edb_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
app/code/community/TTT/Edb/Model/Abstract.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class TTT_Edb_Model_Abstract extends Mage_Core_Model_Abstract
3
+ {
4
+
5
+ /* @var TTT_Edb_Model_Connection */
6
+ protected $_externalConnection;
7
+
8
+ public function __construct()
9
+ {
10
+ $this->_externalConnection = Mage::getModel('edb/connection');
11
+ }
12
+
13
+ /**
14
+ * Gets the External Connection Model
15
+ *
16
+ *@return TTT_Edb_Model_Connection
17
+ */
18
+ public function getExternalConnection()
19
+ {
20
+ return $this->_externalConnection;
21
+ }
22
+
23
+ public function getExternalReadConnection()
24
+ {
25
+ return $this->_externalConnection->getConnectionName();
26
+ }
27
+
28
+ public function getExternalWriteConnection()
29
+ {
30
+ return $this->_externalConnection->getConnectionName();
31
+ }
32
+ }
app/code/community/TTT/Edb/Model/Connection.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class TTT_Edb_Model_Connection
3
+ {
4
+ const XML_CONFIG_EDB_HOST = 'edb_settings/dbconnection/host';
5
+ const XML_CONFIG_EDB_DBNAME = 'edb_settings/dbconnection/dbname';
6
+ const XML_CONFIG_EDB_USERNAME = 'edb_settings/dbconnection/username';
7
+ const XML_CONFIG_EDB_PASSWORD = 'edb_settings/dbconnection/password';
8
+
9
+ const EXTERNAL_RESOURCE_NAME = 'edb_connection';
10
+
11
+ /*@var array */
12
+ protected $_config;
13
+
14
+ /*@var Varien_Db_Adapter_Pdo_Mysql */
15
+ protected $_connection;
16
+
17
+ public function __construct()
18
+ {
19
+ $this->_setConnection();
20
+ }
21
+ /**
22
+ * Gets the Config Settings in the Admin Settings for DB Connection
23
+ * @return array
24
+ */
25
+ public function getConfig()
26
+ {
27
+ if (!$this->_config) {
28
+ $this->_config = array();
29
+ // Setting the Values from the Admin Config
30
+ $this->_config['host'] = Mage::getStoreConfig(self::XML_CONFIG_EDB_HOST);
31
+ $this->_config['dbname'] = Mage::getStoreConfig(self::XML_CONFIG_EDB_DBNAME);
32
+ $this->_config['username'] = Mage::getStoreConfig(self::XML_CONFIG_EDB_USERNAME);
33
+ $this->_config['password'] = Mage::getStoreConfig(self::XML_CONFIG_EDB_PASSWORD);
34
+
35
+ // Setting the default Values
36
+ $this->_config['model'] = 'model';
37
+ $this->_config['initStatements'] = 'SET NAMES utf8';
38
+ $this->_config['type'] = 'pdo_mysql';
39
+
40
+ }
41
+ return $this->_config;
42
+ }
43
+
44
+ /**
45
+ * Gets External DB Connection Resource
46
+ *
47
+ * @return Varien_Db_Adapter_Pdo_Mysql
48
+ */
49
+ public function getConnection()
50
+ {
51
+ if (!$this->_connection) {
52
+ $this->_setConnection();
53
+ }
54
+ return $this->_connection;
55
+ }
56
+
57
+ private function _setConnection()
58
+ {
59
+ if (!$this->_connection) {
60
+ $this->_connection = Mage::getSingleton('core/resource')->createConnection(self::EXTERNAL_RESOURCE_NAME, 'pdo_mysql', $this->getConfig());
61
+ }
62
+ }
63
+
64
+ public static function getConnectionName()
65
+ {
66
+ return self::EXTERNAL_RESOURCE_NAME;
67
+ }
68
+
69
+ }
app/code/community/TTT/Edb/Model/Mysql4/Abstract.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class TTT_Edb_Model_Mysql4_Abstract extends Mage_Core_Model_Mysql4_Abstract
3
+ {
4
+
5
+ protected function _construct()
6
+ {
7
+
8
+ }
9
+
10
+ protected function _getConnection($connectionName)
11
+ {
12
+ //What Ever the Connection Name read or write we use the same connection name for everyting
13
+ $connection =$this->_resources->getConnection(TTT_Edb_Model_Connection::EXTERNAL_RESOURCE_NAME);
14
+ return $connection;
15
+ }
16
+
17
+ }
app/code/community/TTT/Edb/Model/Mysql4/Collection/Abstract.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class TTT_Edb_Model_Mysql4_Collection_Abstract extends Mage_Core_Model_Mysql4_Collection_Abstract
3
+ {
4
+
5
+ public function __construct()
6
+ {
7
+ $this->_construct();
8
+ // Setting the Connection
9
+ $read = $this->getResource()->getReadConnection();
10
+ $this->setConnection($read);
11
+ $this->_initSelect();
12
+ }
13
+ }
app/code/community/TTT/Edb/etc/config.xml ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <TTT_Edb>
5
+ <version>0.1.0</version>
6
+ </TTT_Edb>
7
+ </modules>
8
+ <adminhtml>
9
+ <acl>
10
+ <resources>
11
+ <all>
12
+ <title>Allow Everything</title>
13
+ </all>
14
+ <admin>
15
+ <children>
16
+ <system>
17
+ <children>
18
+ <config>
19
+ <children>
20
+ <edb_settings>
21
+ <title>EDB Settings</title>
22
+ </edb_settings>
23
+ </children>
24
+ </config>
25
+ </children>
26
+ </system>
27
+ </children>
28
+ </admin>
29
+ </resources>
30
+ </acl>
31
+ </adminhtml>
32
+ <global>
33
+ <models>
34
+ <edb>
35
+ <class>TTT_Edb_Model</class>
36
+ <resourceModel>edb_mysql4</resourceModel>
37
+ </edb>
38
+ <edb_mysql4>
39
+ <class>TTT_Edb_Model_Mysql4</class>
40
+ <entities>
41
+ <!-- Add As many tables config here -->
42
+ <report>
43
+ <table>report</table>
44
+ </report>
45
+ <!-- Add As many tables config here -->
46
+ </entities>
47
+ </edb_mysql4>
48
+ </models>
49
+ <!-- <resources>
50
+ <external_read>
51
+ <connection>
52
+ <host><![CDATA[localhost]]></host>
53
+ <username><![CDATA[root]]></username>
54
+ <password><![CDATA[root]]></password>
55
+ <dbname><![CDATA[riverfordreport]]></dbname>
56
+ <model>mysql4</model>
57
+ <initStatements>SET NAMES utf8</initStatements>
58
+ <type>pdo_mysql</type>
59
+ <active>1</active>
60
+ </connection>
61
+ </external_read>
62
+ </resources> -->
63
+ <helpers>
64
+ <edb>
65
+ <class>TTT_Edb_Helper</class>
66
+ </edb>
67
+ </helpers>
68
+ </global>
69
+
70
+ </config>
app/code/community/TTT/Edb/etc/system.xml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <tabs>
4
+ <edb_tab translate="label" module="edb">
5
+ <label>TTT EDB</label>
6
+ <sort_order>500</sort_order>
7
+ </edb_tab>
8
+ </tabs>
9
+ <sections>
10
+ <edb_settings translate="label" module="edb">
11
+ <label>External Database Connection</label>
12
+ <tab>edb_tab</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>1000</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>0</show_in_website>
17
+ <show_in_store>0</show_in_store>
18
+ <groups>
19
+ <dbconnection translate="label" module="edb">
20
+ <label>Database Host Settings</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort>1000</sort>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>0</show_in_website>
25
+ <show_in_store>0</show_in_store>
26
+ <fields>
27
+ <host translate="label,comment" module="edb">
28
+ <label>Database Host</label>
29
+ <comment>Host of the Database Server</comment>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>1</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>0</show_in_website>
34
+ <show_in_store>0</show_in_store>
35
+ </host>
36
+ <dbname translate="label,comment" module="edb">
37
+ <label>Database Name</label>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>1</sort_order>
40
+ <show_in_default>1</show_in_default>
41
+ <show_in_website>0</show_in_website>
42
+ <show_in_store>0</show_in_store>
43
+ </dbname>
44
+ <username translate="label,comment" module="edb">
45
+ <label>User Name</label>
46
+ <comment>User Name of the Database Server</comment>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>1</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>0</show_in_website>
51
+ <show_in_store>0</show_in_store>
52
+ </username>
53
+ <password translate="label,comment" module="edb">
54
+ <label>Password</label>
55
+ <frontend_type>password</frontend_type>
56
+ <comment>Password of the Database Server</comment>
57
+ <sort_order>1</sort_order>
58
+ <show_in_default>1</show_in_default>
59
+ <show_in_website>0</show_in_website>
60
+ <show_in_store>0</show_in_store>
61
+ </password>
62
+ </fields>
63
+ </dbconnection>
64
+ </groups>
65
+ </edb_settings>
66
+ </sections>
67
+ </config>
app/etc/modules/TTT_Edb.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <TTT_Edb>
5
+ <codePool>community</codePool>
6
+ <active>true</active>
7
+ </TTT_Edb>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ttt_external_db</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This is a external DB connector module. This will help in connecting to external databases other than Magento's Database.</summary>
10
+ <description>This is a external DB connector module. This will help in connecting to external databases other than Magento's Database.&#xD;
11
+ This supports both read and write connection. Using this module you don't have to worry about making connections just use the Magento standard Model Object creation and getting collections.</description>
12
+ <notes>Developed and Tested on Magento 1.5.x</notes>
13
+ <authors><author><name>The Three Tree</name><user>auto-converted</user><email>the3tree@gmail.com</email></author></authors>
14
+ <date>2011-04-12</date>
15
+ <time>09:42:10</time>
16
+ <contents><target name="magecommunity"><dir name="TTT"><dir name="Edb"><dir name="Helper"><file name="Data.php" hash="09f20e7089d258f357a9b57debacb7bb"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Collection"><file name="Abstract.php" hash="7fe36b66f9c4d3a9583ef4a6afb6e7ef"/></dir><file name="Abstract.php" hash="8d26cb5133bcee0544f075d317cd976b"/></dir><file name="Abstract.php" hash="162a381543f2ef0f84fc8e7f9b86f9c2"/><file name="Connection.php" hash="d6beb85d38e401b8cb81dbaad263d9e5"/></dir><dir name="etc"><file name="config.xml" hash="bd748ca75b43db62582d1d86cccecde5"/><file name="system.xml" hash="deab65cb13924f4456cd35814208a77f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="TTT_Edb.xml" hash="0d58442c2c4253f724b0b3ebfc300763"/></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies/>
19
+ </package>