Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
ea1c5c78
Commit
ea1c5c78
authored
Sep 09, 2012
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial console commands adjustments
parent
c1ab0a9a
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
165 deletions
+129
-165
AppController.php
framework/console/controllers/AppController.php
+16
-30
MessageController.php
framework/console/controllers/MessageController.php
+46
-61
MigrateController.php
framework/console/controllers/MigrateController.php
+60
-68
ShellController.php
framework/console/controllers/ShellController.php
+7
-6
No files found.
framework/console/controllers/AppController.php
View file @
ea1c5c78
...
...
@@ -4,49 +4,35 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @version $Id$
*/
namespace
yii\console\controllers
;
use
yii\console\Controller
;
/**
*
WebAppC
ommand creates an Yii Web application at the specified location.
*
This c
ommand 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
)),
'\\/'
);
...
...
framework/console/controllers/MessageController.php
View file @
ea1c5c78
...
...
@@ -4,79 +4,66 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\console\controllers
;
use
yii\console\Controller
;
/**
*
MessageC
ommand extracts messages to be translated from source files.
*
This c
ommand 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
MessageCo
mmand
extends
CConsoleCommand
class
MessageCo
ntroller
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
(
!
is
set
(
$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
;
...
...
framework/console/controllers/MigrateController.php
View file @
ea1c5c78
...
...
@@ -4,23 +4,61 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
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
MigrateCo
mmand
extends
CConsoleCommand
class
MigrateCo
ntroller
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
"
\n
Yii Migration Tool v
1
.0 (based on Yii v
{
$yiiVersion
}
)
\n\n
"
;
$yiiVersion
=
\
Yii
::
getVersion
();
echo
"
\n
Yii Migration Tool v
2
.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
)
...
...
framework/console/controllers/ShellController.php
View file @
ea1c5c78
...
...
@@ -4,22 +4,23 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
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
ShellCo
mmand
extends
CConsoleCommand
class
ShellCo
ntroller
extends
Controller
{
/**
* @return string the help information for the shell command
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment