mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixing connection specific schema generation
Fixing missing table errors when reading schema for specific connections. Tests updated to check that tables not on a connection are never touched. Fixes #1106
This commit is contained in:
parent
d83907a77d
commit
5e26d282a1
2 changed files with 16 additions and 8 deletions
|
@ -234,17 +234,25 @@ class CakeSchema extends Object {
|
||||||
|
|
||||||
if (is_array($models)) {
|
if (is_array($models)) {
|
||||||
foreach ($models as $model) {
|
foreach ($models as $model) {
|
||||||
|
$importModel = $model;
|
||||||
if (isset($this->plugin)) {
|
if (isset($this->plugin)) {
|
||||||
$model = $this->plugin . '.' . $model;
|
$importModel = $this->plugin . '.' . $model;
|
||||||
}
|
}
|
||||||
|
if (!App::import('Model', $importModel)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$vars = get_class_vars($model);
|
||||||
|
if (empty($vars['useDbConfig']) || $vars['useDbConfig'] != $connection) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (PHP5) {
|
if (PHP5) {
|
||||||
$Object = ClassRegistry::init(array('class' => $model, 'ds' => null));
|
$Object = ClassRegistry::init(array('class' => $model, 'ds' => $connection));
|
||||||
} else {
|
} else {
|
||||||
$Object =& ClassRegistry::init(array('class' => $model, 'ds' => null));
|
$Object =& ClassRegistry::init(array('class' => $model, 'ds' => $connection));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($Object) && $Object->useTable !== false) {
|
if (is_object($Object) && $Object->useTable !== false) {
|
||||||
$Object->setDataSource($connection);
|
|
||||||
$table = $db->fullTableName($Object, false);
|
$table = $db->fullTableName($Object, false);
|
||||||
if (in_array($table, $currentTables)) {
|
if (in_array($table, $currentTables)) {
|
||||||
$key = array_search($table, $currentTables);
|
$key = array_search($table, $currentTables);
|
||||||
|
|
|
@ -658,17 +658,17 @@ class CakeSchemaTest extends CakeTestCase {
|
||||||
'name' => 'TestApp',
|
'name' => 'TestApp',
|
||||||
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
||||||
));
|
));
|
||||||
unset($read['tables']['missing']);
|
|
||||||
$this->assertTrue(isset($read['tables']['posts']));
|
$this->assertTrue(isset($read['tables']['posts']));
|
||||||
$this->assertFalse(isset($read['tables']['cross_database']));
|
$this->assertFalse(isset($read['tables']['cross_database']), 'Cross database should not appear');
|
||||||
|
$this->assertFalse(isset($read['tables']['missing']['cross_database']), 'Cross database should not appear');
|
||||||
|
|
||||||
$read = $this->Schema->read(array(
|
$read = $this->Schema->read(array(
|
||||||
'connection' => 'test2',
|
'connection' => 'test2',
|
||||||
'name' => 'TestApp',
|
'name' => 'TestApp',
|
||||||
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
'models' => array('SchemaCrossDatabase', 'SchemaPost')
|
||||||
));
|
));
|
||||||
unset($read['tables']['missing']);
|
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
|
||||||
$this->assertFalse(isset($read['tables']['posts']));
|
$this->assertFalse(isset($read['tables']['posts']), 'Posts should not appear');
|
||||||
$this->assertTrue(isset($read['tables']['cross_database']));
|
$this->assertTrue(isset($read['tables']['cross_database']));
|
||||||
|
|
||||||
$fixture->drop($db2);
|
$fixture->drop($db2);
|
||||||
|
|
Loading…
Reference in a new issue