Browse Source

Fix #15202: Add optional param `--silent-exit-on-exception` in `yii\console\Controller`

tags/2.0.36
egorrishe 4 years ago committed by GitHub
parent
commit
5c3ee63316
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 14
      framework/base/ErrorHandler.php
  3. 17
      framework/console/Controller.php
  4. 1
      tests/framework/console/controllers/HelpControllerTest.php

1
framework/CHANGELOG.md

@ -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)

14
framework/base/ErrorHandler.php

@ -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();

17
framework/console/Controller.php

@ -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'];
}
/**

1
tests/framework/console/controllers/HelpControllerTest.php

@ -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);

Loading…
Cancel
Save