@@ -663,23 +663,11 @@ private function setupModuleRegistry(SchemaSetupInterface $setup)
663
663
// change the charset to utf8mb4
664
664
$ getTableSchema = $ connection ->getCreateTable ($ setup ->getTable ('setup_module ' )) ?? '' ;
665
665
if (str_contains ($ getTableSchema , self ::OLDCHARSET )) {
666
- $ charset = $ this ->columnConfig ->getDefaultCharset ();
667
- $ collate = $ this ->columnConfig ->getDefaultCollation ();
668
- $ columnEncoding = " CHARACTER SET " .$ charset ." COLLATE " .$ collate ;
669
- $ connection ->query (
670
- sprintf (
671
- 'ALTER TABLE `%s` MODIFY COLUMN `module` varchar(50) %s,
672
- MODIFY COLUMN `schema_version` varchar(50) %s,
673
- MODIFY COLUMN `data_version` varchar(50) %s,
674
- DEFAULT CHARSET=%s, DEFAULT COLLATE=%s ' ,
675
- $ setup ->getTable ('setup_module ' ),
676
- $ columnEncoding ,
677
- $ columnEncoding ,
678
- $ columnEncoding ,
679
- $ charset ,
680
- $ collate
681
- )
682
- );
666
+ $ tableName = $ setup ->getTable ('setup_module ' );
667
+ $ columns = ['module ' => ['varchar(50) ' ,'' ],
668
+ 'schema_version ' => ['varchar(50) ' ,'' ],
669
+ 'data_version ' => ['varchar(50) ' ,'' ]];
670
+ $ this ->updateDBTable ($ tableName , $ columns , $ connection );
683
671
}
684
672
}
685
673
}
@@ -744,19 +732,9 @@ private function setupSessionTable(
744
732
// change the charset to utf8mb4
745
733
$ getTableSchema = $ connection ->getCreateTable ($ setup ->getTable ('session ' )) ?? '' ;
746
734
if (str_contains ($ getTableSchema , self ::OLDCHARSET )) {
747
- $ charset = $ this ->columnConfig ->getDefaultCharset ();
748
- $ collate = $ this ->columnConfig ->getDefaultCollation ();
749
- $ columnEncoding = " CHARACTER SET " .$ charset ." COLLATE " .$ collate ;
750
- $ connection ->query (
751
- sprintf (
752
- 'ALTER TABLE `%s` MODIFY COLUMN `session_id` varchar(255) %s ,
753
- DEFAULT CHARSET=%s, DEFAULT COLLATE=%s ' ,
754
- $ setup ->getTable ('session ' ),
755
- $ columnEncoding ,
756
- $ charset ,
757
- $ collate
758
- )
759
- );
735
+ $ tableName = $ setup ->getTable ('session ' );
736
+ $ columns = ['session_id ' => ['varchar(255) ' ,'' ]];
737
+ $ this ->updateDBTable ($ tableName , $ columns , $ connection );
760
738
}
761
739
}
762
740
}
@@ -817,19 +795,9 @@ private function setupCacheTable(
817
795
// change the charset to utf8mb4
818
796
$ getTableSchema = $ connection ->getCreateTable ($ setup ->getTable ('cache ' )) ?? '' ;
819
797
if (str_contains ($ getTableSchema , self ::OLDCHARSET )) {
820
- $ charset = $ this ->columnConfig ->getDefaultCharset ();
821
- $ collate = $ this ->columnConfig ->getDefaultCollation ();
822
- $ columnEncoding = " CHARACTER SET " .$ charset ." COLLATE " .$ collate ;
823
- $ connection ->query (
824
- sprintf (
825
- 'ALTER TABLE `%s` MODIFY COLUMN `id` varchar(200) %s,
826
- DEFAULT CHARSET=%s, DEFAULT COLLATE=%s ' ,
827
- $ setup ->getTable ('cache ' ),
828
- $ columnEncoding ,
829
- $ charset ,
830
- $ collate
831
- )
832
- );
798
+ $ tableName = $ setup ->getTable ('cache ' );
799
+ $ columns = ['id ' => ['varchar(200) ' ,'' ]];
800
+ $ this ->updateDBTable ($ tableName , $ columns , $ connection );
833
801
}
834
802
}
835
803
}
@@ -872,20 +840,9 @@ private function setupCacheTagTable(
872
840
// change the charset to utf8mb4
873
841
$ getTableSchema = $ connection ->getCreateTable ($ setup ->getTable ('cache_tag ' )) ?? '' ;
874
842
if (str_contains ($ getTableSchema , self ::OLDCHARSET )) {
875
- $ charset = $ this ->columnConfig ->getDefaultCharset ();
876
- $ collate = $ this ->columnConfig ->getDefaultCollation ();
877
- $ columnEncoding = " CHARACTER SET " .$ charset ." COLLATE " .$ collate ;
878
- $ connection ->query (
879
- sprintf (
880
- 'ALTER TABLE `%s` MODIFY COLUMN `tag` varchar(100) %s,
881
- MODIFY COLUMN `cache_id` varchar(200) %s, DEFAULT CHARSET=%s, DEFAULT COLLATE=%s ' ,
882
- $ setup ->getTable ('cache_tag ' ),
883
- $ columnEncoding ,
884
- $ columnEncoding ,
885
- $ charset ,
886
- $ collate
887
- )
888
- );
843
+ $ tableName = $ setup ->getTable ('cache_tag ' );
844
+ $ columns = ['tag ' => ['varchar(100) ' ,'' ],'cache_id ' => ['varchar(200) ' ,'' ]];
845
+ $ this ->updateDBTable ($ tableName , $ columns , $ connection );
889
846
}
890
847
}
891
848
}
@@ -948,20 +905,8 @@ private function setupFlagTable(
948
905
// change the charset to utf8mb4
949
906
$ getTableSchema = $ connection ->getCreateTable ($ tableName ) ?? '' ;
950
907
if (str_contains ($ getTableSchema , self ::OLDCHARSET )) {
951
- $ charset = $ this ->columnConfig ->getDefaultCharset ();
952
- $ collate = $ this ->columnConfig ->getDefaultCollation ();
953
- $ columnEncoding = " CHARACTER SET " .$ charset ." COLLATE " .$ collate ;
954
- $ connection ->query (
955
- sprintf (
956
- 'ALTER TABLE `%s` MODIFY COLUMN `flag_code` varchar(255) %s NOT NULL,
957
- MODIFY COLUMN `flag_data` mediumtext %s, DEFAULT CHARSET=%s, DEFAULT COLLATE=%s ' ,
958
- $ setup ->getTable ('flag ' ),
959
- $ columnEncoding ,
960
- $ columnEncoding ,
961
- $ charset ,
962
- $ collate
963
- )
964
- );
908
+ $ columns = ['flag_code ' => ['varchar(255) ' ,'NOT NULL ' ],'flag_data ' => ['mediumtext ' ,'' ]];
909
+ $ this ->updateDBTable ($ tableName , $ columns , $ connection );
965
910
}
966
911
}
967
912
}
@@ -1937,4 +1882,25 @@ private function reindexAll(): void
1937
1882
$ this ->log ->log (__ ("Indexing Error: " .$ e ->getMessage ()));
1938
1883
}
1939
1884
}
1885
+
1886
+ /**
1887
+ * Add column attribute and update table
1888
+ *
1889
+ * @param string $tableName
1890
+ * @param array $columns
1891
+ * @param AdapterInterface $connection
1892
+ * @return void
1893
+ */
1894
+ private function updateDBTable (string $ tableName , array $ columns , $ connection ) : void
1895
+ {
1896
+ $ charset = $ this ->columnConfig ->getDefaultCharset ();
1897
+ $ collate = $ this ->columnConfig ->getDefaultCollation ();
1898
+ $ encoding = " CHARACTER SET " .$ charset ." COLLATE " .$ collate ;
1899
+ $ qry = sprintf ('ALTER TABLE %s ' , $ tableName );
1900
+ foreach ($ columns as $ key => $ prop ) {
1901
+ $ qry .= "MODIFY COLUMN ` $ key` $ prop [0 ] $ encoding $ prop [1 ], " ;
1902
+ }
1903
+ $ qry .= sprintf ('DEFAULT CHARSET=%s, DEFAULT COLLATE=%s ' , $ charset , $ collate );
1904
+ $ connection ->query ($ qry );
1905
+ }
1940
1906
}
0 commit comments