Browse Source

initial console commands adjustments

tags/2.0.0-beta
Alexander Makarov 12 years ago
parent
commit
ea1c5c7831
  1. 46
      framework/console/controllers/AppController.php
  2. 107
      framework/console/controllers/MessageController.php
  3. 128
      framework/console/controllers/MigrateController.php
  4. 13
      framework/console/controllers/ShellController.php

46
framework/console/controllers/AppController.php

@ -4,49 +4,35 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @version $Id$
*/
namespace yii\console\controllers;
use yii\console\Controller;
/**
* WebAppCommand creates an Yii Web application at the specified location.
* This command creates an Yii Web application at the specified location.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.cli.commands
* @since 1.0
* @since 2.0
*/
class WebAppCommand extends CConsoleCommand
class AppController extends Controller
{
private $_rootPath;
public function getHelp()
{
return <<<EOD
USAGE
yiic webapp <app-path>
DESCRIPTION
This command generates an Yii Web Application at the specified location.
PARAMETERS
* app-path: required, the directory where the new application will be created.
If the directory does not exist, it will be created. After the application
is created, please make sure the directory can be accessed by Web users.
EOD;
}
/**
* Execute the action.
* @param array command line parameters specific for this command
* Generates Yii application at the path specified via appPath parameter.
*
* @param string $appPath the directory where the new application will be created.
* If the directory does not exist, it will be created. After the application
* is created, please make sure the directory has enough permissions.
* @return integer the exit status
*/
public function run($args)
public function actionIndex($appPath)
{
if(!isset($args[0]))
$this->usageError('the Web application location is not specified.');
$path=strtr($args[0],'/\\',DIRECTORY_SEPARATOR);
$path=strtr($appPath,'/\\',DIRECTORY_SEPARATOR);
if(strpos($path,DIRECTORY_SEPARATOR)===false)
$path='.'.DIRECTORY_SEPARATOR.$path;
$dir=rtrim(realpath(dirname($path)),'\\/');

107
framework/console/controllers/MessageController.php

@ -4,79 +4,66 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\console\controllers;
use yii\console\Controller;
/**
* MessageCommand extracts messages to be translated from source files.
* This command extracts messages to be translated from source files.
* The extracted messages are saved as PHP message source files
* under the specified directory.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.cli.commands
* @since 1.0
* @since 2.0
*/
class MessageCommand extends CConsoleCommand
class MessageController extends Controller
{
public function getHelp()
{
return <<<EOD
USAGE
yiic message <config-file>
DESCRIPTION
This command searches for messages to be translated in the specified
source files and compiles them into PHP arrays as message source.
PARAMETERS
* config-file: required, the path of the configuration file. You can find
an example in framework/messages/config.php.
The file can be placed anywhere and must be a valid PHP script which
returns an array of name-value pairs. Each name-value pair represents
a configuration option.
The following options are available:
- sourcePath: string, root directory of all source files.
- messagePath: string, root directory containing message translations.
- languages: array, list of language codes that the extracted messages
should be translated to. For example, array('zh_cn','en_au').
- fileTypes: array, a list of file extensions (e.g. 'php', 'xml').
Only the files whose extension name can be found in this list
will be processed. If empty, all files will be processed.
- exclude: array, a list of directory and file exclusions. Each
exclusion can be either a name or a path. If a file or directory name
or path matches the exclusion, it will not be copied. For example,
an exclusion of '.svn' will exclude all files and directories whose
name is '.svn'. And an exclusion of '/a/b' will exclude file or
directory 'sourcePath/a/b'.
- translator: the name of the function for translating messages.
Defaults to 'Yii::t'. This is used as a mark to find messages to be
translated.
- overwrite: if message file must be overwritten with the merged messages.
- removeOld: if message no longer needs translation it will be removed,
instead of being enclosed between a pair of '@@' marks.
- sort: sort messages by key when merging, regardless of their translation
state (new, obsolete, translated.)
EOD;
}
/**
* Execute the action.
* @param array command line parameters specific for this command
* Searches for messages to be translated in the specified
* source files and compiles them into PHP arrays as message source.
*
* @param string $config the path of the configuration file. You can find
* an example in framework/messages/config.php.
*
* The file can be placed anywhere and must be a valid PHP script which
* returns an array of name-value pairs. Each name-value pair represents
* a configuration option.
*
* The following options are available:
*
* - sourcePath: string, root directory of all source files.
* - messagePath: string, root directory containing message translations.
* - languages: array, list of language codes that the extracted messages
* should be translated to. For example, array('zh_cn','en_au').
* - fileTypes: array, a list of file extensions (e.g. 'php', 'xml').
* Only the files whose extension name can be found in this list
* will be processed. If empty, all files will be processed.
* - exclude: array, a list of directory and file exclusions. Each
* exclusion can be either a name or a path. If a file or directory name
* or path matches the exclusion, it will not be copied. For example,
* an exclusion of '.svn' will exclude all files and directories whose
* name is '.svn'. And an exclusion of '/a/b' will exclude file or
* directory 'sourcePath/a/b'.
* - translator: the name of the function for translating messages.
* Defaults to 'Yii::t'. This is used as a mark to find messages to be
* translated.
* - overwrite: if message file must be overwritten with the merged messages.
* - removeOld: if message no longer needs translation it will be removed,
* instead of being enclosed between a pair of '@@' marks.
* - sort: sort messages by key when merging, regardless of their translation
* state (new, obsolete, translated.)
*/
public function run($args)
public function actionIndex($config)
{
if(!isset($args[0]))
$this->usageError('the configuration file is not specified.');
if(!is_file($args[0]))
$this->usageError("the configuration file {$args[0]} does not exist.");
if(!is_file($config))
$this->usageError("the configuration file {$config} does not exist.");
$config=require_once($config);
$config=require_once($args[0]);
$translator='Yii::t';
extract($config);
@ -212,8 +199,6 @@ EOD;
* of the guide for details.
*
* NOTE, this file must be saved in UTF-8 encoding.
*
* @version \$Id: \$
*/
return $array;

128
framework/console/controllers/MigrateController.php

@ -4,23 +4,61 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\console\controllers;
use yii\console\Controller;
/**
* MigrateCommand manages the database migrations.
* This command provides support for database migrations.
*
* The implementation of this command and other supporting classes referenced
* the yii-dbmigrations extension ((https://github.com/pieterclaerhout/yii-dbmigrations),
* authored by Pieter Claerhout.
*
* EXAMPLES
*
* - yiic migrate
* Applies ALL new migrations. This is equivalent to 'yiic migrate up'.
*
* - yiic migrate create create_user_table
* Creates a new migration named 'create_user_table'.
*
* - yiic migrate up 3
* Applies the next 3 new migrations.
*
* - yiic migrate down
* Reverts the last applied migration.
*
* - yiic migrate down 3
* Reverts the last 3 applied migrations.
*
* - yiic migrate to 101129_185401
* Migrates up or down to version 101129_185401.
*
* - yiic migrate mark 101129_185401
* Modifies the migration history up or down to version 101129_185401.
* No actual migration will be performed.
*
* - yiic migrate history
* Shows all previously applied migration information.
*
* - yiic migrate history 10
* Shows the last 10 applied migrations.
*
* - yiic migrate new
* Shows all new migrations.
*
* - yiic migrate new 10
* Shows the next 10 migrations that have not been applied.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.cli.commands
* @since 1.1.6
* @since 2.0
*/
class MigrateCommand extends CConsoleCommand
class MigrateController extends Controller
{
const BASE_MIGRATION='m000000_000000_base';
@ -57,31 +95,37 @@ class MigrateCommand extends CConsoleCommand
*/
public $interactive=true;
public function beforeAction($action,$params)
public function beforeAction($action)
{
$path=Yii::getPathOfAlias($this->migrationPath);
if($path===false || !is_dir($path))
die('Error: The migration directory does not exist: '.$this->migrationPath."\n");
$path = \Yii::getAlias($this->migrationPath);
if($path===false || !is_dir($path)) {
echo 'Error: The migration directory does not exist: ' . $this->migrationPath . "\n";
\Yii::$application->end(1);
}
$this->migrationPath=$path;
$yiiVersion=Yii::getVersion();
echo "\nYii Migration Tool v1.0 (based on Yii v{$yiiVersion})\n\n";
$yiiVersion = \Yii::getVersion();
echo "\nYii Migration Tool v2.0 (based on Yii v{$yiiVersion})\n\n";
return true;
return parent::beforeAction($action);
}
/**
* @param array $args
*/
public function actionUp($args)
{
if(($migrations=$this->getNewMigrations())===array())
if(($migrations = $this->getNewMigrations())===array())
{
echo "No new migration found. Your system is up-to-date.\n";
return;
\Yii::$application->end();
}
$total=count($migrations);
$step=isset($args[0]) ? (int)$args[0] : 0;
if($step>0)
if($step>0) {
$migrations=array_slice($migrations,0,$step);
}
$n=count($migrations);
if($n===$total)
@ -473,58 +517,6 @@ class MigrateCommand extends CConsoleCommand
return $migrations;
}
public function getHelp()
{
return <<<EOD
USAGE
yiic migrate [action] [parameter]
DESCRIPTION
This command provides support for database migrations. The optional
'action' parameter specifies which specific migration task to perform.
It can take these values: up, down, to, create, history, new, mark.
If the 'action' parameter is not given, it defaults to 'up'.
Each action takes different parameters. Their usage can be found in
the following examples.
EXAMPLES
* yiic migrate
Applies ALL new migrations. This is equivalent to 'yiic migrate up'.
* yiic migrate create create_user_table
Creates a new migration named 'create_user_table'.
* yiic migrate up 3
Applies the next 3 new migrations.
* yiic migrate down
Reverts the last applied migration.
* yiic migrate down 3
Reverts the last 3 applied migrations.
* yiic migrate to 101129_185401
Migrates up or down to version 101129_185401.
* yiic migrate mark 101129_185401
Modifies the migration history up or down to version 101129_185401.
No actual migration will be performed.
* yiic migrate history
Shows all previously applied migration information.
* yiic migrate history 10
Shows the last 10 applied migrations.
* yiic migrate new
Shows all new migrations.
* yiic migrate new 10
Shows the next 10 migrations that have not been applied.
EOD;
}
protected function getTemplate()
{
if($this->templateFile!==null)

13
framework/console/controllers/ShellController.php

@ -4,22 +4,23 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @copyright Copyright &copy; 2008-2012 Yii Software LLC
* @license http://www.yiiframework.com/license/
* @version $Id$
*/
namespace yii\console\controllers;
use yii\console\Controller;
/**
* ShellCommand executes the specified Web application and provides a shell for interaction.
*
* @property string $help The help information for the shell command.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id$
* @package system.cli.commands
* @since 1.0
* @since 2.0
*/
class ShellCommand extends CConsoleCommand
class ShellController extends Controller
{
/**
* @return string the help information for the shell command

Loading…
Cancel
Save