From 26a6a0e36f3f8ef8257e288f93db4db7fb37d739 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 17 Sep 2008 01:47:19 +0000 Subject: [PATCH] CakeSchema no longer takes tables that are not properly prefixed. Tests added to show prefixed db config and schema read. Closes #5413 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7613 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/schema.php | 6 ++++++ cake/tests/cases/libs/model/schema.test.php | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/cake/libs/model/schema.php b/cake/libs/model/schema.php index 9820d1454..3e84d96b6 100644 --- a/cake/libs/model/schema.php +++ b/cake/libs/model/schema.php @@ -169,6 +169,9 @@ class CakeSchema extends Object { * Reads database and creates schema tables * * @param array $options schema object properties + * 'connection' - the db connection to use + * 'name' - name of the schema + * 'models' - a list of models to use, or false to ignore models * @return array Array indexed by name and tables * @access public */ @@ -241,6 +244,9 @@ class CakeSchema extends Object { if (!empty($currentTables)) { foreach($currentTables as $table) { if ($prefix) { + if (strpos($table, $prefix) !== 0) { + continue; + } $table = str_replace($prefix, '', $table); } $Object = new AppModel(array('name' => Inflector::classify($table), 'table' => $table, 'ds' => $connection)); diff --git a/cake/tests/cases/libs/model/schema.test.php b/cake/tests/cases/libs/model/schema.test.php index d1969579d..191ad4244 100644 --- a/cake/tests/cases/libs/model/schema.test.php +++ b/cake/tests/cases/libs/model/schema.test.php @@ -387,6 +387,13 @@ class CakeSchemaTest extends CakeTestCase { unset($read['tables']['missing']); $this->assertEqual($read['tables'], $this->Schema->tables); $this->assertIdentical($read['tables']['datatypes']['float_field'], $this->Schema->tables['datatypes']['float_field']); + + $db =& ConnectionManager::getDataSource('test_suite'); + $config = $db->config; + $config['prefix'] = 'schema_test_prefix_'; + ConnectionManager::create('schema_prefix', $config); + $read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false)); + $this->assertTrue(empty($read['tables'])); } /** * testSchemaWrite method