Issues

ZF-10543: Zend_Application_Resource_Db && Zend_Application_Resource_Cachemanager

Issue Type: Bug Created: 2010-10-10T16:07:32.000+0000 Last Updated: 2010-11-18T16:03:10.000+0000 Status: Resolved Fix version(s): - 1.11.1 (30/Nov/10)

Reporter: Maksym Sliesarenko (sm) Assignee: Ramon Henrique Ornelas (ramon) Tags: - Zend_Application_Resource

Related issues: Attachments: - ZF-10543.patch

Description

Setting cache for Zend_Db with CacheManager

<pre class="highlight">
resources.db.defaultMetadataCache = database



<pre class="highlight">
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

Posted by Ramon Henrique Ornelas (ramon) on 2010-10-30T18:55:37.000+0000

Attached patch.

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

Posted by Ramon Henrique Ornelas (ramon) on 2010-11-11T03:25:29.000+0000

Here a simple code reproduced:

<pre class="highlight">
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'));

Posted by Ramon Henrique Ornelas (ramon) on 2010-11-18T15:25:17.000+0000

Attach patch with new test.

Posted by Ramon Henrique Ornelas (ramon) on 2010-11-18T16:03:10.000+0000

Fixed in r23383 merged to release branch 1.11 r23384.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts