model and db_config task fixes

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5760 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-10-15 07:48:19 +00:00
parent 9c7f0755a5
commit 68c63b67f3
2 changed files with 21 additions and 16 deletions

View file

@ -36,6 +36,11 @@ if (!class_exists('File')) {
* @subpackage cake.cake.console.libs.tasks
*/
class DbConfigTask extends Shell {
var $__defaultConfig = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
'schema'=> null, 'prefix'=> null);
/**
* Execution method always used for tasks
@ -143,10 +148,7 @@ class DbConfigTask extends Shell {
* @return bool
*/
function __verify($config) {
$defaults = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
'schema'=> null,'prefix'=> null);
$config = am($defaults, $config);
$config = am($this->__defaultConfig, $config);
extract($config);
$this->out('');
$this->hr();
@ -165,7 +167,7 @@ class DbConfigTask extends Shell {
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
return true;
return $config;
}
return false;
}
@ -182,9 +184,10 @@ class DbConfigTask extends Shell {
}
$out = "<?php\n";
$out .= "class DATABASE_CONFIG {\n\n";
foreach ($configs as $config) {
extract($config);
$config = am($this->__defaultConfig, $config);
extract($config);
$out .= "\tvar \${$name} = array(\n";
$out .= "\t\t'driver' => '{$driver}',\n";
$out .= "\t\t'persistent' => {$persistent},\n";

View file

@ -750,8 +750,8 @@ class Model extends Overloadable {
$this->{$type}[$assocKey]['joinTable'] = $this->{$joinClass}->table;
}
if(count($this->{$joinClass}->_schema->value) > 2) {
if(isset($this->{$joinClass}->_schema->value['id'])) {
if (count($this->{$joinClass}->_schema->value) > 2) {
if (isset($this->{$joinClass}->_schema->value['id'])) {
$this->{$joinClass}->primaryKey = 'id';
}
}
@ -853,13 +853,15 @@ class Model extends Overloadable {
* @deprecated
*/
function loadInfo($clear = false) {
$info = $this->schema($clear);
$fields = array();
foreach($info->value as $field => $value) {
$fields[] = am(array('name'=> $field), $value);
if (!is_object($this->_tableInfo) || $clear) {
$info = $this->schema($clear);
$fields = array();
foreach($info->value as $field => $value) {
$fields[] = am(array('name'=> $field), $value);
}
unset($info);
$this->_tableInfo = new Set($fields);
}
unset($info);
$this->_tableInfo = new Set($fields);
return $this->_tableInfo;
}
/**
@ -1104,7 +1106,7 @@ class Model extends Overloadable {
}
} else {
foreach ($this->_tableInfo->value as $key => $value) {
if(in_array($this->primaryKey, $value)) {
if (in_array($this->primaryKey, $value)) {
if (empty($this->data[$this->name][$this->primaryKey]) && $this->_tableInfo->value[$key]['type'] === 'string' && $this->_tableInfo->value[$key]['length'] === 36) {
$fields[] = $this->primaryKey;
$values[] = String::uuid();