mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Fix #15202: Add optional param --silent-exit-on-exception
in yii\console\Controller
This commit is contained in:
@ -20,6 +20,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #18101: Fix behavior of OUTPUT INSERTED.* for SQL Server query: "insert default values"; correct MSSQL unit tests; turn off profiling echo message in migration test (darkdef)
|
||||
- Bug #18105: Fix for old trigger in RBAC migration with/without prefixTable (darkdef)
|
||||
- Enh #18120: Include path to the log file into error message if `FileTarget::export` fails (uaoleg)
|
||||
- Enh #15202: Add optional param `--silent-exit-on-exception` in `yii\console\Controller` (egorrishe)
|
||||
- Bug #18110: Add quotes to return value of viewName in MSSQL schema. It is `[someView]` now (darkdef)
|
||||
|
||||
|
||||
|
@ -41,6 +41,12 @@ abstract class ErrorHandler extends Component
|
||||
* @var \Exception|null the exception that is being handled currently.
|
||||
*/
|
||||
public $exception;
|
||||
/**
|
||||
* @var bool if TRUE - `handleException()` will finish script with `ExitCode::OK`.
|
||||
* FALSE - `ExitCode::UNSPECIFIED_ERROR`.
|
||||
* @since 2.0.36
|
||||
*/
|
||||
public $silentExitOnException;
|
||||
|
||||
/**
|
||||
* @var string Used to reserve memory for fatal error handler.
|
||||
@ -56,6 +62,12 @@ abstract class ErrorHandler extends Component
|
||||
private $_registered = false;
|
||||
|
||||
|
||||
public function init()
|
||||
{
|
||||
$this->silentExitOnException = $this->silentExitOnException !== null ? $this->silentExitOnException : YII_ENV_TEST;
|
||||
parent::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register this error handler.
|
||||
* @since 2.0.32 this will not do anything if the error handler was already registered
|
||||
@ -121,7 +133,7 @@ abstract class ErrorHandler extends Component
|
||||
$this->clearOutput();
|
||||
}
|
||||
$this->renderException($exception);
|
||||
if (!YII_ENV_TEST) {
|
||||
if (!$this->silentExitOnException) {
|
||||
\Yii::getLogger()->flush(true);
|
||||
if (defined('HHVM_VERSION')) {
|
||||
flush();
|
||||
|
@ -65,6 +65,13 @@ class Controller extends \yii\base\Controller
|
||||
* @since 2.0.10
|
||||
*/
|
||||
public $help;
|
||||
/**
|
||||
* @var bool if TRUE - script finish with `ExitCode::OK` in case of exception.
|
||||
* FALSE - `ExitCode::UNSPECIFIED_ERROR`.
|
||||
* Default: `YII_ENV_TEST`
|
||||
* @since 2.0.36
|
||||
*/
|
||||
public $silentExitOnException;
|
||||
|
||||
/**
|
||||
* @var array the options passed during execution.
|
||||
@ -72,6 +79,14 @@ class Controller extends \yii\base\Controller
|
||||
private $_passedOptions = [];
|
||||
|
||||
|
||||
public function beforeAction($action)
|
||||
{
|
||||
$silentExit = $this->silentExitOnException !== null ? $this->silentExitOnException : YII_ENV_TEST;
|
||||
Yii::$app->errorHandler->silentExitOnException = $silentExit;
|
||||
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value indicating whether ANSI color is enabled.
|
||||
*
|
||||
@ -398,7 +413,7 @@ class Controller extends \yii\base\Controller
|
||||
public function options($actionID)
|
||||
{
|
||||
// $actionId might be used in subclasses to provide options specific to action id
|
||||
return ['color', 'interactive', 'help'];
|
||||
return ['color', 'interactive', 'help', 'silentExitOnException'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,6 +128,7 @@ action:route to action
|
||||
--interactive: whether to run the command interactively.
|
||||
--color: whether to enable ANSI color in the output.If not set, ANSI color will only be enabled for terminals that support it.
|
||||
--help: whether to display help information about current command.
|
||||
--silent-exit-on-exception: if TRUE - script finish with `ExitCode\:\:OK` in case of exception.FALSE - `ExitCode\:\:UNSPECIFIED_ERROR`.Default\: `YII_ENV_TEST`
|
||||
|
||||
STRING
|
||||
, $result);
|
||||
|
Reference in New Issue
Block a user