mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Leave db->cacheSources unaltered.
When a model uses cacheSources = false, it should not have side effects on the datasource. Fixes #2364
This commit is contained in:
parent
cc94026f7e
commit
99fd6e40fe
1 changed files with 4 additions and 1 deletions
|
@ -1125,10 +1125,13 @@ class Model extends Object implements CakeEventListener {
|
||||||
public function setSource($tableName) {
|
public function setSource($tableName) {
|
||||||
$this->setDataSource($this->useDbConfig);
|
$this->setDataSource($this->useDbConfig);
|
||||||
$db = ConnectionManager::getDataSource($this->useDbConfig);
|
$db = ConnectionManager::getDataSource($this->useDbConfig);
|
||||||
$db->cacheSources = ($this->cacheSources && $db->cacheSources);
|
|
||||||
|
|
||||||
if (method_exists($db, 'listSources')) {
|
if (method_exists($db, 'listSources')) {
|
||||||
|
$restore = $db->cacheSources;
|
||||||
|
$db->cacheSources = $this->cacheSources;
|
||||||
$sources = $db->listSources();
|
$sources = $db->listSources();
|
||||||
|
$db->cacheSources = $restore;
|
||||||
|
|
||||||
if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
|
if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) {
|
||||||
throw new MissingTableException(array(
|
throw new MissingTableException(array(
|
||||||
'table' => $this->tablePrefix . $tableName,
|
'table' => $this->tablePrefix . $tableName,
|
||||||
|
|
Loading…
Reference in a new issue