|
|
@@ -32,6 +32,8 @@ require_once 'Zend/Db/Table.php';
|
|
|
*
|
|
|
* Example configuration:
|
|
|
* <pre>
|
|
|
+ * resources.multidb.defaultMetadataCache = "database"
|
|
|
+ *
|
|
|
* resources.multidb.db1.adapter = "pdo_mysql"
|
|
|
* resources.multidb.db1.host = "localhost"
|
|
|
* resources.multidb.db1.username = "webuser"
|
|
|
@@ -77,6 +79,11 @@ class Zend_Application_Resource_Multidb extends Zend_Application_Resource_Resour
|
|
|
{
|
|
|
$options = $this->getOptions();
|
|
|
|
|
|
+ if (isset($options['defaultMetadataCache'])) {
|
|
|
+ $this->_setDefaultMetadataCache($options['defaultMetadataCache']);
|
|
|
+ unset($options['defaultMetadataCache']);
|
|
|
+ }
|
|
|
+
|
|
|
foreach ($options as $id => $params) {
|
|
|
$adapter = $params['adapter'];
|
|
|
$default = (int) (
|
|
|
@@ -168,4 +175,36 @@ class Zend_Application_Resource_Multidb extends Zend_Application_Resource_Resour
|
|
|
Zend_Db_Table::setDefaultAdapter($adapter);
|
|
|
$this->_defaultDb = $adapter;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set the default metadata cache
|
|
|
+ *
|
|
|
+ * @param string|Zend_Cache_Core $cache
|
|
|
+ * @return Zend_Application_Resource_Multidb
|
|
|
+ */
|
|
|
+ protected function _setDefaultMetadataCache($cache)
|
|
|
+ {
|
|
|
+ $metadataCache = null;
|
|
|
+
|
|
|
+ if (is_string($cache)) {
|
|
|
+ $bootstrap = $this->getBootstrap();
|
|
|
+ if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
|
|
|
+ $bootstrap->hasPluginResource('CacheManager')
|
|
|
+ ) {
|
|
|
+ $cacheManager = $bootstrap->bootstrap('CacheManager')
|
|
|
+ ->getResource('CacheManager');
|
|
|
+ if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
|
|
|
+ $metadataCache = $cacheManager->getCache($cache);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if ($cache instanceof Zend_Cache_Core) {
|
|
|
+ $metadataCache = $cache;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($metadataCache instanceof Zend_Cache_Core) {
|
|
|
+ Zend_Db_Table::setDefaultMetadataCache($metadataCache);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
}
|