From 6a1cdf2138d9ab553e97d293816416db2d65e196 Mon Sep 17 00:00:00 2001 From: gwoo Date: Sat, 15 Mar 2008 05:45:43 +0000 Subject: [PATCH] updating bake and tasks, closes #4326, closes #3993, closes #4032, closes #4337 git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6574 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/console/libs/bake.php | 5 +++-- cake/console/libs/tasks/controller.php | 8 +++++++- cake/console/libs/tasks/db_config.php | 8 ++++++++ cake/console/libs/tasks/model.php | 23 +++++++++++++++++++++-- cake/console/libs/tasks/project.php | 7 +++---- cake/console/libs/tasks/view.php | 1 - 6 files changed, 42 insertions(+), 10 deletions(-) diff --git a/cake/console/libs/bake.php b/cake/console/libs/bake.php index 577d4cd7f..013f7cc10 100644 --- a/cake/console/libs/bake.php +++ b/cake/console/libs/bake.php @@ -41,7 +41,7 @@ class BakeShell extends Shell { * @var array * @access public */ - var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin'); + var $tasks = array('Project', 'DbConfig', 'Model', 'Controller', 'View', 'Plugin', 'Test'); /** * Override loadTasks() to handle paths * @@ -105,7 +105,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 D, 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.', true)); } $this->hr(); $this->main(); @@ -198,6 +198,7 @@ class BakeShell extends Shell { $this->out("\n\tbake help\n\t\tshows this help message."); $this->out("\n\tbake all \n\t\tbakes complete MVC. optional of a Model"); $this->out("\n\tbake project \n\t\tbakes a new app folder in the path supplied\n\t\tor in current directory if no path is specified"); + $this->out("\n\tbake plugin \n\t\tbakes a new plugin folder in the path supplied\n\t\tor in current directory if no path is specified."); $this->out("\n\tbake db_config\n\t\tbakes a database.php file in config directory."); $this->out("\n\tbake model\n\t\tbakes a model. run 'bake model help' for more info"); $this->out("\n\tbake view\n\t\tbakes views. run 'bake view help' for more info"); diff --git a/cake/console/libs/tasks/controller.php b/cake/console/libs/tasks/controller.php index b24280a4d..e59762c69 100644 --- a/cake/console/libs/tasks/controller.php +++ b/cake/console/libs/tasks/controller.php @@ -508,8 +508,14 @@ class ControllerTask extends Shell { } else { $tables = $db->listSources(); } + + if (empty($tables)) { + $this->err(__('Your database does not have any tables.', true)); + exit(); + } + $this->__tables = $tables; - $this->out('Possible Models based on your current database:'); + $this->out('Possible Controllers based on your current database:'); $this->_controllerNames = array(); $count = count($tables); for ($i = 0; $i < $count; $i++) { diff --git a/cake/console/libs/tasks/db_config.php b/cake/console/libs/tasks/db_config.php index 630d5b62c..d80eab1e1 100644 --- a/cake/console/libs/tasks/db_config.php +++ b/cake/console/libs/tasks/db_config.php @@ -71,6 +71,14 @@ class DbConfigTask extends Shell { while ($name == '') { $name = $this->in("Name:", null, 'default'); + if (preg_match('/[^a-z0-9_]/i', $name)) { + $name = ''; + $this->out('The name may only contain unaccented latin characters, numbers or underscores'); + } + else if (preg_match('/^[^a-z_]/i', $name)) { + $name = ''; + $this->out('The name must start with an unaccented latin character or an underscore'); + } } $driver = ''; diff --git a/cake/console/libs/tasks/model.php b/cake/console/libs/tasks/model.php index b5976acd7..c096b540e 100644 --- a/cake/console/libs/tasks/model.php +++ b/cake/console/libs/tasks/model.php @@ -47,6 +47,14 @@ class ModelTask extends Shell { * @access public */ var $path = MODELS; + +/** + * tasks + * + * @var array + * @access public + */ + var $tasks = array('DbConfig'); /** * Execution method always used for tasks * @@ -83,7 +91,13 @@ class ModelTask extends Shell { $associations = array('belongsTo'=> array(), 'hasOne'=> array(), 'hasMany' => array(), 'hasAndBelongsToMany'=> array()); $useDbConfig = 'default'; - $connections = array_keys(get_class_vars('DATABASE_CONFIG')); + $configs = get_class_vars('DATABASE_CONFIG'); + + if (!is_array($configs)) { + return $this->DbConfig->execute(); + } + + $connections = array_keys($configs); if (count($connections) > 1) { $useDbConfig = $this->in(__('Use Database Config', true) .':', $connections, 'default'); } @@ -196,7 +210,7 @@ class ModelTask extends Shell { } } } else { - $this->out('Bake Aborted.'); + return false; } } /** @@ -733,6 +747,11 @@ class ModelTask extends Shell { } else { $tables = $db->listSources(); } + if (empty($tables)) { + $this->err(__('Your database does not have any tables.', true)); + exit(); + } + $this->__tables = $tables; if ($interactive === true) { diff --git a/cake/console/libs/tasks/project.php b/cake/console/libs/tasks/project.php index d66f16cfe..426f43dd9 100644 --- a/cake/console/libs/tasks/project.php +++ b/cake/console/libs/tasks/project.php @@ -92,13 +92,13 @@ class ProjectTask extends Shell { while (!$response) { $response = $this->in("What is the full path for this app including the app directory name?\nExample: ".$this->params['root'] . DS . "myapp\n[Q]uit", null, 'Q'); if (strtoupper($response) === 'Q') { - $this->out('Bake Aborted'); + $this->out(__('Bake Aborted.', true)); exit(); } $this->params['working'] = null; $this->params['app'] = null; $this->execute($response); - exit(); + return true; } } } @@ -107,7 +107,7 @@ class ProjectTask extends Shell { while (!$project) { $project = $this->in("What is the full path for this app including the app directory name?\nExample: ".$this->params['root'] . DS . "myapp", null, $this->params['root'] . DS . 'myapp'); $this->execute($project); - exit(); + return true; } if($this->bake($project)) { @@ -137,7 +137,6 @@ class ProjectTask extends Shell { $this->out(sprintf(__('chmod -R 0777 %s', true), $path . DS .'tmp')); } } - exit(); } /** * Looks for a skeleton template of a Cake application, diff --git a/cake/console/libs/tasks/view.php b/cake/console/libs/tasks/view.php index ce7746347..a2db46dab 100644 --- a/cake/console/libs/tasks/view.php +++ b/cake/console/libs/tasks/view.php @@ -219,7 +219,6 @@ class ViewTask extends Shell { exit(); } else { $this->out('Bake Aborted.'); - exit(); } } }