From 99fd6e40fe994e836e035fc49ca151d7a04ce657 Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 19 Nov 2013 15:06:55 -0500 Subject: [PATCH 1/3] Leave db->cacheSources unaltered. When a model uses cacheSources = false, it should not have side effects on the datasource. Fixes #2364 --- lib/Cake/Model/Model.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 7517b620b..11de1e8c0 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1125,10 +1125,13 @@ class Model extends Object implements CakeEventListener { public function setSource($tableName) { $this->setDataSource($this->useDbConfig); $db = ConnectionManager::getDataSource($this->useDbConfig); - $db->cacheSources = ($this->cacheSources && $db->cacheSources); if (method_exists($db, 'listSources')) { + $restore = $db->cacheSources; + $db->cacheSources = $this->cacheSources; $sources = $db->listSources(); + $db->cacheSources = $restore; + if (is_array($sources) && !in_array(strtolower($this->tablePrefix . $tableName), array_map('strtolower', $sources))) { throw new MissingTableException(array( 'table' => $this->tablePrefix . $tableName, From ec38ee1c4800d150e8ee9684e613f718a8a972ba Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 19 Nov 2013 17:32:31 -0500 Subject: [PATCH 2/3] Only enable cacheSources if both the datasource + model agree on it. This prevents models from flipping cacheSources on when the datasource has it disabled already. Refs #2364 --- lib/Cake/Model/Model.php | 3 ++- lib/Cake/Test/Case/Model/ModelIntegrationTest.php | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 11de1e8c0..8797172e4 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -843,6 +843,7 @@ class Model extends Object implements CakeEventListener { } } + if (!$className) { return false; } @@ -1128,7 +1129,7 @@ class Model extends Object implements CakeEventListener { if (method_exists($db, 'listSources')) { $restore = $db->cacheSources; - $db->cacheSources = $this->cacheSources; + $db->cacheSources = ($restore && $this->cacheSources); $sources = $db->listSources(); $db->cacheSources = $restore; diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index b73cd8e6b..2eb194289 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -155,17 +155,17 @@ class ModelIntegrationTest extends BaseModelTest { } /** - * Tests that $cacheSources can only be disabled in the db using model settings, not enabled + * Tests that $cacheSources is restored despite the settings on the model. * * @return void */ - public function testCacheSourcesDisabling() { + public function testCacheSourcesRestored() { $this->loadFixtures('JoinA', 'JoinB', 'JoinAB', 'JoinC', 'JoinAC'); $this->db->cacheSources = true; $TestModel = new JoinA(); $TestModel->cacheSources = false; $TestModel->setSource('join_as'); - $this->assertFalse($this->db->cacheSources); + $this->assertTrue($this->db->cacheSources); $this->db->cacheSources = false; $TestModel = new JoinA(); From 1be40d5d64685c23bcb6d2beb149d62db766b68c Mon Sep 17 00:00:00 2001 From: mark_story Date: Tue, 19 Nov 2013 18:36:52 -0500 Subject: [PATCH 3/3] Fix coding standards error. Refs #2364 --- lib/Cake/Model/Model.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 8797172e4..2c1b66ce1 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -843,7 +843,6 @@ class Model extends Object implements CakeEventListener { } } - if (!$className) { return false; }