diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 6bf54622d7..633bd5a65f 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -4,6 +4,7 @@ Yii Framework 2 Change Log 2.0.16 under development ------------------------ +- Bug #16822: Create config dir recursively in message/config (Groonya) - Bug #16580: Delete unused php message files in MessageController if `$removeUnused` option is on (Groonya) - Bug #16022: Fix UniqueValidator for PostgreSQL. Checks the uniqueness of keys in `jsonb` field (lav45) - Bug #16903: Fixed 'yii\validators\NumberValidator' method 'isNotNumber' returns false for true/false value (annechko) diff --git a/framework/console/controllers/MessageController.php b/framework/console/controllers/MessageController.php index 16f4defb99..bd460ae8a7 100644 --- a/framework/console/controllers/MessageController.php +++ b/framework/console/controllers/MessageController.php @@ -218,6 +218,8 @@ class MessageController extends \yii\console\Controller public function actionConfig($filePath) { $filePath = Yii::getAlias($filePath); + $dir = dirname($filePath); + if (file_exists($filePath)) { if (!$this->confirm("File '{$filePath}' already exists. Do you wish to overwrite it?")) { return ExitCode::OK; @@ -241,7 +243,7 @@ return $array; EOD; - if (file_put_contents($filePath, $content, LOCK_EX) === false) { + if (FileHelper::createDirectory($dir) === false || file_put_contents($filePath, $content, LOCK_EX) === false) { $this->stdout("Configuration file was NOT created: '{$filePath}'.\n\n", Console::FG_RED); return ExitCode::UNSPECIFIED_ERROR; } diff --git a/tests/framework/console/controllers/BaseMessageControllerTest.php b/tests/framework/console/controllers/BaseMessageControllerTest.php index 2c7e6515d6..28812bc602 100644 --- a/tests/framework/console/controllers/BaseMessageControllerTest.php +++ b/tests/framework/console/controllers/BaseMessageControllerTest.php @@ -153,6 +153,13 @@ abstract class BaseMessageControllerTest extends TestCase "Unable to create config file from template. Command output:\n\n" . $out); } + public function testActionConfigSubDir() + { + $configFileName = Yii::getAlias('@yiiunit/runtime/not_existing_subdir') . DIRECTORY_SEPARATOR . 'message_controller_test_config-' . md5(uniqid()) . '.php'; + $out = $this->runMessageControllerAction('config', [$configFileName]); + $this->assertFileExists($configFileName, "Unable to create config file in subdirectory. Command output:\n\n" . $out); + } + public function testConfigFileNotExist() { $this->expectException('yii\\console\\Exception');