From 2ccf81dec1fbe4e215ea47700a4e006420318621 Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Sun, 15 Mar 2015 13:50:28 +0100 Subject: Bug 902395: Enforce utf8 = true for all installations and remove the utf8 parameter r=dkl a=sgreen --- Bugzilla/DB/Mysql.pm | 32 +++++++++++++------------------- Bugzilla/DB/Oracle.pm | 5 ++--- Bugzilla/DB/Pg.pm | 2 +- Bugzilla/DB/Schema/Mysql.pm | 7 +------ Bugzilla/DB/Schema/Pg.pm | 7 +------ Bugzilla/DB/Sqlite.pm | 3 +-- 6 files changed, 19 insertions(+), 37 deletions(-) (limited to 'Bugzilla/DB') diff --git a/Bugzilla/DB/Mysql.pm b/Bugzilla/DB/Mysql.pm index 389cc6baa..402e9c58b 100644 --- a/Bugzilla/DB/Mysql.pm +++ b/Bugzilla/DB/Mysql.pm @@ -54,7 +54,7 @@ sub new { $dsn .= ";mysql_socket=$sock" if $sock; my %attrs = ( - mysql_enable_utf8 => Bugzilla->params->{'utf8'}, + mysql_enable_utf8 => 1, # Needs to be explicitly specified for command-line processes. mysql_auto_reconnect => 1, ); @@ -74,9 +74,8 @@ sub new { my $self = $class->db_new({ dsn => $dsn, user => $user, pass => $pass, attrs => \%attrs }); - # This makes sure that if the tables are encoded as UTF-8, we - # return their data correctly. - $self->do("SET NAMES utf8") if Bugzilla->params->{'utf8'}; + # This makes sure that we return table names correctly. + $self->do("SET NAMES utf8"); # all class local variables stored in DBI derived class needs to have # a prefix 'private_'. See DBI documentation. @@ -543,13 +542,11 @@ sub bz_setup_database { # If there are no tables, but the DB isn't utf8 and it should be, # then we should alter the database to be utf8. We know it should be - # if the utf8 parameter is true or there are no params at all. + # if there are no params at all. # This kind of situation happens when people create the database # themselves, and if we don't do this they will get the big # scary WARNING statement about conversion to UTF8. - if ( !$self->bz_db_is_utf8 && !@tables - && (Bugzilla->params->{'utf8'} || !scalar keys %{Bugzilla->params}) ) - { + if (!$self->bz_db_is_utf8 && !@tables) { $self->_alter_db_charset_to_utf8(); } @@ -653,7 +650,7 @@ sub bz_setup_database { MAX_ROWS=100000"); } - # Convert the database to UTF-8 if the utf8 parameter is on. + # Convert the database to UTF-8. # We check if any table isn't utf8, because lots of crazy # partial-conversion situations can happen, and this handles anything # that could come up (including having the DB charset be utf8 but not @@ -665,8 +662,8 @@ sub bz_setup_database { WHERE TABLE_SCHEMA = ? AND TABLE_COLLATION IS NOT NULL AND TABLE_COLLATION NOT LIKE 'utf8%' LIMIT 1", undef, $db_name); - - if (Bugzilla->params->{'utf8'} && $non_utf8_tables) { + + if ($non_utf8_tables) { print "\n", install_string('mysql_utf8_conversion'); if (!Bugzilla->installation_answers->{NO_PAUSE}) { @@ -681,8 +678,7 @@ sub bz_setup_database { } } - print "Converting table storage format to UTF-8. This may take a", - " while.\n"; + say 'Converting table storage format to UTF-8. This may take a while.'; foreach my $table ($self->bz_table_list_real) { my $info_sth = $self->prepare("SHOW FULL COLUMNS FROM $table"); $info_sth->execute(); @@ -699,7 +695,7 @@ sub bz_setup_database { { my $name = $column->{Field}; - print "$table.$name needs to be converted to UTF-8...\n"; + say "$table.$name needs to be converted to UTF-8..."; # These will be automatically re-created at the end # of checksetup. @@ -737,7 +733,7 @@ sub bz_setup_database { } } - print "Converting the $table table to UTF-8...\n"; + say "Converting the $table table to UTF-8..."; my $bin = "ALTER TABLE $table " . join(', ', @binary_sql); my $utf = "ALTER TABLE $table " . join(', ', @utf8_sql, 'DEFAULT CHARACTER SET utf8'); @@ -761,11 +757,9 @@ sub bz_setup_database { # a mysqldump.) So we have this change outside of the above block, # so that it just happens silently if no actual *table* conversion # needs to happen. - if (Bugzilla->params->{'utf8'} && !$self->bz_db_is_utf8) { - $self->_alter_db_charset_to_utf8(); - } + $self->_alter_db_charset_to_utf8() unless $self->bz_db_is_utf8; - $self->_fix_defaults(); + $self->_fix_defaults(); # Bug 451735 highlighted a bug in bz_drop_index() which didn't # check for FKs before trying to delete an index. Consequently, diff --git a/Bugzilla/DB/Oracle.pm b/Bugzilla/DB/Oracle.pm index 7424019ac..51678dec9 100644 --- a/Bugzilla/DB/Oracle.pm +++ b/Bugzilla/DB/Oracle.pm @@ -55,7 +55,7 @@ sub new { $dbname ||= Bugzilla->localconfig->{db_name}; # Set the language enviroment - $ENV{'NLS_LANG'} = '.AL32UTF8' if Bugzilla->params->{'utf8'}; + $ENV{'NLS_LANG'} = '.AL32UTF8'; # construct the DSN from the parameters we got my $dsn = "dbi:Oracle:host=$host;sid=$dbname"; @@ -74,8 +74,7 @@ sub new { # Set the session's default date format to match MySQL $self->do("ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'"); $self->do("ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS'"); - $self->do("ALTER SESSION SET NLS_LENGTH_SEMANTICS='CHAR'") - if Bugzilla->params->{'utf8'}; + $self->do("ALTER SESSION SET NLS_LENGTH_SEMANTICS='CHAR'"); # To allow case insensitive query. $self->do("ALTER SESSION SET NLS_COMP='ANSI'"); $self->do("ALTER SESSION SET NLS_SORT='BINARY_AI'"); diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm index 59231e2a6..37f06c354 100644 --- a/Bugzilla/DB/Pg.pm +++ b/Bugzilla/DB/Pg.pm @@ -53,7 +53,7 @@ sub new { # creating tables. $dsn .= ";options='-c client_min_messages=warning'"; - my $attrs = { pg_enable_utf8 => Bugzilla->params->{'utf8'} }; + my $attrs = { pg_enable_utf8 => 1 }; my $self = $class->db_new({ dsn => $dsn, user => $user, pass => $pass, attrs => $attrs }); diff --git a/Bugzilla/DB/Schema/Mysql.pm b/Bugzilla/DB/Schema/Mysql.pm index 1dc408654..db01e971d 100644 --- a/Bugzilla/DB/Schema/Mysql.pm +++ b/Bugzilla/DB/Schema/Mysql.pm @@ -148,12 +148,7 @@ sub _get_create_index_ddl { sub get_create_database_sql { my ($self, $name) = @_; - # We only create as utf8 if we have no params (meaning we're doing - # a new installation) or if the utf8 param is on. - my $create_utf8 = Bugzilla->params->{'utf8'} - || !defined Bugzilla->params->{'utf8'}; - my $charset = $create_utf8 ? "CHARACTER SET utf8" : ''; - return ("CREATE DATABASE `$name` $charset"); + return ("CREATE DATABASE `$name` CHARACTER SET utf8"); } # MySQL has a simpler ALTER TABLE syntax than ANSI. diff --git a/Bugzilla/DB/Schema/Pg.pm b/Bugzilla/DB/Schema/Pg.pm index 03a3b0a48..dd8531927 100644 --- a/Bugzilla/DB/Schema/Pg.pm +++ b/Bugzilla/DB/Schema/Pg.pm @@ -79,12 +79,7 @@ sub _initialize { sub get_create_database_sql { my ($self, $name) = @_; - # We only create as utf8 if we have no params (meaning we're doing - # a new installation) or if the utf8 param is on. - my $create_utf8 = Bugzilla->params->{'utf8'} - || !defined Bugzilla->params->{'utf8'}; - my $charset = $create_utf8 ? "ENCODING 'UTF8' TEMPLATE template0" : ''; - return ("CREATE DATABASE \"$name\" $charset"); + return ("CREATE DATABASE \"$name\" ENCODING 'UTF8' TEMPLATE template0"); } sub get_rename_column_ddl { diff --git a/Bugzilla/DB/Sqlite.pm b/Bugzilla/DB/Sqlite.pm index ddafc1696..0cdfa3477 100644 --- a/Bugzilla/DB/Sqlite.pm +++ b/Bugzilla/DB/Sqlite.pm @@ -93,8 +93,7 @@ sub new { my $dsn = "dbi:SQLite:dbname=$db_name"; my $attrs = { - # XXX Should we just enforce this to be always on? - sqlite_unicode => Bugzilla->params->{'utf8'}, + sqlite_unicode => 1, }; my $self = $class->db_new({ dsn => $dsn, user => '', -- cgit v1.2.3-24-g4f1b