Skip to content

Commit

Permalink
Backporting bugfix for #22 from 1.3-console to 1.2. Adds schema shell…
Browse files Browse the repository at this point in the history
… test cases, fixes for schema object references, i18n of schema schell output strings.
  • Loading branch information
jperras committed Sep 7, 2009
1 parent bcbdb1c commit 24351b5
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 20 deletions.
41 changes: 21 additions & 20 deletions cake/console/libs/schema.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* Command-line database management utility to automate programmer chores.
*
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}
/**
Expand All @@ -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();
Expand All @@ -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);
}

Expand All @@ -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();
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions cake/libs/model/schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 24351b5

Please sign in to comment.