Issues

ZF-10543: Zend_Application_Resource_Db && Zend_Application_Resource_Cachemanager

Description

Setting cache for Zend_Db with CacheManager


resources.db.defaultMetadataCache = database

public 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;
}

options in resources set before init() is called and $this->getBootstrap() returns null before init(), so first condition is useless.

rev 23076

Comments

Attached patch.

Forced the assignment of the object "bootstrap" in the start of the execution of the plugin resource.

Here a simple code reproduced:


require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();

$options = array(
    'resources' => array(
        'db'    => array(
            'adapter'  => 'Pdo_Sqlite',
            'params'   => array(
                'dbname'   => ':memory:'
             ),
             'defaultMetadataCache' => 'default'
        ),
        'cachemanager' => array(
            'default'  => array(
                'backend' => array('name' => 'black-hole')
            )
        )
    )
);
$application = new Zend_Application('testing', $options);
$application->bootstrap();

$resource = $application->getBootstrap()->getResource('cachemanager');
assert_options(ASSERT_ACTIVE, 1);
assert_options(ASSERT_WARNING, 1);
assert(Zend_Db_Table::getDefaultMetadataCache() == $resource->getCache('default'));

Attach patch with new test.

Fixed in r23383 merged to release branch 1.11 r23384.