diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 0614deafce..c8bc18afff 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -8,6 +8,7 @@ Yii Framework 2 Change Log - Bug #10850: Fixed unable to use 'definitions' and 'aliases' at `yii\widgets\MaskedInput` (rahimov, klimov-paul) - Bug #10884: Fixed MessageFormatter for formatting messages when not all parameters are given (laxity7, cebe) - Bug #10946: Fixed parameters binding to the SQL query in `yii\db\mysqlSchema::findConstraints()` (silverfire) +- Bug #10969: Fixed generator migration tool with decimal params in column (pana1990) - Bug #10974: `yii.js` - fixed error in ajaxPrefilter event handler, caused by blocked frame (maximal) - Bug: SQlite querybuilder did not create primary key with bigint for `TYPE_BIGPK` (cebe) - Enh #5469: Add mimetype validation by mask in FileValidator (kirsenn, samdark, silverfire) diff --git a/framework/console/Controller.php b/framework/console/Controller.php index 84a28050bc..f279e39931 100644 --- a/framework/console/Controller.php +++ b/framework/console/Controller.php @@ -91,7 +91,7 @@ class Controller extends \yii\base\Controller if (in_array($name, $options, true)) { $default = $this->$name; if (is_array($default)) { - $this->$name = preg_split('/\s*,\s*/', $value); + $this->$name = preg_split('/(?!\(\d+)\s*,\s*(?!\d+\))/', $value); } elseif ($default !== null) { settype($value, gettype($default)); $this->$name = $value; diff --git a/framework/helpers/BaseInflector.php b/framework/helpers/BaseInflector.php index 0e2cc3a015..4c0f07d55c 100644 --- a/framework/helpers/BaseInflector.php +++ b/framework/helpers/BaseInflector.php @@ -493,7 +493,7 @@ class BaseInflector return transliterator_transliterate($transliterator, $string); } else { - return str_replace(array_keys(static::$transliteration), static::$transliteration, $string); + return strtr($string, static::$transliteration); } } diff --git a/tests/framework/console/controllers/MigrateControllerTestTrait.php b/tests/framework/console/controllers/MigrateControllerTestTrait.php index ef1913067b..3c13094267 100644 --- a/tests/framework/console/controllers/MigrateControllerTestTrait.php +++ b/tests/framework/console/controllers/MigrateControllerTestTrait.php @@ -215,7 +215,7 @@ CODE; $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; $this->runMigrateControllerAction('create', [ $migrationName, - 'fields' => 'title:string(10):notNull:unique:defaultValue("test"),body:text:notNull' + 'fields' => 'title:string(10):notNull:unique:defaultValue("test"),body:text:notNull,price:money(11,2):notNull' ]); $file = $this->parseNameClassMigration($class); @@ -231,7 +231,8 @@ class {$class} extends Migration \$this->createTable('test', [ 'id' => \$this->primaryKey(), 'title' => \$this->string(10)->notNull()->unique()->defaultValue("test"), - 'body' => \$this->text()->notNull() + 'body' => \$this->text()->notNull(), + 'price' => \$this->money(11,2)->notNull() ]); } @@ -247,7 +248,7 @@ CODE; $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; $this->runMigrateControllerAction('create', [ $migrationName, - 'fields' => 'title:primaryKey,body:text:notNull', + 'fields' => 'title:primaryKey,body:text:notNull,price:money(11,2)', ]); $file = $this->parseNameClassMigration($class); $code = <<createTable('test', [ 'title' => \$this->primaryKey(), - 'body' => \$this->text()->notNull() + 'body' => \$this->text()->notNull(), + 'price' => \$this->money(11,2) ]); } @@ -299,6 +301,38 @@ class {$class} extends Migration } } +CODE; + $this->assertEqualsWithoutLE($code, $file); + + $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; + $this->runMigrateControllerAction('create', [ + $migrationName, + 'fields' => 'id:primaryKey,address:string,address2:string,email:string', + ]); + $file = $this->parseNameClassMigration($class); + $code = <<createTable('test', [ + 'id' => \$this->primaryKey(), + 'address' => \$this->string(), + 'address2' => \$this->string(), + 'email' => \$this->string() + ]); + } + + public function down() + { + \$this->dropTable('test'); + } +} + CODE; $this->assertEqualsWithoutLE($code, $file); } @@ -338,7 +372,7 @@ CODE; $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; $this->runMigrateControllerAction('create', [ $migrationName, - 'fields' => 'body:text:notNull' + 'fields' => 'body:text:notNull,price:money(11,2)' ]); $file = $this->parseNameClassMigration($class); $code = <<createTable('test', [ 'id' => \$this->primaryKey(), - 'body' => \$this->text()->notNull() - ]); - } -} - -CODE; - $this->assertEqualsWithoutLE($code, $file); - - $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; - $this->runMigrateControllerAction('create', [ - $migrationName, - 'fields' => 'title:primaryKey,body:text:notNull' - ]); - $file = $this->parseNameClassMigration($class); - $code = <<dropTable('test'); - } - - public function down() - { - \$this->createTable('test', [ - 'title' => \$this->primaryKey(), - 'body' => \$this->text()->notNull() + 'body' => \$this->text()->notNull(), + 'price' => \$this->money(11,2) ]); } } @@ -402,7 +407,7 @@ CODE; $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; $this->runMigrateControllerAction('create', [ $migrationName, - 'fields' => 'title:string(10):notNull,body:text:notNull,created_at:dateTime' + 'fields' => 'title:string(10):notNull,body:text:notNull,price:money(11,2):notNull,created_at:dateTime' ]); $file = $this->parseNameClassMigration($class); @@ -417,6 +422,7 @@ class {$class} extends Migration { \$this->addColumn('test', 'title', \$this->string(10)->notNull()); \$this->addColumn('test', 'body', \$this->text()->notNull()); + \$this->addColumn('test', 'price', \$this->money(11,2)->notNull()); \$this->addColumn('test', 'created_at', \$this->dateTime()); } @@ -424,6 +430,7 @@ class {$class} extends Migration { \$this->dropColumn('test', 'title'); \$this->dropColumn('test', 'body'); + \$this->dropColumn('test', 'price'); \$this->dropColumn('test', 'created_at'); } } @@ -438,39 +445,7 @@ CODE; $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; $this->runMigrateControllerAction('create', [ $migrationName, - 'fields' => 'title:string(10):notNull,body:text:notNull,created_at:dateTime' - ]); - $file = $this->parseNameClassMigration($class); - - $code = <<dropColumn('test', 'title'); - \$this->dropColumn('test', 'body'); - \$this->dropColumn('test', 'created_at'); - } - - public function down() - { - \$this->addColumn('test', 'title', \$this->string(10)->notNull()); - \$this->addColumn('test', 'body', \$this->text()->notNull()); - \$this->addColumn('test', 'created_at', \$this->dateTime()); - } -} - -CODE; - $this->assertEqualsWithoutLE($code, $file); - - $class = 'm' . gmdate('ymd_His') . '_' . $migrationName; - $this->runMigrateControllerAction('create', [ - $migrationName, - 'fields' => 'title:string(10):notNull,body:text:notNull,created_at:dateTime' + 'fields' => 'title:string(10):notNull,body:text:notNull,price:money(11,2):notNull,created_at:dateTime' ]); $file = $this->parseNameClassMigration($class); @@ -485,6 +460,7 @@ class {$class} extends Migration { \$this->dropColumn('test', 'title'); \$this->dropColumn('test', 'body'); + \$this->dropColumn('test', 'price'); \$this->dropColumn('test', 'created_at'); } @@ -492,6 +468,7 @@ class {$class} extends Migration { \$this->addColumn('test', 'title', \$this->string(10)->notNull()); \$this->addColumn('test', 'body', \$this->text()->notNull()); + \$this->addColumn('test', 'price', \$this->money(11,2)->notNull()); \$this->addColumn('test', 'created_at', \$this->dateTime()); } }