From 921b102961002eba964175cc216b575f1eea1fc1 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Pan Date: Fri, 26 Feb 2016 03:34:03 +0100 Subject: [PATCH 1/3] Fixed #10969: generator migration tool not works with decimal params in column --- framework/CHANGELOG.md | 1 + framework/console/Controller.php | 2 +- .../MigrateControllerTestTrait.php | 85 ++++--------------- 3 files changed, 17 insertions(+), 71 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index c11e7e346d..fecc86c2bb 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: 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) - Enh #9893: `yii.js` handleAction enhanced to support for data-form attribute, so links can trigger specific forms (SamMousa) 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/tests/framework/console/controllers/MigrateControllerTestTrait.php b/tests/framework/console/controllers/MigrateControllerTestTrait.php index 6b48f07898..7ecd7f6928 100644 --- a/tests/framework/console/controllers/MigrateControllerTestTrait.php +++ b/tests/framework/console/controllers/MigrateControllerTestTrait.php @@ -212,7 +212,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); @@ -228,7 +228,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() ]); } @@ -244,7 +245,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) ]); } @@ -335,7 +337,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) ]); } } @@ -399,7 +372,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); @@ -414,6 +387,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()); } @@ -421,6 +395,7 @@ class {$class} extends Migration { \$this->dropColumn('test', 'title'); \$this->dropColumn('test', 'body'); + \$this->dropColumn('test', 'price'); \$this->dropColumn('test', 'created_at'); } } @@ -435,39 +410,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); @@ -482,6 +425,7 @@ class {$class} extends Migration { \$this->dropColumn('test', 'title'); \$this->dropColumn('test', 'body'); + \$this->dropColumn('test', 'price'); \$this->dropColumn('test', 'created_at'); } @@ -489,6 +433,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()); } } From 03cb361a59abb4427e545f45b013dd5480e7ad60 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Pan Date: Fri, 26 Feb 2016 15:57:41 +0100 Subject: [PATCH 2/3] Fixed #10969: add more tests --- .../MigrateControllerTestTrait.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/framework/console/controllers/MigrateControllerTestTrait.php b/tests/framework/console/controllers/MigrateControllerTestTrait.php index 7ecd7f6928..4813e91349 100644 --- a/tests/framework/console/controllers/MigrateControllerTestTrait.php +++ b/tests/framework/console/controllers/MigrateControllerTestTrait.php @@ -298,6 +298,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); } From e50b300a0f7d0d2cc6d308271a4aae0a7bdf693a Mon Sep 17 00:00:00 2001 From: DrDeath72 Date: Fri, 26 Feb 2016 22:31:39 +0500 Subject: [PATCH 3/3] string array replace change shorten :D --- framework/helpers/BaseInflector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } }