Permalink
Browse files

Removing `cake schema run`. Replacing it with `cake schema create` an…

…d `cake schema update`. Removes extra typing and simplifies schema shell commands.

Updating test cases.
  • Loading branch information...
1 parent e1d0be6 commit c2a53d3c6972865b7e72262b8bf12df790c96ae3 @markstory markstory committed Oct 4, 2009
Showing with 30 additions and 35 deletions.
  1. +24 −27 cake/console/libs/schema.php
  2. +6 −8 cake/tests/cases/console/libs/schema.test.php
@@ -238,20 +238,31 @@ function dump() {
}
/**
- * 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();
- }
-
- $command = $this->args[0];
+ * @return void
+ **/
+ function create() {
+ list($Schema, $table) = $this->_loadSchema();
+ $this->__create($Schema, $table);
+ }
- $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 @@ function run() {
$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 @@ function __create(&$Schema, $table = null) {
$this->out(__('Creating table(s).', true));
$this->__run($create, 'create', $Schema);
}
-
$this->out(__('End create.', true));
}
@@ -395,7 +393,6 @@ function __run($contents, $event, &$Schema) {
}
Configure::write('debug', 2);
$db =& ConnectionManager::getDataSource($this->Schema->connection);
- $db->fullDebug = true;
foreach ($contents as $table => $sql) {
if (empty($sql)) {
@@ -289,13 +289,12 @@ function testGenerateOverwrite() {
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 @@ function testRunCreateWithTableArgs() {
'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 @@ function testRunCreateWithTableArgs() {
**/
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();

0 comments on commit c2a53d3

Please sign in to comment.