mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
cleaning up DbConfigTask
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6789 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b32a196238
commit
9982a30eea
1 changed files with 61 additions and 24 deletions
|
@ -49,9 +49,11 @@ class DbConfigTask extends Shell {
|
|||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $__defaultConfig = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
||||
var $__defaultConfig = array(
|
||||
'name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
|
||||
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
|
||||
'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null);
|
||||
'schema'=> null, 'prefix'=> null, 'encoding' => null, 'port' => null
|
||||
);
|
||||
/**
|
||||
* initialization callback
|
||||
*
|
||||
|
@ -172,9 +174,11 @@ class DbConfigTask extends Shell {
|
|||
}
|
||||
$schema = '';
|
||||
|
||||
if ($driver == 'postrges') {
|
||||
while ($schema == '') {
|
||||
$schema = $this->in('Table schema?', null, 'n');
|
||||
}
|
||||
}
|
||||
|
||||
if (low($schema) == 'n') {
|
||||
$schema = null;
|
||||
|
@ -214,13 +218,27 @@ class DbConfigTask extends Shell {
|
|||
$this->out("Driver: $driver");
|
||||
$this->out("Persistent: $persistent");
|
||||
$this->out("Host: $host");
|
||||
|
||||
if ($port) {
|
||||
$this->out("Port: $port");
|
||||
}
|
||||
|
||||
$this->out("User: $login");
|
||||
$this->out("Pass: " . str_repeat('*', strlen($password)));
|
||||
$this->out("Database: $database");
|
||||
|
||||
if ($prefix) {
|
||||
$this->out("Table prefix: $prefix");
|
||||
}
|
||||
|
||||
if ($schema) {
|
||||
$this->out("Schema: $schema");
|
||||
}
|
||||
|
||||
if ($encoding) {
|
||||
$this->out("Encoding: $encoding");
|
||||
}
|
||||
|
||||
$this->hr();
|
||||
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
|
||||
|
||||
|
@ -250,6 +268,8 @@ class DbConfigTask extends Shell {
|
|||
$temp = get_class_vars(get_class($db));
|
||||
|
||||
foreach ($temp as $configName => $info) {
|
||||
$info = array_merge($this->__defaultConfig, $info);
|
||||
|
||||
if (!isset($info['schema'])) {
|
||||
$info['schema'] = null;
|
||||
}
|
||||
|
@ -266,7 +286,8 @@ class DbConfigTask extends Shell {
|
|||
$info['persistent'] = 'false';
|
||||
}
|
||||
|
||||
$oldConfigs[] = array('name' => $configName,
|
||||
$oldConfigs[] = array(
|
||||
'name' => $configName,
|
||||
'driver' => $info['driver'],
|
||||
'persistent' => $info['persistent'],
|
||||
'host' => $info['host'],
|
||||
|
@ -276,7 +297,8 @@ class DbConfigTask extends Shell {
|
|||
'database' => $info['database'],
|
||||
'prefix' => $info['prefix'],
|
||||
'schema' => $info['schema'],
|
||||
'encoding' => $info['encoding']);
|
||||
'encoding' => $info['encoding']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,17 +317,32 @@ class DbConfigTask extends Shell {
|
|||
foreach ($configs as $config) {
|
||||
$config = array_merge($this->__defaultConfig, $config);
|
||||
extract($config);
|
||||
|
||||
$out .= "\tvar \${$name} = array(\n";
|
||||
$out .= "\t\t'driver' => '{$driver}',\n";
|
||||
$out .= "\t\t'persistent' => {$persistent},\n";
|
||||
$out .= "\t\t'host' => '{$host}',\n";
|
||||
|
||||
if ($port) {
|
||||
$out .= "\t\t'port' => {$port},\n";
|
||||
}
|
||||
|
||||
$out .= "\t\t'login' => '{$login}',\n";
|
||||
$out .= "\t\t'password' => '{$password}',\n";
|
||||
$out .= "\t\t'database' => '{$database}',\n";
|
||||
|
||||
if ($schema) {
|
||||
$out .= "\t\t'schema' => '{$schema}',\n";
|
||||
}
|
||||
|
||||
if ($prefix) {
|
||||
$out .= "\t\t'prefix' => '{$prefix}',\n";
|
||||
}
|
||||
|
||||
if ($encoding) {
|
||||
$out .= "\t\t'encoding' => '{$encoding}'\n";
|
||||
}
|
||||
|
||||
$out .= "\t);\n";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue