updating schema, fixes #3816 and fixes #3896

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6367 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-01-12 17:06:28 +00:00
parent a9cd0f997d
commit ce1b042843

View file

@ -184,11 +184,12 @@ class CakeSchema extends Object {
)); ));
$db =& ConnectionManager::getDataSource($connection); $db =& ConnectionManager::getDataSource($connection);
$prefix = null;
App::import('Model', 'AppModel'); App::import('Model', 'AppModel');
$tables = array(); $tables = array();
$currentTables = $db->sources(); $currentTables = $db->listSources();
$prefix = null;
if (isset($db->config['prefix'])) { if (isset($db->config['prefix'])) {
$prefix = $db->config['prefix']; $prefix = $db->config['prefix'];
} }
@ -200,15 +201,16 @@ class CakeSchema extends Object {
if (is_array($models)) { if (is_array($models)) {
foreach ($models as $model) { foreach ($models as $model) {
if (!class_exists($model)) { if (PHP5) {
App::import('Model', $model); $Object = ClassRegistry::init($model);
} else {
$Object =& ClassRegistry::init($model);
} }
if (class_exists($model)) {
$Object =& new $model(); if (is_object($Object)) {
$Object->setDataSource($connection); $Object->setDataSource($connection);
$table = $db->fullTableName($Object, false); $table = $db->fullTableName($Object, false);
if (is_object($Object)) {
$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);
if (empty($tables[$Object->table])) { if (empty($tables[$Object->table])) {
@ -238,7 +240,6 @@ class CakeSchema extends Object {
} }
} }
} }
}
if (!empty($currentTables)) { if (!empty($currentTables)) {
foreach($currentTables as $table) { foreach($currentTables as $table) {
if ($prefix) { if ($prefix) {
@ -320,7 +321,7 @@ class CakeSchema extends Object {
} else { } else {
$col = "\t\t\t'indexes' => array("; $col = "\t\t\t'indexes' => array(";
$props = array(); $props = array();
foreach ($value as $key => $index) { foreach ((array)$value as $key => $index) {
$props[] = "'{$key}' => array(".join(', ', $this->__values($index)).")"; $props[] = "'{$key}' => array(".join(', ', $this->__values($index)).")";
} }
$col .= join(', ', $props); $col .= join(', ', $props);