ZF-7042: metadata cache identifier collisions

Description

The cache identifier where the metadata are saved is not unique:

  • schema is not mandatory, so if you have two databases with a same table name in both and you haven't set the schema it will generate the same id.
  • you can connect to databases on different host or port and it's also not include in the id so there are collisions.

$cacheId = md5("$this->_schema.$this->_name");

should be replace to :


//get db configuration
$dbConfig = $this->_db->getConfig();

//get the port if available 
$port = isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : null;

//get the custom schema or the default schema if not specified
$schema = !empty($this->_schema) ? $this->_schema : $dbConfig['dbname'];

// Define the cache identifier where the metadata are saved
$cacheId = md5($dbConfig['host'].$port.'/'.$schema.'.'.$this->_name);

Comments

Exactly the same for me today ;)

But with your correction, we can't have same schema in different database on same server.

I choose:


// If $this has a metadata cache
if (null !== $this->_metadataCache) {
    //get db configuration
    $dbConfig = $this->_db->getConfig();

    //get the port if available
    $port = isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : null;

    //get the host if available
    $host = isset($dbConfig['options']['host']) ? ':'.$dbConfig['options']['host'] : null;

    // Define the cache identifier where the metadata are saved
    $cacheId = md5($host.$port.'/'.$dbConfig['dbname'].':'.$this->_schema.'.'.$this->_name);
}

Used patch supplied.

Fixed in trunk in 17819, and merged to release branch 1.9 in 17820