From c2a53d3c6972865b7e72262b8bf12df790c96ae3 Mon Sep 17 00:00:00 2001 From: mark_story Date: Sun, 4 Oct 2009 11:16:23 -0400 Subject: [PATCH] Removing `cake schema run`. Replacing it with `cake schema create` and `cake schema update`. Removes extra typing and simplifies schema shell commands. Updating test cases. --- cake/console/libs/schema.php | 51 +++++++++---------- cake/tests/cases/console/libs/schema.test.php | 14 +++-- 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/cake/console/libs/schema.php b/cake/console/libs/schema.php index be2b88801..6dc10da1b 100644 --- a/cake/console/libs/schema.php +++ b/cake/console/libs/schema.php @@ -238,20 +238,31 @@ class SchemaShell extends Shell { } /** - * Run database commands: create, update + * Run database create commands. Alias for run create. * - * @access public - */ - function run() { - if (!isset($this->args[0])) { - $this->err(__('Command not found', true)); - $this->_stop(); - } + * @return void + **/ + function create() { + list($Schema, $table) = $this->_loadSchema(); + $this->__create($Schema, $table); + } - $command = $this->args[0]; - - $this->Dispatch->shiftArgs(); +/** + * Run database create commands. Alias for run create. + * + * @return void + **/ + function update() { + list($Schema, $table) = $this->_loadSchema(); + $this->__update($Schema, $table); + } +/** + * Prepares the Schema objects for database operations. + * + * @return void + **/ + function _loadSchema() { $name = null; if (isset($this->args[0])) { $name = $this->args[0]; @@ -271,29 +282,17 @@ class SchemaShell extends Shell { $options['file'] = $fileName . '_' . $this->params['s'] . '.php'; } - $Schema = $this->Schema->load($options); + $Schema =& $this->Schema->load($options); if (!$Schema) { $this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file)); $this->_stop(); } - $table = null; if (isset($this->args[1])) { $table = $this->args[1]; } - - switch ($command) { - case 'create': - $this->__create($Schema, $table); - break; - case 'update': - $this->__update($Schema, $table); - break; - default: - $this->err(__('Command not found', true)); - $this->_stop(); - } + return array(&$Schema, $table); } /** @@ -336,7 +335,6 @@ class SchemaShell extends Shell { $this->out(__('Creating table(s).', true)); $this->__run($create, 'create', $Schema); } - $this->out(__('End create.', true)); } @@ -395,7 +393,6 @@ class SchemaShell extends Shell { } Configure::write('debug', 2); $db =& ConnectionManager::getDataSource($this->Schema->connection); - $db->fullDebug = true; foreach ($contents as $table => $sql) { if (empty($sql)) { diff --git a/cake/tests/cases/console/libs/schema.test.php b/cake/tests/cases/console/libs/schema.test.php index 79929f050..14b9cf7ce 100644 --- a/cake/tests/cases/console/libs/schema.test.php +++ b/cake/tests/cases/console/libs/schema.test.php @@ -289,13 +289,12 @@ class SchemaShellTest extends CakeTestCase { function testRunCreateNoArgs() { $this->Shell->params = array( 'connection' => 'test_suite', - 'name' => 'i18n', 'path' => APP . 'config' . DS . 'sql' ); - $this->Shell->args = array('create'); + $this->Shell->args = array('i18n'); $this->Shell->startup(); $this->Shell->setReturnValue('in', 'y'); - $this->Shell->run(); + $this->Shell->create(); $db =& ConnectionManager::getDataSource('test_suite'); $sources = $db->listSources(); @@ -316,10 +315,10 @@ class SchemaShellTest extends CakeTestCase { 'name' => 'DbAcl', 'path' => APP . 'config' . DS . 'schema' ); - $this->Shell->args = array('create', 'acos'); + $this->Shell->args = array('DbAcl', 'acos'); $this->Shell->startup(); $this->Shell->setReturnValue('in', 'y'); - $this->Shell->run(); + $this->Shell->create(); $db =& ConnectionManager::getDataSource('test_suite'); $sources = $db->listSources(); @@ -337,14 +336,13 @@ class SchemaShellTest extends CakeTestCase { **/ function testRunUpdateWithTable() { $this->Shell->params = array( - 'name' => 'SchemaShellTest', 'connection' => 'test_suite', 'f' => true ); - $this->Shell->args = array('update', 'articles'); + $this->Shell->args = array('SchemaShellTest', 'articles'); $this->Shell->startup(); $this->Shell->setReturnValue('in', 'y'); - $this->Shell->run(); + $this->Shell->update(); $article =& new Model(array('name' => 'Article', 'ds' => 'test_suite')); $fields = $article->schema();