Permalink
Browse files

Backporting bugfix for #22 from 1.3-console to 1.2. Adds schema shell…

… test cases, fixes for schema object references, i18n of schema schell output strings.
  • Loading branch information...
1 parent bcbdb1c commit 24351b5a21085e1beccf1dbf5100155a72a60bb8 @jperras jperras committed Sep 7, 2009
Showing with 375 additions and 20 deletions.
  1. +21 −20 cake/console/libs/schema.php
  2. +1 −0 cake/libs/model/schema.php
  3. +353 −0 cake/tests/cases/console/libs/schema.test.php
@@ -1,5 +1,4 @@
<?php
-/* SVN FILE: $Id$ */
/**
* Command-line database management utility to automate programmer chores.
*
@@ -9,20 +8,17 @@
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.console.libs
* @since CakePHP(tm) v 1.2.0.5550
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
App::import('File');
@@ -116,7 +112,7 @@ function view() {
* @access public
*/
function generate() {
- $this->out('Generating Schema...');
+ $this->out(__('Generating Schema...', true));
$options = array();
if (isset($this->params['f'])) {
$options = array('models' => false);
@@ -131,7 +127,7 @@ function generate() {
$snapshot = true;
$result = strtolower($this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's'));
if ($result === 'q') {
- $this->_stop();
+ return $this->_stop();
}
if ($result === 'o') {
$snapshot = false;
@@ -224,7 +220,7 @@ function dump() {
*/
function run() {
if (!isset($this->args[0])) {
- $this->err('command not found');
+ $this->err(__('Command not found', true));
$this->_stop();
}
@@ -271,8 +267,8 @@ function run() {
$this->__update($Schema, $table);
break;
default:
- $this->err(__('command not found', true));
- $this->_stop();
+ $this->err(__('Command not found', true));
+ $this->_stop();
}
}
/**
@@ -281,7 +277,7 @@ function run() {
*
* @access private
*/
- function __create($Schema, $table = null) {
+ function __create(&$Schema, $table = null) {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$drop = $create = array();
@@ -304,15 +300,15 @@ function __create($Schema, $table = null) {
$this->out(array_keys($drop));
if ('y' == $this->in(__('Are you sure you want to drop the table(s)?', true), array('y', 'n'), 'n')) {
- $this->out('Dropping table(s).');
+ $this->out(__('Dropping table(s).', true));
$this->__run($drop, 'drop', $Schema);
}
$this->out("\n" . __('The following table(s) will be created.', true));
$this->out(array_keys($create));
if ('y' == $this->in(__('Are you sure you want to create the table(s)?', true), array('y', 'n'), 'y')) {
- $this->out('Creating table(s).');
+ $this->out(__('Creating table(s).', true));
$this->__run($create, 'create', $Schema);
}
@@ -324,11 +320,15 @@ function __create($Schema, $table = null) {
*
* @access private
*/
- function __update($Schema, $table = null) {
+ function __update(&$Schema, $table = null) {
$db =& ConnectionManager::getDataSource($this->Schema->connection);
- $this->out('Comparing Database to Schema...');
- $Old = $this->Schema->read();
+ $this->out(__('Comparing Database to Schema...', true));
+ $options = array();
+ if (isset($this->params['f'])) {
+ $options['models'] = false;
+ }
+ $Old = $this->Schema->read($options);
$compare = $this->Schema->compare($Old, $Schema);
$contents = array();
@@ -361,15 +361,15 @@ function __update($Schema, $table = null) {
*
* @access private
*/
- function __run($contents, $event, $Schema) {
+ function __run($contents, $event, &$Schema) {
if (empty($contents)) {
$this->err(__('Sql could not be run', true));
return;
}
Configure::write('debug', 2);
$db =& ConnectionManager::getDataSource($this->Schema->connection);
$db->fullDebug = true;
-
+
foreach ($contents as $table => $sql) {
if (empty($sql)) {
$this->out(sprintf(__('%s is up to date.', true), $table));
@@ -403,7 +403,8 @@ function __run($contents, $event, $Schema) {
* @access public
*/
function help() {
- $this->out("The Schema Shell generates a schema object from \n\t\tthe database and updates the database from the schema.");
+ $this->out("The Schema Shell generates a schema object from");
+ $this->out("the database and updates the database from the schema.");
$this->hr();
$this->out("Usage: cake schema <command> <arg1> <arg2>...");
$this->hr();
@@ -172,6 +172,7 @@ function load($options = array()) {
* - 'connection' - the db connection to use
* - 'name' - name of the schema
* - 'models' - a list of models to use, or false to ignore models
+ *
* @param array $options schema object properties
* @return array Array indexed by name and tables
* @access public
Oops, something went wrong.

0 comments on commit 24351b5

Please sign in to comment.