diff --git a/cake/console/libs/bake.php b/cake/console/libs/bake.php index c4789ad35..3593e7eda 100644 --- a/cake/console/libs/bake.php +++ b/cake/console/libs/bake.php @@ -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(); diff --git a/cake/console/libs/tasks/db_config.php b/cake/console/libs/tasks/db_config.php index 6296bbfa8..266415e0b 100644 --- a/cake/console/libs/tasks/db_config.php +++ b/cake/console/libs/tasks/db_config.php @@ -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 = " '{$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); } - } ?> \ No newline at end of file diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index b64ef0a36..5de2b4fce 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -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); diff --git a/cake/tests/cases/libs/folder.test.php b/cake/tests/cases/libs/folder.test.php index 8197350e5..8ffc0d97f 100644 --- a/cake/tests/cases/libs/folder.test.php +++ b/cake/tests/cases/libs/folder.test.php @@ -119,10 +119,6 @@ class FolderTest extends UnitTestCase { $result = $Folder->delete($mv); $this->assertTrue($result); - - //pr($Folder->messages()); - - //pr($Folder->errors()); } function testRealPathForWebroot() {