Fixes #1166, bake.php ability to supply alternate database configurations.

Removed debug code from FolderTest

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5640 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-09-15 20:23:30 +00:00
parent e7b3d24e18
commit b91f9b087d
4 changed files with 101 additions and 84 deletions

View file

@ -51,13 +51,17 @@ class BakeShell extends Shell {
}
$this->out('Interactive Bake Shell');
$this->hr();
$this->out('[D]atabase Configuration');
$this->out('[M]odel');
$this->out('[V]iew');
$this->out('[C]ontroller');
$this->out('[Q]uit');
$classToBake = strtoupper($this->in('What would you like to Bake?', array('M', 'V', 'C', 'Q')));
$classToBake = strtoupper($this->in('What would you like to Bake?', array('D', 'M', 'V', 'C', 'Q')));
switch($classToBake) {
case 'D':
$this->DbConfig->execute();
break;
case 'M':
$this->Model->execute();
break;
@ -71,7 +75,7 @@ class BakeShell extends Shell {
exit(0);
break;
default:
$this->out('You have made an invalid selection. Please choose a type of class to Bake by entering M, V, or C.');
$this->out('You have made an invalid selection. Please choose a type of class to Bake by entering D, M, V, or C.');
}
$this->hr();
$this->main();

View file

@ -47,6 +47,7 @@ class DbConfigTask extends Shell {
$this->__interactive();
}
}
/**
* Interactive interface
*
@ -54,64 +55,83 @@ class DbConfigTask extends Shell {
* @return void
*/
function __interactive() {
$this->out('Database Configuration:');
$driver = '';
while ($driver == '') {
$driver = $this->in('Driver:', array('mysql','mysqli','mssql','sqlite','postgres', 'odbc', 'oracle', 'db2'), 'mysql');
}
$done = false;
$dbConfigs = array();
$persistent = '';
while ($persistent == '') {
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
}
if (low($persistent) == 'n') {
$persistent = 'false';
} else {
$persistent = 'true';
}
while ($done == false) {
$name = '';
$host = '';
while ($host == '') {
$host = $this->in('Database Host:', null, 'localhost');
}
while ($name == '') {
$name = $this->in("Name:", null, 'default');
}
$driver = '';
$login = '';
while ($login == '') {
$login = $this->in('User:', null, 'root');
}
while ($driver == '') {
$driver = $this->in('Driver:', array('mysql','mysqli','mssql','sqlite','postgres', 'odbc', 'oracle', 'db2'), 'mysql');
}
$persistent = '';
$password = '';
$blankPassword = false;
while ($password == '' && $blankPassword == false) {
$password = $this->in('Password:');
if ($password == '') {
$blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
if ($blank == 'y')
{
$blankPassword = true;
while ($persistent == '') {
$persistent = $this->in('Persistent Connection?', array('y', 'n'), 'n');
}
if (low($persistent) == 'n') {
$persistent = 'false';
} else {
$persistent = 'true';
}
$host = '';
while ($host == '') {
$host = $this->in('Database Host:', null, 'localhost');
}
$login = '';
while ($login == '') {
$login = $this->in('User:', null, 'root');
}
$password = '';
$blankPassword = false;
while ($password == '' && $blankPassword == false) {
$password = $this->in('Password:');
if ($password == '') {
$blank = $this->in('The password you supplied was empty. Use an empty password?', array('y', 'n'), 'n');
if ($blank == 'y')
{
$blankPassword = true;
}
}
}
}
$database = '';
$database = '';
while ($database == '') {
$database = $this->in('Database Name:', null, 'cake');
}
while ($database == '') {
$database = $this->in('Database Name:', null, 'cake');
}
$prefix = '';
$prefix = '';
while ($prefix == '') {
$prefix = $this->in('Table Prefix?', null, 'n');
}
if (low($prefix) == 'n') {
$prefix = null;
}
while ($prefix == '') {
$prefix = $this->in('Table Prefix?', null, 'n');
}
$config = compact('driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix');
while ($this->__verify($config) == false) {
$this->__interactive();
}
if (low($prefix) == 'n') {
$prefix = null;
}
$config = compact('name', 'driver', 'persistent', 'host', 'login', 'password', 'database', 'prefix');
while ($this->__verify($config) == false) {
$this->__interactive();
}
$dbConfigs[] = $config;
$doneYet = $this->in('Do you wish to add another database configuration?', null, 'n');
if (low($doneYet == 'n')) {
$done = true;
}
}
$this->bake($dbConfigs);
config('database');
return true;
}
@ -123,16 +143,16 @@ class DbConfigTask extends Shell {
* @return bool
*/
function __verify($config) {
$defaults = array('driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
'schema'=> null,'prefix'=> null);
$defaults = array('name' => 'default', 'driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
'schema'=> null,'prefix'=> null, 'schema' => null);
$config = am($defaults, $config);
extract($config);
$this->out('');
$this->hr();
$this->out('The following database configuration will be created:');
$this->hr();
$this->out("Name: $name");
$this->out("Driver: $driver");
$this->out("Persistent: $persistent");
$this->out("Host: $host");
@ -140,14 +160,14 @@ class DbConfigTask extends Shell {
$this->out("Pass: " . str_repeat('*', strlen($password)));
$this->out("Database: $database");
$this->out("Table prefix: $prefix");
$this->out("Schema: $schema");
$this->hr();
$looksGood = $this->in('Look okay?', array('y', 'n'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
return $this->bake($config);
} else {
return false;
return true;
}
return false;
}
/**
* Assembles and writes database.php
@ -155,37 +175,34 @@ class DbConfigTask extends Shell {
* @access public
* @return bool
*/
function bake($config) {
$defaults = array('driver'=> 'mysql', 'persistent'=> 'false', 'host'=> 'localhost',
'login'=> 'root', 'password'=> 'password', 'database'=> 'project_name',
'schema'=> null,'prefix'=> null);
$config = am($defaults, $config);
extract($config);
function bake($configs) {
if (!is_dir(CONFIGS)) {
$this->err(CONFIGS .' not found');
return false;
}
$out = "<?php\n";
$out .= "class DATABASE_CONFIG {\n\n";
if (is_dir(CONFIGS)) {
$out = "<?php\n";
$out .= "class DATABASE_CONFIG {\n\n";
$out .= "\tvar \$default = array(\n";
foreach ($configs as $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";
$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";
}
$out .= "\t\t'prefix' => '{$prefix}' \n";
$out .= "\t);\n";
$out .= "}\n";
$out .= "?>";
$filename = CONFIGS.'database.php';
return $this->createFile($filename, $out);
} else {
$this->err(CONFIGS .' not found');
}
return false;
$out .= "}\n";
$out .= "?>";
$filename = CONFIGS.'database.php';
return $this->createFile($filename, $out);
}
}
?>

View file

@ -69,14 +69,14 @@ class ModelTask extends Shell {
$primaryKey = 'id';
$validate = array();
$associations = array('belongsTo'=> array(), 'hasOne'=> array(), 'hasMany', 'hasAndBelongsToMany'=> array());
/*$usingDefault = $this->in('Will your model be using a database connection setting other than the default?');
if (low($usingDefault) == 'y' || low($usingDefault) == 'yes')
{
$useDbConfig = $this->in('Please provide the name of the connection you wish to use.');
}*/
$usingDefault = $this->in('Will your model be using a database connection setting other than the default?');
$useDbConfig = 'default';
$currentModelName = $this->getName($useDbConfig);
if (low($usingDefault) == 'y' || low($usingDefault) == 'yes') {
$useDbConfig = $this->in('Please provide the name of the connection you wish to use.');
}
$currentModelName = $this->getName($useDbConfig);
$db =& ConnectionManager::getDataSource($useDbConfig);
$tableIsGood = false;
$useTable = Inflector::tableize($currentModelName);

View file

@ -119,10 +119,6 @@ class FolderTest extends UnitTestCase {
$result = $Folder->delete($mv);
$this->assertTrue($result);
//pr($Folder->messages());
//pr($Folder->errors());
}
function testRealPathForWebroot() {