Commit a86d2ad1 by Alexander Makarov

Added `yii\console\Controller::EXIT_CODE_NORMAL` and…

Added `yii\console\Controller::EXIT_CODE_NORMAL` and `yii\console\Controller::EXIT_CODE_ERROR` constants, `yii\console\MigrateController` now returns `yii\console\Controller::EXIT_CODE_ERROR` in case of failed migration
parent c7b05f0c
...@@ -45,6 +45,8 @@ Yii Framework 2 Change Log ...@@ -45,6 +45,8 @@ Yii Framework 2 Change Log
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue) - Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
- Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue) - Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
- Enh: Added support to insert an event handler at the beginning of class-level event handler queue (qiangxue) - Enh: Added support to insert an event handler at the beginning of class-level event handler queue (qiangxue)
- Enh: Added `yii\console\Controller::EXIT_CODE_NORMAL` and `yii\console\Controller::EXIT_CODE_ERROR` constants (samdark)
- Enh: `yii\console\MigrateController` now returns `yii\console\Controller::EXIT_CODE_ERROR` in case of failed migration (samdark)
- Chg #2913: RBAC `DbManager` is now initialized via migration (samdark) - Chg #2913: RBAC `DbManager` is now initialized via migration (samdark)
- Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue) - Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue)
- Chg #3175: InvalidCallException, InvalidParamException, UnknownMethodException are now extended from SPL BadMethodCallException (samdark) - Chg #3175: InvalidCallException, InvalidParamException, UnknownMethodException are now extended from SPL BadMethodCallException (samdark)
......
...@@ -29,6 +29,9 @@ use yii\helpers\Console; ...@@ -29,6 +29,9 @@ use yii\helpers\Console;
*/ */
class Controller extends \yii\base\Controller class Controller extends \yii\base\Controller
{ {
const EXIT_CODE_NORMAL = 0;
const EXIT_CODE_ERROR = 1;
/** /**
* @var boolean whether to run the command interactively. * @var boolean whether to run the command interactively.
*/ */
......
...@@ -611,7 +611,7 @@ return [ ...@@ -611,7 +611,7 @@ return [
EOD; EOD;
if (file_exists($configFile)) { if (file_exists($configFile)) {
if (!$this->confirm("File '{$configFile}' already exists. Do you wish to overwrite it?")) { if (!$this->confirm("File '{$configFile}' already exists. Do you wish to overwrite it?")) {
return; return self::EXIT_CODE_NORMAL;
} }
} }
if (!file_put_contents($configFile, $template)) { if (!file_put_contents($configFile, $template)) {
......
...@@ -96,7 +96,7 @@ class FixtureController extends Controller ...@@ -96,7 +96,7 @@ class FixtureController extends Controller
} }
if (!$this->confirmLoad($foundFixtures, $except)) { if (!$this->confirmLoad($foundFixtures, $except)) {
return; return self::EXIT_CODE_NORMAL;
} }
$filtered = array_diff($foundFixtures, $except); $filtered = array_diff($foundFixtures, $except);
...@@ -140,7 +140,7 @@ class FixtureController extends Controller ...@@ -140,7 +140,7 @@ class FixtureController extends Controller
} }
if (!$this->confirmUnload($foundFixtures, $except)) { if (!$this->confirmUnload($foundFixtures, $except)) {
return; return self::EXIT_CODE_NORMAL;
} }
$filtered = array_diff($foundFixtures, $except); $filtered = array_diff($foundFixtures, $except);
......
...@@ -54,7 +54,7 @@ class MessageController extends Controller ...@@ -54,7 +54,7 @@ class MessageController extends Controller
$filePath = Yii::getAlias($filePath); $filePath = Yii::getAlias($filePath);
if (file_exists($filePath)) { if (file_exists($filePath)) {
if (!$this->confirm("File '{$filePath}' already exists. Do you wish to overwrite it?")) { if (!$this->confirm("File '{$filePath}' already exists. Do you wish to overwrite it?")) {
return; return self::EXIT_CODE_NORMAL;
} }
} }
copy(Yii::getAlias('@yii/views/messageConfig.php'), $filePath); copy(Yii::getAlias('@yii/views/messageConfig.php'), $filePath);
...@@ -298,7 +298,7 @@ class MessageController extends Controller ...@@ -298,7 +298,7 @@ class MessageController extends Controller
if (array_keys($translated) == $messages) { if (array_keys($translated) == $messages) {
echo "nothing new...skipped.\n"; echo "nothing new...skipped.\n";
return; return self::EXIT_CODE_NORMAL;
} }
$merged = []; $merged = [];
$untranslated = []; $untranslated = [];
......
...@@ -144,6 +144,8 @@ class MigrateController extends Controller ...@@ -144,6 +144,8 @@ class MigrateController extends Controller
* *
* @param integer $limit the number of new migrations to be applied. If 0, it means * @param integer $limit the number of new migrations to be applied. If 0, it means
* applying all available new migrations. * applying all available new migrations.
*
* @return integer the status of the action execution. 0 means normal, other values mean abnormal.
*/ */
public function actionUp($limit = 0) public function actionUp($limit = 0)
{ {
...@@ -151,7 +153,7 @@ class MigrateController extends Controller ...@@ -151,7 +153,7 @@ class MigrateController extends Controller
if (empty($migrations)) { if (empty($migrations)) {
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; return self::EXIT_CODE_NORMAL;
} }
$total = count($migrations); $total = count($migrations);
...@@ -177,7 +179,7 @@ class MigrateController extends Controller ...@@ -177,7 +179,7 @@ class MigrateController extends Controller
if (!$this->migrateUp($migration)) { if (!$this->migrateUp($migration)) {
echo "\nMigration failed. The rest of the migrations are canceled.\n"; echo "\nMigration failed. The rest of the migrations are canceled.\n";
return; return self::EXIT_CODE_ERROR;
} }
} }
echo "\nMigrated up successfully.\n"; echo "\nMigrated up successfully.\n";
...@@ -196,6 +198,8 @@ class MigrateController extends Controller ...@@ -196,6 +198,8 @@ class MigrateController extends Controller
* @param integer $limit the number of migrations to be reverted. Defaults to 1, * @param integer $limit the number of migrations to be reverted. Defaults to 1,
* meaning the last applied migration will be reverted. * meaning the last applied migration will be reverted.
* @throws Exception if the number of the steps specified is less than 1. * @throws Exception if the number of the steps specified is less than 1.
*
* @return integer the status of the action execution. 0 means normal, other values mean abnormal.
*/ */
public function actionDown($limit = 1) public function actionDown($limit = 1)
{ {
...@@ -208,7 +212,7 @@ class MigrateController extends Controller ...@@ -208,7 +212,7 @@ class MigrateController extends Controller
if (empty($migrations)) { if (empty($migrations)) {
echo "No migration has been done before.\n"; echo "No migration has been done before.\n";
return; return self::EXIT_CODE_NORMAL;
} }
$migrations = array_keys($migrations); $migrations = array_keys($migrations);
...@@ -224,7 +228,7 @@ class MigrateController extends Controller ...@@ -224,7 +228,7 @@ class MigrateController extends Controller
if (!$this->migrateDown($migration)) { if (!$this->migrateDown($migration)) {
echo "\nMigration failed. The rest of the migrations are canceled.\n"; echo "\nMigration failed. The rest of the migrations are canceled.\n";
return; return self::EXIT_CODE_ERROR;
} }
} }
echo "\nMigrated down successfully.\n"; echo "\nMigrated down successfully.\n";
...@@ -245,6 +249,8 @@ class MigrateController extends Controller ...@@ -245,6 +249,8 @@ class MigrateController extends Controller
* @param integer $limit the number of migrations to be redone. Defaults to 1, * @param integer $limit the number of migrations to be redone. Defaults to 1,
* meaning the last applied migration will be redone. * meaning the last applied migration will be redone.
* @throws Exception if the number of the steps specified is less than 1. * @throws Exception if the number of the steps specified is less than 1.
*
* @return integer the status of the action execution. 0 means normal, other values mean abnormal.
*/ */
public function actionRedo($limit = 1) public function actionRedo($limit = 1)
{ {
...@@ -257,7 +263,7 @@ class MigrateController extends Controller ...@@ -257,7 +263,7 @@ class MigrateController extends Controller
if (empty($migrations)) { if (empty($migrations)) {
echo "No migration has been done before.\n"; echo "No migration has been done before.\n";
return; return self::EXIT_CODE_NORMAL;
} }
$migrations = array_keys($migrations); $migrations = array_keys($migrations);
...@@ -273,14 +279,14 @@ class MigrateController extends Controller ...@@ -273,14 +279,14 @@ class MigrateController extends Controller
if (!$this->migrateDown($migration)) { if (!$this->migrateDown($migration)) {
echo "\nMigration failed. The rest of the migrations are canceled.\n"; echo "\nMigration failed. The rest of the migrations are canceled.\n";
return; return self::EXIT_CODE_ERROR;
} }
} }
foreach (array_reverse($migrations) as $migration) { foreach (array_reverse($migrations) as $migration) {
if (!$this->migrateUp($migration)) { if (!$this->migrateUp($migration)) {
echo "\nMigration failed. The rest of the migrations migrations are canceled.\n"; echo "\nMigration failed. The rest of the migrations migrations are canceled.\n";
return; return self::EXIT_CODE_ERROR;
} }
} }
echo "\nMigration redone successfully.\n"; echo "\nMigration redone successfully.\n";
...@@ -361,7 +367,7 @@ class MigrateController extends Controller ...@@ -361,7 +367,7 @@ class MigrateController extends Controller
echo "The migration history is set at $originalVersion.\nNo actual migration was performed.\n"; echo "The migration history is set at $originalVersion.\nNo actual migration was performed.\n";
} }
return; return self::EXIT_CODE_NORMAL;
} }
} }
...@@ -383,7 +389,7 @@ class MigrateController extends Controller ...@@ -383,7 +389,7 @@ class MigrateController extends Controller
} }
} }
return; return self::EXIT_CODE_NORMAL;
} }
} }
...@@ -598,7 +604,7 @@ class MigrateController extends Controller ...@@ -598,7 +604,7 @@ class MigrateController extends Controller
if (strpos($migration, $version . '_') === 0) { if (strpos($migration, $version . '_') === 0) {
$this->actionUp($i + 1); $this->actionUp($i + 1);
return; return self::EXIT_CODE_NORMAL;
} }
} }
...@@ -612,7 +618,7 @@ class MigrateController extends Controller ...@@ -612,7 +618,7 @@ class MigrateController extends Controller
$this->actionDown($i); $this->actionDown($i);
} }
return; return self::EXIT_CODE_NORMAL;
} }
} }
......
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