mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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:
parent
9c7f0755a5
commit
68c63b67f3
2 changed files with 21 additions and 16 deletions
|
@ -37,6 +37,11 @@ if (!class_exists('File')) {
|
||||||
*/
|
*/
|
||||||
class DbConfigTask extends Shell {
|
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
|
* Execution method always used for tasks
|
||||||
*
|
*
|
||||||
|
@ -143,10 +148,7 @@ class DbConfigTask extends Shell {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function __verify($config) {
|
function __verify($config) {
|
||||||
$defaults = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
$config = am($this->__defaultConfig, $config);
|
||||||
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
|
|
||||||
'schema'=> null,'prefix'=> null);
|
|
||||||
$config = am($defaults, $config);
|
|
||||||
extract($config);
|
extract($config);
|
||||||
$this->out('');
|
$this->out('');
|
||||||
$this->hr();
|
$this->hr();
|
||||||
|
@ -165,7 +167,7 @@ class DbConfigTask extends Shell {
|
||||||
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
|
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
|
||||||
|
|
||||||
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
|
||||||
return true;
|
return $config;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -184,6 +186,7 @@ class DbConfigTask extends Shell {
|
||||||
$out .= "class DATABASE_CONFIG {\n\n";
|
$out .= "class DATABASE_CONFIG {\n\n";
|
||||||
|
|
||||||
foreach ($configs as $config) {
|
foreach ($configs as $config) {
|
||||||
|
$config = am($this->__defaultConfig, $config);
|
||||||
extract($config);
|
extract($config);
|
||||||
$out .= "\tvar \${$name} = array(\n";
|
$out .= "\tvar \${$name} = array(\n";
|
||||||
$out .= "\t\t'driver' => '{$driver}',\n";
|
$out .= "\t\t'driver' => '{$driver}',\n";
|
||||||
|
|
|
@ -750,8 +750,8 @@ class Model extends Overloadable {
|
||||||
$this->{$type}[$assocKey]['joinTable'] = $this->{$joinClass}->table;
|
$this->{$type}[$assocKey]['joinTable'] = $this->{$joinClass}->table;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(count($this->{$joinClass}->_schema->value) > 2) {
|
if (count($this->{$joinClass}->_schema->value) > 2) {
|
||||||
if(isset($this->{$joinClass}->_schema->value['id'])) {
|
if (isset($this->{$joinClass}->_schema->value['id'])) {
|
||||||
$this->{$joinClass}->primaryKey = 'id';
|
$this->{$joinClass}->primaryKey = 'id';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -853,13 +853,15 @@ class Model extends Overloadable {
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
function loadInfo($clear = false) {
|
function loadInfo($clear = false) {
|
||||||
$info = $this->schema($clear);
|
if (!is_object($this->_tableInfo) || $clear) {
|
||||||
$fields = array();
|
$info = $this->schema($clear);
|
||||||
foreach($info->value as $field => $value) {
|
$fields = array();
|
||||||
$fields[] = am(array('name'=> $field), $value);
|
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;
|
return $this->_tableInfo;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -1104,7 +1106,7 @@ class Model extends Overloadable {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
foreach ($this->_tableInfo->value as $key => $value) {
|
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) {
|
if (empty($this->data[$this->name][$this->primaryKey]) && $this->_tableInfo->value[$key]['type'] === 'string' && $this->_tableInfo->value[$key]['length'] === 36) {
|
||||||
$fields[] = $this->primaryKey;
|
$fields[] = $this->primaryKey;
|
||||||
$values[] = String::uuid();
|
$values[] = String::uuid();
|
||||||
|
|
Loading…
Add table
Reference in a new issue