Skip to content

Commit

Permalink
#1167 - do not connect to write adapter when getting the read adapter (
Browse files Browse the repository at this point in the history
…#1169)

* #1167 - do not connect to write adapter when getting the read adapter

* #1167 - accidentally changed the return signature for _getReadAdapter()
  • Loading branch information
joshua-bn committed May 16, 2021
1 parent e055833 commit 9d0cb18
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app/code/core/Mage/Core/Model/Resource/Db/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,18 +324,30 @@ protected function _getConnection($connectionName)
return $this->_connections[$connectionName];
}

/**
* @param string $connectionName
* @return bool
*/
public function hasConnection($connectionName)
{
return isset($this->_connections[$connectionName]);
}

/**
* Retrieve connection for read data
*
* @return Magento_Db_Adapter_Pdo_Mysql
*/
protected function _getReadAdapter()
{
$writeAdapter = $this->_getWriteAdapter();
if ($writeAdapter && $writeAdapter->getTransactionLevel() > 0) {
// if transaction is started we should use write connection for reading
return $writeAdapter;
if ($this->hasConnection('write')) {
$writeAdapter = $this->_getWriteAdapter();
if ($writeAdapter && $writeAdapter->getTransactionLevel() > 0) {
// if transaction is started we should use write connection for reading
return $writeAdapter;
}
}

return $this->_getConnection('read');
}

Expand Down

0 comments on commit 9d0cb18

Please sign in to comment.