Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MT7] Introduce DatabaseEnableUTF8 MTC-28790 #2575

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ jobs:

- # Perl 5.32 / PHP 7.4 / MariaDB 10.5
if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/*.t"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/*.t"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/mt7/[^t]*"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/mt7/[^t]*"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/mt7/t*"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/mt7/t*"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/app/ t/class/ t/cms/ t/model/ t/mt_object/ t/object_driver/ t/task/ t/template/ t/tools t/util/"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/app/ t/class/ t/cms/ t/model/ t/mt_object/ t/object_driver/ t/task/ t/template/ t/tools t/util/"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/cms_permission/"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/cms_permission/"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_FORCE_DATAAPI_VERSION=5 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/data_api/"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 MT_TEST_FORCE_DATAAPI_VERSION=5 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/data_api/"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/tag/"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 prove -j4 -PMySQLPool=MT::Test::Env -It/lib t/tag/"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="prove -j4 -PMySQLPool=MT::Test::Env -It/lib plugins/*/t"
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="MT_TEST_DATABASE_ENABLE_UTF8=1 prove -j4 -PMySQLPool=MT::Test::Env -It/lib plugins/*/t"
- if: (type = cron AND (branch = master OR branch = develop OR branch =~ /^support-/ OR branch =~ /^release-/)) OR branch =~ /cron/
env: TEST_IMAGE_NAME="bullseye" TEST_COMMAND="phpunit && make test-php-lint"

Expand Down
1 change: 1 addition & 0 deletions lib/MT/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2359,6 +2359,7 @@ BEGIN {
'WaitAfterReboot' => { default => '1.0' },
'DisableMetaRefresh' => { default => 1 },
'DynamicTemplateAllowPHP' => { default => 1 },
'DatabaseEnableUTF8' => { default => 0 },
'TrimFilePath' => { default => 0 },
},
upgrade_functions => \&load_upgrade_fns,
Expand Down
32 changes: 17 additions & 15 deletions lib/MT/Object.pm
Original file line number Diff line number Diff line change
Expand Up @@ -354,21 +354,23 @@ sub install_properties {
$class->add_trigger(
'__core_final_post_load',
sub {
my ($obj) = @_;
my $data = $obj->{column_values};
my $props = $obj->properties;
my $cols = $props->{columns};
my $col_defs = $obj->column_defs;
my %is_blob;
for my $col (@$cols) {
$is_blob{$col} = 1
if $col_defs->{$col}
&& $col_defs->{$col}{type} =~ /\bblob\b/;
}
foreach ( keys %$data ) {
my $v = $data->{$_};
if ( !( MT::Util::Encode::is_utf8( $data->{$_} ) ) && !$is_blob{$_} ) {
$data->{$_} = MT::Util::Encode::decode( $enc, $v );
my ($obj) = @_;
if ($obj->driver->dbd->need_encode) {
my $data = $obj->{column_values};
my $props = $obj->properties;
my $cols = $props->{columns};
my $col_defs = $props->{column_defs_parsed} ? $props->{column_defs} : $obj->column_defs;
my %is_blob;
for my $col (@$cols) {
$is_blob{$col} = 1
if $col_defs->{$col}
&& $col_defs->{$col}{type} =~ /\bblob\b/;
}
foreach ( keys %$data ) {
my $v = $data->{$_};
if ( !$is_blob{$_} && !( MT::Util::Encode::is_utf8($v) ) ) {
$data->{$_} = MT::Util::Encode::decode( $enc, $v );
}
}
}
$obj->{__core_final_post_load_mark} = 1;
Expand Down
9 changes: 8 additions & 1 deletion lib/MT/ObjectDriver/Driver/DBD/Legacy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use warnings;
## _attributes with the D::OD::DBD::bind_param_attributes we'd inherit.
use base qw();

my $NeedEncode;

sub ts2db { $_[1] }
sub db2ts { $_[1] }

Expand Down Expand Up @@ -57,7 +59,12 @@ sub db_column_name {

sub configure { }

sub need_encode { 1; }
sub enable_utf8_option_name { }

sub need_encode {
return $NeedEncode if defined $NeedEncode;
$NeedEncode = MT->config->DatabaseEnableUTF8 ? 0 : 1;
}

1;
__END__
Expand Down
6 changes: 6 additions & 0 deletions lib/MT/ObjectDriver/Driver/DBD/mysql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ use base qw(
MT::ErrorHandler
);

sub enable_utf8_option_name {
require DBD::mysql;
(my $dbd_version = DBD::mysql->VERSION) =~ s/_.+$//;
$dbd_version >= 4.032 ? 'mysql_enable_utf8mb4' : 'mysql_enable_utf8';
}

sub dsn_from_config {
my $dbd = shift;
my $dsn = $dbd->SUPER::dsn_from_config(@_);
Expand Down
4 changes: 4 additions & 0 deletions lib/MT/ObjectDriver/Driver/DBI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ sub init {
my $cfg = $mt->config;
$opts->{RaiseError} = $cfg->DBIRaiseError;
$opts->{ShowErrorStatement} = $cfg->DBIShowErrorStatement if $MT::DebugMode;
if ($cfg->DatabaseEnableUTF8) {
my $key = $driver->dbd->enable_utf8_option_name;
$opts->{$key} = 1 if $key;
}

$driver->connect_options($opts);
$driver;
Expand Down
1 change: 1 addition & 0 deletions t/lib/MT/Test/Env.pm
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ sub write_config {
DebugMode => $ENV{MT_TEST_DEBUG_MODE} || 0,
BuilderModule => $ENV{MT_TEST_BUILDER} || 'MT::Builder',
DisableObjectCache => $ENV{MT_TEST_DISABLE_OBJECT_CACHE} || 0,
DatabaseEnableUTF8 => $ENV{MT_TEST_DATABASE_ENABLE_UTF8} || 0,
);

if ($extra) {
Expand Down