]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 352608: Make checksetup more localizable
authormkanat%bugzilla.org <>
Thu, 14 Sep 2006 13:57:29 +0000 (13:57 +0000)
committermkanat%bugzilla.org <>
Thu, 14 Sep 2006 13:57:29 +0000 (13:57 +0000)
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> (module owner) a=myk

12 files changed:
Bugzilla.pm
Bugzilla/DB.pm
Bugzilla/Group.pm
Bugzilla/Install.pm
Bugzilla/Install/Filesystem.pm
Bugzilla/Install/Localconfig.pm
Bugzilla/Template.pm
Bugzilla/User/Setting.pm
Bugzilla/Util.pm
checksetup.pl
template/en/default/global/code-error.html.tmpl
template/en/default/global/messages.html.tmpl

index 287e054ae7797fb158d5849b2eeb777ff5e803e0..c4300b0b541a35181b824d14411205a1339b2570 100644 (file)
@@ -338,7 +338,11 @@ sub switch_to_main_db {
 sub get_fields {
     my $class = shift;
     my $criteria = shift;
-    return @{Bugzilla::Field->match($criteria)};
+    # This function may be called during installation, and Field::match
+    # may fail at that time. so we want to return an empty list in that
+    # case.
+    my $fields = eval { Bugzilla::Field->match($criteria) } || [];
+    return @$fields;
 }
 
 sub custom_field_names {
index 5fceb961dc839d0ba46a9f80e456f6ce65c1ca2b..a87c1a6069889fdf01cae757eff1b4bfedbd0005 100644 (file)
@@ -424,9 +424,8 @@ sub bz_add_column {
     if ( $new_def->{NOTNULL} && !exists $new_def->{DEFAULT} 
          && !defined $init_value && $new_def->{TYPE} !~ /SERIAL/)
     {
-        die "Failed adding the column ${table}.${name}:\n  You cannot add"
-            . " a NOT NULL column with no default to an existing table,\n"
-            . "  unless you specify something for \$init_value." 
+        ThrowCodeError('column_not_null_without_default',
+                       { name => "$table.$name" });
     }
 
     my $current_def = $self->bz_column_info($table, $name);
@@ -435,8 +434,9 @@ sub bz_add_column {
         my @statements = $self->_bz_real_schema->get_add_column_ddl(
             $table, $name, $new_def, 
             defined $init_value ? $self->quote($init_value) : undef);
-        print "Adding new column $name to table $table ...\n"
-          unless i_am_cgi();
+        print get_text('install_column_add',
+                       { column => $name, table => $table }) . "\n"
+            if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
         foreach my $sql (@statements) {
             $self->do($sql);
         }
@@ -460,12 +460,8 @@ sub bz_alter_column {
             # Check for NULLs
             my $any_nulls = $self->selectrow_array(
                 "SELECT 1 FROM $table WHERE $name IS NULL");
-            if ($any_nulls) {
-                die "You cannot alter the ${table}.${name} column to be"
-                    . " NOT NULL without\nspecifying a default or"
-                    . " something for \$set_nulls_to, because"
-                    . " there are\nNULL values currently in it.";
-            }
+            ThrowCodeError('column_not_null_no_default_alter', 
+                           { name => "$table.$name" }) if ($any_nulls);
         }
         $self->bz_alter_column_raw($table, $name, $new_def, $current_def,
                                    $set_nulls_to);
@@ -604,7 +600,9 @@ sub bz_drop_column {
     if ($current_def) {
         my @statements = $self->_bz_real_schema->get_drop_column_ddl(
             $table, $column);
-        print "Deleting unused column $column from table $table ...\n";
+        print get_text('install_column_drop', 
+                       { table => $table, column => $column }) . "\n"
+            if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
         foreach my $sql (@statements) {
             # Because this is a deletion, we don't want to die hard if
             # we fail because of some local customization. If something
@@ -664,7 +662,8 @@ sub bz_drop_table {
 
     if ($table_exists) {
         my @statements = $self->_bz_schema->get_drop_table_ddl($name);
-        print "Dropping table $name...\n";
+        print get_text('install_table_drop', { name => $name }) . "\n"
+            if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
         foreach my $sql (@statements) {
             # Because this is a deletion, we don't want to die hard if
             # we fail because of some local customization. If something
@@ -683,13 +682,16 @@ sub bz_rename_column {
 
     if ($old_col_exists) {
         my $already_renamed = $self->bz_column_info($table, $new_name);
-        die "Name conflict: Cannot rename ${table}.${old_name} to"
-            . " ${table}.${new_name},\nbecause ${table}.${new_name}"
-            . " already exists." if $already_renamed;
+            ThrowCodeError('column_rename_conflict',
+                           { old => "$table.$old_name", 
+                             new => "$table.$new_name" }) if $already_renamed;
         my @statements = $self->_bz_real_schema->get_rename_column_ddl(
             $table, $old_name, $new_name);
-        print "Changing column $old_name in table $table to"
-              . " be named $new_name...\n";
+
+        print get_text('install_column_rename', 
+                       { old => "$table.$old_name", new => "$table.$new_name" })
+               . "\n" if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
+
         foreach my $sql (@statements) {
             $self->do($sql);
         }
index 93a78331ce9697b01cb19a228f2626beb7f4e6ee..69c3f51deaf7be829f15034158ccb01e81e4c7b1 100644 (file)
@@ -27,6 +27,7 @@ use strict;
 package Bugzilla::Group;
 
 use base qw(Bugzilla::Object);
+
 use Bugzilla::Constants;
 use Bugzilla::Util;
 use Bugzilla::Error;
@@ -84,7 +85,8 @@ sub create {
     my ($params) = @_;
     my $dbh = Bugzilla->dbh;
 
-    print "Creating group $params->{name}...\n" unless i_am_cgi();
+    print get_text('install_group_create', { name => $params->{name} }) . "\n" 
+        if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
 
     my $group = $class->SUPER::create(@_);
 
index c50abea95101b1e47c831a4ac7e5d8f051cca445..18f7473ae905a097949081f69e52bdb2227e1289 100644 (file)
@@ -32,6 +32,7 @@ use Bugzilla::Group;
 use Bugzilla::Product;
 use Bugzilla::User;
 use Bugzilla::User::Setting;
+use Bugzilla::Util qw(get_text);
 use Bugzilla::Version;
 
 use constant SETTINGS => {
@@ -210,7 +211,8 @@ sub create_default_product {
     # Make the default Classification if it doesn't already exist.
     if (!$dbh->selectrow_array('SELECT 1 FROM classifications')) {
         my $class = DEFAULT_CLASSIFICATION;
-        print "Creating default classification '$class->{name}'...\n";
+        print get_text('install_default_classification', 
+                       { name => $class->{name} }) . "\n";
         $dbh->do('INSERT INTO classifications (name, description)
                        VALUES (?, ?)',
                  undef, $class->{name}, $class->{description});
@@ -219,7 +221,8 @@ sub create_default_product {
     # And same for the default product/component.
     if (!$dbh->selectrow_array('SELECT 1 FROM products')) {
         my $default_prod = DEFAULT_PRODUCT;
-        print "Creating initial dummy product '$default_prod->{name}'...\n";
+        print get_text('install_default_product', 
+                       { name => $default_prod->{name} }) . "\n";
 
         $dbh->do(q{INSERT INTO products (name, description)
                         VALUES (?,?)}, 
@@ -367,19 +370,6 @@ sub _create_admin_exit {
     exit 1;
 }
 
-sub get_text {
-    my ($name, $vars) = @_;
-    my $template = Bugzilla->template;
-    $vars ||= {};
-    $vars->{'message'} = $name;
-    my $message;
-    $template->process('global/message.txt.tmpl', $vars, \$message)
-        || ThrowTemplateError($template->error());
-    # Remove the indenting that exists in messages.html.tmpl.
-    $message =~ s/^    //gm;
-    return $message;
-}
-
 1;
 
 __END__
index 3fd24cdd1df623d2a78c391d5432069b512983c9..4986e4d7abca1e29c4e75d19541e91d11cab1371 100644 (file)
@@ -27,7 +27,9 @@ package Bugzilla::Install::Filesystem;
 use strict;
 
 use Bugzilla::Constants;
+use Bugzilla::Error;
 use Bugzilla::Install::Localconfig;
+use Bugzilla::Util;
 
 use File::Find;
 use File::Path;
@@ -484,6 +486,9 @@ sub _update_old_charts {
 sub fix_all_file_permissions {
     my ($output) = @_;
 
+    my $ws_group = Bugzilla->localconfig->{'webservergroup'};
+    my $group_id = _check_web_server_group($ws_group, $output);
+
     return if ON_WINDOWS;
 
     my $fs = FILESYSTEM();
@@ -491,17 +496,10 @@ sub fix_all_file_permissions {
     my %dirs  = %{$fs->{all_dirs}};
     my %recurse_dirs = %{$fs->{recurse_dirs}};
 
-    print "Fixing file permissions...\n" if $output;
+    print get_text('install_file_perms_fix') . "\n" if $output;
 
     my $owner_id = POSIX::getuid();
-    my $group_id = POSIX::getgid();
-    my $ws_group = Bugzilla->localconfig->{'webservergroup'};
-    if ($ws_group) {
-        my $ws_group_id = getgrnam($ws_group);
-        die "There is no such group: $ws_group. Check your \$webservergroup"
-            . " setting in localconfig" unless defined $ws_group_id;
-        $group_id = $ws_group_id;
-    }
+    $group_id = POSIX::getgid() unless defined $group_id;
 
     foreach my $dir (sort keys %dirs) {
         next unless -d $dir;
@@ -561,6 +559,40 @@ sub _fix_perms {
         || warn "Failed to change permissions of $name: $!";
 }
 
+sub _check_web_server_group {
+    my ($group, $output) = @_;
+
+    my $filename = bz_locations()->{'localconfig'};
+    my $group_id;
+
+    # If we are on Windows, webservergroup does nothing
+    if (ON_WINDOWS && $group && $output) {
+        print "\n\n" . get_text('install_webservergroup_windows') . "\n\n";
+    }
+
+    # If we're not on Windows, make sure that webservergroup isn't
+    # empty.
+    elsif (!ON_WINDOWS && !$group && $output) {
+        print "\n\n" . get_text('install_webservergroup_empty') . "\n\n";
+    }
+
+    # If we're not on Windows, make sure we are actually a member of
+    # the webservergroup.
+    elsif (!ON_WINDOWS && $group) {
+        $group_id = getgrnam($group);
+        ThrowCodeError('invalid_webservergroup', { group => $group }) 
+            unless defined $group_id;
+
+        # If on unix, see if we need to print a warning about a webservergroup
+        # that we can't chgrp to
+        if ($output && $< != 0 && !grep($_ eq $group_id, split(" ", $)))) {
+            print "\n\n" . get_text('install_webservergroup_not_in') . "\n\n";
+        }
+    }
+
+    return $group_id;
+}
+
 1;
 
 __END__
index f01be8bf9f1fbd9e83a19f1538ca246ba839de8a..971c27d02f58d3fdd5d513542d0597865401bf74 100644 (file)
@@ -339,9 +339,6 @@ EOT
         exit;
     }
 
-    # Now we do some checks on localconfig values.
-    _check_web_server_group($localconfig->{'webservergroup'}) if $output;
-
     # Reset the cache for Bugzilla->localconfig so that it will be re-read
     delete Bugzilla->request_cache->{localconfig};
 
@@ -388,68 +385,6 @@ sub _get_default_diffpath {
     return $diff_binaries;
 }
 
-sub _check_web_server_group {
-    my ($group) = @_;
-
-    my $filename = bz_locations()->{'localconfig'};
-
-    # If we are on Windows, webservergroup does nothing
-    if (ON_WINDOWS && $group) {
-        print <<EOT
-
-Warning: You have set webservergroup in $filename
-Please understand that this does not bring you any security when
-running under Windows.
-Verify that the file permissions in your Bugzilla directory are
-suitable for your system. Avoid unnecessary write access.
-
-EOT
-    }
-
-    # If we're not on Windows, make sure that webservergroup isn't
-    # empty.
-    elsif (!ON_WINDOWS && !$group) {
-        print <<EOT;
-
-********************************************************************************
-WARNING! You have not entered a value for the "webservergroup" parameter
-in localconfig. This means that certain files and directories which need
-to be editable by both you and the webserver must be world writable, and
-other files (including the localconfig file which stores your database
-password) must be world readable. This means that _anyone_ who can obtain
-local access to this machine can do whatever they want to your Bugzilla
-installation, and is probably also able to run arbitrary Perl code as the
-user that the webserver runs as.
-
-You really, really, really need to change this setting.
-********************************************************************************
-EOT
-    }
-
-    # If we're not on Windows, make sure we are actually a member of
-    # the webservergroup.
-    elsif (!ON_WINDOWS && $group) {
-        # If on unix, see if we need to print a warning about a webservergroup
-        # that we can't chgrp to
-        my $webservergid = (getgrnam($group))[2]
-                            or die("no such group: $group");
-        if ($< != 0 && !grep($_ eq $webservergid, split(" ", $)))) {
-            my $root = ROOT_USER;
-            print <<EOT;
-
-Warning: you have entered a value for the "webservergroup" parameter in
-localconfig, but you are not either a) running this script as $root; or b) a
-member of this group. This can cause permissions problems and decreased
-security.  If you experience problems running Bugzilla scripts, log in as
-$root and re-run this script, become a member of the group, or remove the
-value of the "webservergroup" parameter. Note that any warnings about
-"uninitialized values" that you may see below are caused by this.
-
-EOT
-        }
-    }
-}
-
 1;
 
 __END__
index 5c5453231cc8775be8d45fe243f59ffbd8b15d2c..a60a453d6c06cd622578eddd2e10bc2a379815e7 100644 (file)
@@ -864,6 +864,9 @@ sub precompile_templates {
             $template->context->template($file);
         }
     }
+
+    # If anything created a Template object before now, clear it out.
+    delete Bugzilla->request_cache->{template};
 }
 
 # Helper for precompile_templates
index 7ed1b2f11cfa3ebeb4af3ad06b3ef0757e3dc09c..ad39d194bc32bedf3c738709a241da47d9229063 100644 (file)
@@ -23,12 +23,13 @@ package Bugzilla::User::Setting;
 use strict;
 use base qw(Exporter);
 
+
 # Module stuff
 @Bugzilla::User::Setting::EXPORT = qw(get_all_settings get_defaults
      add_setting);
 
 use Bugzilla::Error;
-use Bugzilla::Util qw{trick_taint};
+use Bugzilla::Util qw(trick_taint get_text);
 
 ###############################
 ###  Module Initialization  ###
@@ -135,7 +136,7 @@ sub add_setting {
     ($name && $default_value)
       ||  ThrowCodeError("setting_info_invalid");
 
-    print "Adding a new user setting called '$name'\n";
+    print get_text('install_setting_new', { name => $name }) . "\n";
     $dbh->do(q{INSERT INTO setting (name, default_value, is_enabled, subclass)
                     VALUES (?, ?, 1, ?)},
              undef, ($name, $default_value, $subclass));
index 8821a6c6637f639b5d42c44c1d4a26290d5fa6de..c051a987ff83901b4395152d2c8e18ed05e31009 100644 (file)
@@ -43,7 +43,8 @@ use base qw(Exporter);
                              format_time format_time_decimal validate_date
                              file_mod_time is_7bit_clean
                              bz_crypt generate_random_password
-                             validate_email_syntax clean_text);
+                             validate_email_syntax clean_text
+                             get_text);
 
 use Bugzilla::Constants;
 
@@ -397,6 +398,20 @@ sub clean_text {
     return trim($dtext);
 }
 
+sub get_text {
+    my ($name, $vars) = @_;
+    my $template = Bugzilla->template;
+    $vars ||= {};
+    $vars->{'message'} = $name;
+    my $message;
+    $template->process('global/message.txt.tmpl', $vars, \$message)
+        || ThrowTemplateError($template->error());
+    # Remove the indenting that exists in messages.html.tmpl.
+    $message =~ s/^    //gm;
+    return $message;
+}
+
+
 sub get_netaddr {
     my $ipaddr = shift;
 
@@ -683,6 +698,34 @@ ASCII 10 (LineFeed) and ASCII 13 (Carrage Return).
 Returns the parameter "cleaned" by exchanging non-printable characters with spaces.
 Specifically characters (ASCII 0 through 31) and (ASCII 127) will become ASCII 32 (Space).
 
+=item C<get_text>
+
+=over
+
+=item B<Description>
+
+This is a method of getting localized strings within Bugzilla code.
+Use this when you don't want to display a whole template, you just
+want a particular string.
+
+It uses the F<global/message.txt.tmpl> template to return a string.
+
+=item B<Params>
+
+=over
+
+=item C<$message> - The identifier for the message.
+
+=item C<$vars> - A hashref. Any variables you want to pass to the template.
+
+=back
+
+=item B<Returns>
+
+A string.
+
+=back
+
 =back
 
 =head2 Formatting Time
index d38fb5441ddc928c88ca27a799d333999dafae05..d8e920a6de2794b6e9a1e13da8398e1051285820 100755 (executable)
@@ -47,6 +47,7 @@ use 5.008;
 use File::Basename;
 use Getopt::Long qw(:config bundling);
 use Pod::Usage;
+use POSIX qw(setlocale LC_CTYPE);
 use Safe;
 
 BEGIN { chdir dirname($0); }
@@ -130,6 +131,10 @@ require Bugzilla::Install;
 
 Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
 
+# When we're running at the command line, we need to pick the right
+# language before ever creating a template object.
+$ENV{'HTTP_ACCEPT_LANGUAGE'} ||= setlocale(LC_CTYPE);
+
 ###########################################################################
 # Check and update --LOCAL-- configuration
 ###########################################################################
index c6d1ee1987a8bbc30e21a23bcdd4eea43eb23899..63ce0ffab92e7060ffa6fef9799ce91dcd6b1f69 100644 (file)
     Charts will not work without the Chart::Lines Perl module being installed.
     Run checksetup.pl for installation instructions.
 
+  [% ELSIF error == "column_not_null_without_default" %]
+    Failed adding the column [% name FILTER html %]:
+    You cannot add a NOT NULL column with no default to an existing table
+    unless you specify something for the <code>$init_value</code> argument.
+
+  [% ELSIF error == "column_not_null_no_default_alter" %]
+    You cannot alter the [% name FILTER html %] column to be NOT NULL 
+    without specifying a default or something for $set_nulls_to, because
+    there are NULL values currently in it.
+
+  [% ELSIF error == "column_rename_conflict" %]
+    Name conflict: Cannot rename [% old FILTER html %] to
+    [% new FILTER html %] because [% new FILTER html %] already exists.
+
   [% ELSIF error == "cookies_need_value" %]
     Every cookie must have a value.
 
     The series_id [% series_id FILTER html %] is not valid. It may be that
     this series has been deleted.
 
+  [% ELSIF error == "invalid_webservergroup" %]
+    There is no such group: [% group FILTER html %]. Check your $webservergroup
+    setting in [% constants.bz_locations.localconfig FILTER html %].
+
   [% ELSIF error == "list_comparison_error" %]
     Unexpected error in list comparing code.
 
index f7a5e6b6b49c41d0dc91e7e4cc29485b72d98e24..21c79b8ac15aeb99f783a16cc20e5200fe80fc30 100644 (file)
     Either this is your first time using [% terms.Bugzilla %], or your
     administrator's privileges might have accidentally been deleted.
 
+  [% ELSIF message_tag == "install_column_add" %]
+    Adding new column '[% column FILTER html %]' to the '[% table FILTER html %]' table...
+
+  [% ELSIF message_tag == "install_column_drop" %]
+    Deleting the '[% column FILTER html %]' column from the '[% table FILTER html %]' table...
+
+  [% ELSIF message_tag == "install_column_rename" %]
+    Renaming column '[% old FILTER html %]' to '[% new FILTER html %]'...
+
+  [% ELSIF message_tag == "install_default_classification" %]
+    Creating default classification '[% name FILTER html %]'...
+
+  [% ELSIF message_tag == "install_default_product" %]
+    Creating initial dummy product '[% name FILTER html %]'...
+
+  [% ELSIF message_tag == "install_file_perms_fix" %]
+    Fixing file permissions...
+
+  [% ELSIF message_tag == "install_group_create" %]
+    Creating group [% name FILTER html %]...
+
+  [% ELSIF message_tag == "install_setting_new" %]
+    Adding a new user setting called '[% name FILTER html %]'
+
+  [% ELSIF message_tag == "install_table_drop" %]
+    Dropping the '[% name FILTER html %]' table...
+
   [% ELSIF message_tag == "install_urlbase_default" %]
     Now that you have installed [% terms.Bugzilla %], you should visit the
     'Parameters' page (linked in the footer of the Administrator
     account) to ensure it is set up as you wish - this includes
     setting the 'urlbase' option to the correct url.
 
+  [% ELSIF message_tag == "install_webservergroup_empty" %]
+    ****************************************************************************
+    WARNING! You have not entered a value for the "webservergroup" parameter
+    in localconfig. This means that certain files and directories which need
+    to be editable by both you and the webserver must be world writable, and
+    other files (including the localconfig file which stores your database
+    password) must be world readable. This means that _anyone_ who can obtain
+    local access to this machine can do whatever they want to your 
+    [%+ terms.Bugzilla %] installation, and is probably also able to run 
+    arbitrary Perl code as the user that the webserver runs as.
+
+    You really, really, really need to change this setting.
+    ****************************************************************************
+
+  [% ELSIF message_tag == "install_webservergroup_not_in" %]
+    Warning: you have entered a value for the "webservergroup" parameter in
+    localconfig, but you are not either a) running this script as [% constants.ROOT_USER FILTER html %]; 
+    or b) a member of this group. This can cause permissions problems and 
+    decreased security.  If you experience problems running [% terms.Bugzilla %]
+    scripts, log in as [% constants.ROOT_USER FILTER html %] and re-run this script, become a 
+    member of the group, or remove the value of the "webservergroup" parameter.
+
+  [% ELSIF message_tag == "install_webservergroup_windows" %]
+    Warning: You have set webservergroup in [% constants.bz_locations.localconfig FILTER html %]
+    Please understand that this does not bring you any security when
+    running under Windows.
+    Verify that the file permissions in your [% terms.Bugzilla %] directory are
+    suitable for your system. Avoid unnecessary write access.
+
   [% ELSIF message_tag == "product_invalid" %]
     [% title = "$terms.Bugzilla Component Descriptions" %]
     The product <em>[% product FILTER html %]</em> does not exist