1
1
<?php
2
- /* SVN FILE: $Id$ */
3
2
/**
4
3
* Command-line database management utility to automate programmer chores.
5
4
*
9
8
* PHP versions 4 and 5
10
9
*
11
10
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
12
- * Copyright 2005-2008 , Cake Software Foundation, Inc. (http://www.cakefoundation.org)
11
+ * Copyright 2005-2009 , Cake Software Foundation, Inc. (http://www.cakefoundation.org)
13
12
*
14
13
* Licensed under The MIT License
15
14
* Redistributions of files must retain the above copyright notice.
16
15
*
17
16
* @filesource
18
- * @copyright Copyright 2005-2008 , Cake Software Foundation, Inc. (http://www.cakefoundation.org)
17
+ * @copyright Copyright 2005-2009 , Cake Software Foundation, Inc. (http://www.cakefoundation.org)
19
18
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
20
19
* @package cake
21
20
* @subpackage cake.cake.console.libs
22
21
* @since CakePHP(tm) v 1.2.0.5550
23
- * @version $Revision$
24
- * @modifiedby $LastChangedBy$
25
- * @lastmodified $Date$
26
22
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
27
23
*/
28
24
App::import ('File ' );
@@ -116,7 +112,7 @@ function view() {
116
112
* @access public
117
113
*/
118
114
function generate () {
119
- $ this ->out ('Generating Schema... ' );
115
+ $ this ->out (__ ( 'Generating Schema... ' , true ) );
120
116
$ options = array ();
121
117
if (isset ($ this ->params ['f ' ])) {
122
118
$ options = array ('models ' => false );
@@ -131,7 +127,7 @@ function generate() {
131
127
$ snapshot = true ;
132
128
$ 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 ' ));
133
129
if ($ result === 'q ' ) {
134
- $ this ->_stop ();
130
+ return $ this ->_stop ();
135
131
}
136
132
if ($ result === 'o ' ) {
137
133
$ snapshot = false ;
@@ -224,7 +220,7 @@ function dump() {
224
220
*/
225
221
function run () {
226
222
if (!isset ($ this ->args [0 ])) {
227
- $ this ->err (' command not found ' );
223
+ $ this ->err (__ ( ' Command not found ', true ) );
228
224
$ this ->_stop ();
229
225
}
230
226
@@ -271,8 +267,8 @@ function run() {
271
267
$ this ->__update ($ Schema , $ table );
272
268
break ;
273
269
default :
274
- $ this ->err (__ ('command not found ' , true ));
275
- $ this ->_stop ();
270
+ $ this ->err (__ ('Command not found ' , true ));
271
+ $ this ->_stop ();
276
272
}
277
273
}
278
274
/**
@@ -281,7 +277,7 @@ function run() {
281
277
*
282
278
* @access private
283
279
*/
284
- function __create ($ Schema , $ table = null ) {
280
+ function __create (& $ Schema , $ table = null ) {
285
281
$ db =& ConnectionManager::getDataSource ($ this ->Schema ->connection );
286
282
287
283
$ drop = $ create = array ();
@@ -304,15 +300,15 @@ function __create($Schema, $table = null) {
304
300
$ this ->out (array_keys ($ drop ));
305
301
306
302
if ('y ' == $ this ->in (__ ('Are you sure you want to drop the table(s)? ' , true ), array ('y ' , 'n ' ), 'n ' )) {
307
- $ this ->out ('Dropping table(s). ' );
303
+ $ this ->out (__ ( 'Dropping table(s). ' , true ) );
308
304
$ this ->__run ($ drop , 'drop ' , $ Schema );
309
305
}
310
306
311
307
$ this ->out ("\n" . __ ('The following table(s) will be created. ' , true ));
312
308
$ this ->out (array_keys ($ create ));
313
309
314
310
if ('y ' == $ this ->in (__ ('Are you sure you want to create the table(s)? ' , true ), array ('y ' , 'n ' ), 'y ' )) {
315
- $ this ->out ('Creating table(s). ' );
311
+ $ this ->out (__ ( 'Creating table(s). ' , true ) );
316
312
$ this ->__run ($ create , 'create ' , $ Schema );
317
313
}
318
314
@@ -324,11 +320,15 @@ function __create($Schema, $table = null) {
324
320
*
325
321
* @access private
326
322
*/
327
- function __update ($ Schema , $ table = null ) {
323
+ function __update (& $ Schema , $ table = null ) {
328
324
$ db =& ConnectionManager::getDataSource ($ this ->Schema ->connection );
329
325
330
- $ this ->out ('Comparing Database to Schema... ' );
331
- $ Old = $ this ->Schema ->read ();
326
+ $ this ->out (__ ('Comparing Database to Schema... ' , true ));
327
+ $ options = array ();
328
+ if (isset ($ this ->params ['f ' ])) {
329
+ $ options ['models ' ] = false ;
330
+ }
331
+ $ Old = $ this ->Schema ->read ($ options );
332
332
$ compare = $ this ->Schema ->compare ($ Old , $ Schema );
333
333
334
334
$ contents = array ();
@@ -361,15 +361,15 @@ function __update($Schema, $table = null) {
361
361
*
362
362
* @access private
363
363
*/
364
- function __run ($ contents , $ event , $ Schema ) {
364
+ function __run ($ contents , $ event , & $ Schema ) {
365
365
if (empty ($ contents )) {
366
366
$ this ->err (__ ('Sql could not be run ' , true ));
367
367
return ;
368
368
}
369
369
Configure::write ('debug ' , 2 );
370
370
$ db =& ConnectionManager::getDataSource ($ this ->Schema ->connection );
371
371
$ db ->fullDebug = true ;
372
-
372
+
373
373
foreach ($ contents as $ table => $ sql ) {
374
374
if (empty ($ sql )) {
375
375
$ this ->out (sprintf (__ ('%s is up to date. ' , true ), $ table ));
@@ -403,7 +403,8 @@ function __run($contents, $event, $Schema) {
403
403
* @access public
404
404
*/
405
405
function help () {
406
- $ this ->out ("The Schema Shell generates a schema object from \n\t\tthe database and updates the database from the schema. " );
406
+ $ this ->out ("The Schema Shell generates a schema object from " );
407
+ $ this ->out ("the database and updates the database from the schema. " );
407
408
$ this ->hr ();
408
409
$ this ->out ("Usage: cake schema <command> <arg1> <arg2>... " );
409
410
$ this ->hr ();
0 commit comments