Commit 8c50ee9e by Qiang Xue

Fixes #5613: Added `--overwrite` option to Gii console command to support overwriting all files

Fixed the bug that Gii console command help information does not contain global options
parent 2d31f9f6
...@@ -4,7 +4,8 @@ Yii Framework 2 gii extension Change Log ...@@ -4,7 +4,8 @@ Yii Framework 2 gii extension Change Log
2.0.1 under development 2.0.1 under development
----------------------- -----------------------
- no changes in this release. - Enh #5613: Added `--overwrite` option to Gii console command to support overwriting all files (motin, qiangxue)
- Bug: Gii console command help information does not contain global options (qiangxue)
2.0.0 October 12, 2014 2.0.0 October 12, 2014
......
...@@ -56,7 +56,7 @@ class GenerateAction extends \yii\base\Action ...@@ -56,7 +56,7 @@ class GenerateAction extends \yii\base\Action
return; return;
} }
echo "The following files will be generated:\n"; echo "The following files will be generated:\n";
$skipAll = $this->controller->interactive ? null : true; $skipAll = $this->controller->interactive ? null : !$this->controller->overwrite;
$answers = []; $answers = [];
foreach ($files as $file) { foreach ($files as $file) {
$path = $file->getRelativePath(); $path = $file->getRelativePath();
......
...@@ -32,6 +32,12 @@ class GenerateController extends Controller ...@@ -32,6 +32,12 @@ class GenerateController extends Controller
*/ */
public $module; public $module;
/** /**
* @var boolean whether to overwrite all existing code files when in non-interactive mode.
* Defaults to false, meaning none of the existing code files will be overwritten.
* This option is used only when `--interactive=0`.
*/
public $overwrite = false;
/**
* @var array a list of the available code generators * @var array a list of the available code generators
*/ */
public $generators = []; public $generators = [];
...@@ -115,16 +121,19 @@ class GenerateController extends Controller ...@@ -115,16 +121,19 @@ class GenerateController extends Controller
*/ */
public function options($id) public function options($id)
{ {
if (isset($this->generators[$id])) { $options = parent::options($id);
$options[] = 'overwrite';
if (!isset($this->generators[$id])) {
return $options;
}
$attributes = $this->generators[$id]->attributes; $attributes = $this->generators[$id]->attributes;
unset($attributes['templates']); unset($attributes['templates']);
return array_merge( return array_merge(
parent::options($id), $options,
array_keys($attributes) array_keys($attributes)
); );
} else {
return parent::options($id);
}
} }
/** /**
...@@ -175,7 +184,7 @@ class GenerateController extends Controller ...@@ -175,7 +184,7 @@ class GenerateController extends Controller
unset($attributes['templates']); unset($attributes['templates']);
$hints = $action->generator->hints(); $hints = $action->generator->hints();
$options = []; $options = parent::getActionOptionsHelp($action);
foreach ($attributes as $name => $value) { foreach ($attributes as $name => $value) {
$type = gettype($value); $type = gettype($value);
$options[$name] = [ $options[$name] = [
......
...@@ -5,7 +5,9 @@ Yii Framework 2 Change Log ...@@ -5,7 +5,9 @@ Yii Framework 2 Change Log
----------------------- -----------------------
- Enh #5600: Allow configuring debug panels in `yii\debug\Module::panels` as panel class name strings (qiangxue) - Enh #5600: Allow configuring debug panels in `yii\debug\Module::panels` as panel class name strings (qiangxue)
- Enh #5613: Added `--overwrite` option to Gii console command to support overwriting all files (motin, qiangxue)
- Bug #5584: `yii\rbac\DbRbacManager` should not delete items when deleting a rule on a database not supporting cascade update (mdmunir) - Bug #5584: `yii\rbac\DbRbacManager` should not delete items when deleting a rule on a database not supporting cascade update (mdmunir)
- Bug: Gii console command help information does not contain global options (qiangxue)
2.0.0 October 12, 2014 2.0.0 October 12, 2014
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment