mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-09 17:57:38 +08:00
initial console commands adjustments
This commit is contained in:
@ -4,49 +4,35 @@
|
|||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @link http://www.yiiframework.com/
|
* @link http://www.yiiframework.com/
|
||||||
* @copyright Copyright © 2008-2011 Yii Software LLC
|
* @copyright Copyright © 2008-2012 Yii Software LLC
|
||||||
* @license http://www.yiiframework.com/license/
|
* @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>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @version $Id$
|
* @since 2.0
|
||||||
* @package system.cli.commands
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
*/
|
||||||
class WebAppCommand extends CConsoleCommand
|
class AppController extends Controller
|
||||||
{
|
{
|
||||||
private $_rootPath;
|
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.
|
* Generates Yii application at the path specified via appPath parameter.
|
||||||
* @param array command line parameters specific for this command
|
*
|
||||||
|
* @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]))
|
$path=strtr($appPath,'/\\',DIRECTORY_SEPARATOR);
|
||||||
$this->usageError('the Web application location is not specified.');
|
|
||||||
$path=strtr($args[0],'/\\',DIRECTORY_SEPARATOR);
|
|
||||||
if(strpos($path,DIRECTORY_SEPARATOR)===false)
|
if(strpos($path,DIRECTORY_SEPARATOR)===false)
|
||||||
$path='.'.DIRECTORY_SEPARATOR.$path;
|
$path='.'.DIRECTORY_SEPARATOR.$path;
|
||||||
$dir=rtrim(realpath(dirname($path)),'\\/');
|
$dir=rtrim(realpath(dirname($path)),'\\/');
|
||||||
|
|||||||
@ -4,79 +4,66 @@
|
|||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @link http://www.yiiframework.com/
|
* @link http://www.yiiframework.com/
|
||||||
* @copyright Copyright © 2008-2011 Yii Software LLC
|
* @copyright Copyright © 2008-2012 Yii Software LLC
|
||||||
* @license http://www.yiiframework.com/license/
|
* @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
|
* The extracted messages are saved as PHP message source files
|
||||||
* under the specified directory.
|
* under the specified directory.
|
||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @version $Id$
|
* @since 2.0
|
||||||
* @package system.cli.commands
|
|
||||||
* @since 1.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.
|
* Searches for messages to be translated in the specified
|
||||||
* @param array command line parameters specific for this command
|
* 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]))
|
if(!is_file($config))
|
||||||
$this->usageError('the configuration file is not specified.');
|
$this->usageError("the configuration file {$config} does not exist.");
|
||||||
if(!is_file($args[0]))
|
|
||||||
$this->usageError("the configuration file {$args[0]} does not exist.");
|
$config=require_once($config);
|
||||||
|
|
||||||
$config=require_once($args[0]);
|
|
||||||
$translator='Yii::t';
|
$translator='Yii::t';
|
||||||
extract($config);
|
extract($config);
|
||||||
|
|
||||||
@ -97,7 +84,7 @@ EOD;
|
|||||||
|
|
||||||
if(!isset($sort))
|
if(!isset($sort))
|
||||||
$sort = false;
|
$sort = false;
|
||||||
|
|
||||||
$options=array();
|
$options=array();
|
||||||
if(isset($fileTypes))
|
if(isset($fileTypes))
|
||||||
$options['fileTypes']=$fileTypes;
|
$options['fileTypes']=$fileTypes;
|
||||||
@ -212,8 +199,6 @@ EOD;
|
|||||||
* of the guide for details.
|
* of the guide for details.
|
||||||
*
|
*
|
||||||
* NOTE, this file must be saved in UTF-8 encoding.
|
* NOTE, this file must be saved in UTF-8 encoding.
|
||||||
*
|
|
||||||
* @version \$Id: \$
|
|
||||||
*/
|
*/
|
||||||
return $array;
|
return $array;
|
||||||
|
|
||||||
|
|||||||
@ -4,23 +4,61 @@
|
|||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @link http://www.yiiframework.com/
|
* @link http://www.yiiframework.com/
|
||||||
* @copyright Copyright © 2008-2011 Yii Software LLC
|
* @copyright Copyright © 2008-2012 Yii Software LLC
|
||||||
* @license http://www.yiiframework.com/license/
|
* @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 implementation of this command and other supporting classes referenced
|
||||||
* the yii-dbmigrations extension ((https://github.com/pieterclaerhout/yii-dbmigrations),
|
* the yii-dbmigrations extension ((https://github.com/pieterclaerhout/yii-dbmigrations),
|
||||||
* authored by Pieter Claerhout.
|
* 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>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @version $Id$
|
* @since 2.0
|
||||||
* @package system.cli.commands
|
|
||||||
* @since 1.1.6
|
|
||||||
*/
|
*/
|
||||||
class MigrateCommand extends CConsoleCommand
|
class MigrateController extends Controller
|
||||||
{
|
{
|
||||||
const BASE_MIGRATION='m000000_000000_base';
|
const BASE_MIGRATION='m000000_000000_base';
|
||||||
|
|
||||||
@ -57,31 +95,37 @@ class MigrateCommand extends CConsoleCommand
|
|||||||
*/
|
*/
|
||||||
public $interactive=true;
|
public $interactive=true;
|
||||||
|
|
||||||
public function beforeAction($action,$params)
|
public function beforeAction($action)
|
||||||
{
|
{
|
||||||
$path=Yii::getPathOfAlias($this->migrationPath);
|
$path = \Yii::getAlias($this->migrationPath);
|
||||||
if($path===false || !is_dir($path))
|
if($path===false || !is_dir($path)) {
|
||||||
die('Error: The migration directory does not exist: '.$this->migrationPath."\n");
|
echo 'Error: The migration directory does not exist: ' . $this->migrationPath . "\n";
|
||||||
|
\Yii::$application->end(1);
|
||||||
|
}
|
||||||
$this->migrationPath=$path;
|
$this->migrationPath=$path;
|
||||||
|
|
||||||
$yiiVersion=Yii::getVersion();
|
$yiiVersion = \Yii::getVersion();
|
||||||
echo "\nYii Migration Tool v1.0 (based on Yii v{$yiiVersion})\n\n";
|
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)
|
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";
|
echo "No new migration found. Your system is up-to-date.\n";
|
||||||
return;
|
\Yii::$application->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
$total=count($migrations);
|
$total=count($migrations);
|
||||||
$step=isset($args[0]) ? (int)$args[0] : 0;
|
$step=isset($args[0]) ? (int)$args[0] : 0;
|
||||||
if($step>0)
|
if($step>0) {
|
||||||
$migrations=array_slice($migrations,0,$step);
|
$migrations=array_slice($migrations,0,$step);
|
||||||
|
}
|
||||||
|
|
||||||
$n=count($migrations);
|
$n=count($migrations);
|
||||||
if($n===$total)
|
if($n===$total)
|
||||||
@ -473,58 +517,6 @@ class MigrateCommand extends CConsoleCommand
|
|||||||
return $migrations;
|
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()
|
protected function getTemplate()
|
||||||
{
|
{
|
||||||
if($this->templateFile!==null)
|
if($this->templateFile!==null)
|
||||||
|
|||||||
@ -4,22 +4,23 @@
|
|||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @link http://www.yiiframework.com/
|
* @link http://www.yiiframework.com/
|
||||||
* @copyright Copyright © 2008-2011 Yii Software LLC
|
* @copyright Copyright © 2008-2012 Yii Software LLC
|
||||||
* @license http://www.yiiframework.com/license/
|
* @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.
|
* ShellCommand executes the specified Web application and provides a shell for interaction.
|
||||||
*
|
*
|
||||||
* @property string $help The help information for the shell command.
|
* @property string $help The help information for the shell command.
|
||||||
*
|
*
|
||||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||||
* @version $Id$
|
* @since 2.0
|
||||||
* @package system.cli.commands
|
|
||||||
* @since 1.0
|
|
||||||
*/
|
*/
|
||||||
class ShellCommand extends CConsoleCommand
|
class ShellController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @return string the help information for the shell command
|
* @return string the help information for the shell command
|
||||||
|
|||||||
Reference in New Issue
Block a user