Skip to content

Commit 9d0cb18

Browse files
authored
OpenMage#1167 - do not connect to write adapter when getting the read adapter (OpenMage#1169)
* OpenMage#1167 - do not connect to write adapter when getting the read adapter * OpenMage#1167 - accidentally changed the return signature for _getReadAdapter()
1 parent e055833 commit 9d0cb18

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

app/code/core/Mage/Core/Model/Resource/Db/Abstract.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,18 +324,30 @@ protected function _getConnection($connectionName)
324324
return $this->_connections[$connectionName];
325325
}
326326

327+
/**
328+
* @param string $connectionName
329+
* @return bool
330+
*/
331+
public function hasConnection($connectionName)
332+
{
333+
return isset($this->_connections[$connectionName]);
334+
}
335+
327336
/**
328337
* Retrieve connection for read data
329338
*
330339
* @return Magento_Db_Adapter_Pdo_Mysql
331340
*/
332341
protected function _getReadAdapter()
333342
{
334-
$writeAdapter = $this->_getWriteAdapter();
335-
if ($writeAdapter && $writeAdapter->getTransactionLevel() > 0) {
336-
// if transaction is started we should use write connection for reading
337-
return $writeAdapter;
343+
if ($this->hasConnection('write')) {
344+
$writeAdapter = $this->_getWriteAdapter();
345+
if ($writeAdapter && $writeAdapter->getTransactionLevel() > 0) {
346+
// if transaction is started we should use write connection for reading
347+
return $writeAdapter;
348+
}
338349
}
350+
339351
return $this->_getConnection('read');
340352
}
341353

0 commit comments

Comments
 (0)