@@ -77,7 +77,7 @@ class DbSchemaWriter implements DbSchemaWriterInterface
77
77
*/
78
78
private DtoFactoriesTable $ columnConfig ;
79
79
80
- private const COLUMN_TYPE = ['varchar ' , 'char ' , 'text ' , 'mediumtext ' , 'longtext ' ];
80
+ private const TEXTUAL_COLUMN_TYPES = ['varchar ' , 'char ' , 'text ' , 'mediumtext ' , 'longtext ' ];
81
81
82
82
/**
83
83
* @param ResourceConnection $resourceConnection
@@ -110,7 +110,7 @@ public function createTable($tableName, $resource, array $definition, array $opt
110
110
{
111
111
if (count ($ definition )) {
112
112
foreach ($ definition as $ index => $ value ) {
113
- if ($ this ->isColumnExists ($ value , self ::COLUMN_TYPE )) {
113
+ if ($ this ->isColumnTypes ($ value , self ::TEXTUAL_COLUMN_TYPES )) {
114
114
if (str_contains ($ index , 'column ' )) {
115
115
$ definition [$ index ] = $ this ->setDefaultCharsetAndCollation ($ value );
116
116
}
@@ -192,6 +192,11 @@ private function getDropElementSQL($type, $name)
192
192
public function addElement ($ elementName , $ resource , $ tableName , $ elementDefinition , $ elementType )
193
193
{
194
194
$ addElementSyntax = $ elementType === Column::TYPE ? 'ADD COLUMN %s ' : 'ADD %s ' ;
195
+ if ($ elementType === Column::TYPE ) {
196
+ if ($ this ->isColumnTypes ($ elementDefinition , self ::TEXTUAL_COLUMN_TYPES )) {
197
+ $ elementDefinition = $ this ->setDefaultCharsetAndCollation ($ elementDefinition );
198
+ }
199
+ }
195
200
$ sql = sprintf (
196
201
$ addElementSyntax ,
197
202
$ elementDefinition
@@ -237,7 +242,7 @@ public function modifyTableOption($tableName, $resource, $optionName, $optionVal
237
242
*/
238
243
public function modifyColumn ($ columnName , $ resource , $ tableName , $ columnDefinition )
239
244
{
240
- if ($ this ->isColumnExists ($ columnDefinition , self ::COLUMN_TYPE )) {
245
+ if ($ this ->isColumnTypes ($ columnDefinition , self ::TEXTUAL_COLUMN_TYPES )) {
241
246
$ columnDefinition = $ this ->setDefaultCharsetAndCollation ($ columnDefinition );
242
247
}
243
248
@@ -499,16 +504,16 @@ private function setDefaultCharsetAndCollation(string $columnDefinition): string
499
504
}
500
505
501
506
/**
502
- * Checks if any column of type varchar,char or text (mediumtext/longtext)
507
+ * Checks if any column is of the types passed in $columnTypes
503
508
*
504
509
* @param string $definition
505
- * @param array $columntypes
510
+ * @param array $columnTypes
506
511
* @return bool
507
512
*/
508
- private function isColumnExists (string $ definition , array $ columntypes ): bool
513
+ private function isColumnTypes (string $ definition , array $ columnTypes ): bool
509
514
{
510
515
$ type = explode (' ' , $ definition );
511
- $ pattern = '/\b( ' . implode ('| ' , array_map ('preg_quote ' , $ columntypes )) . ')\b/i ' ;
516
+ $ pattern = '/\b( ' . implode ('| ' , array_map ('preg_quote ' , $ columnTypes )) . ')\b/i ' ;
512
517
return preg_match ($ pattern , $ type [1 ]) === 1 ;
513
518
}
514
519
}
0 commit comments