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
This commit is contained in:
mark_story 2008-09-17 01:47:19 +00:00
parent 616fac0f99
commit 26a6a0e36f
2 changed files with 13 additions and 0 deletions

View file

@ -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));

View file

@ -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