]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 578587: Make checksetup be way quieter when creating a new install
authorMax Kanat-Alexander <mkanat@bugzilla.org>
Wed, 14 Jul 2010 18:52:46 +0000 (11:52 -0700)
committerMax Kanat-Alexander <mkanat@bugzilla.org>
Wed, 14 Jul 2010 18:52:46 +0000 (11:52 -0700)
r=mkanat, a=mkanat (module owner)

Bugzilla/DB.pm
Bugzilla/DB/Mysql.pm
Bugzilla/Group.pm
Bugzilla/Install.pm
Bugzilla/User/Setting.pm
template/en/default/global/messages.html.tmpl
template/en/default/setup/strings.txt.pl

index b1d8ca40121ea8c2bb41445a26df2259342824b9..eeeff22802b13bbc042794f54874d2bafd7cbeac 100644 (file)
@@ -37,7 +37,7 @@ use base qw(DBI::db);
 
 use Bugzilla::Constants;
 use Bugzilla::Install::Requirements;
-use Bugzilla::Install::Util qw(vers_cmp);
+use Bugzilla::Install::Util qw(vers_cmp install_string);
 use Bugzilla::Install::Localconfig;
 use Bugzilla::Util;
 use Bugzilla::Error;
@@ -423,9 +423,13 @@ sub bz_setup_database {
     $self->_bz_init_schema_storage();
     
     my @desired_tables = $self->_bz_schema->get_table_list();
+    my $bugs_exists = $self->bz_table_info('bugs');
+    if (!$bugs_exists) {
+        print install_string('db_table_setup'), "\n";
+    }
 
     foreach my $table_name (@desired_tables) {
-        $self->bz_add_table($table_name);
+        $self->bz_add_table($table_name, { silently => !$bugs_exists });
     }
 }
 
@@ -435,17 +439,31 @@ sub bz_enum_initial_values {
 }
 
 sub bz_populate_enum_tables {
-    my ($self) = @_;
+    my ($self) = @_; 
+
+    my $any_severities = $self->selectrow_array(
+        'SELECT 1 FROM bug_severity ' . $self->sql_limit(1));
+    print install_string('db_enum_setup'), "\n  " if !$any_severities;
 
     my $enum_values = $self->bz_enum_initial_values();
     while (my ($table, $values) = each %$enum_values) {
         $self->_bz_populate_enum_table($table, $values);
     }
+
+    print "\n" if !$any_severities;
 }
 
 sub bz_setup_foreign_keys {
     my ($self) = @_;
 
+    # profiles_activity was the first table to get foreign keys,
+    # so if it doesn't have them, then we're setting up FKs
+    # for the first time, and should be quieter about it.
+    my $activity_fk = $self->bz_fk_info('profiles_activity', 'userid');
+    if (!$activity_fk) {
+        print get_text('install_fk_setup'), "\n";
+    }
+
     # We use _bz_schema because bz_add_table has removed all REFERENCES
     # items from _bz_real_schema.
     my @tables = $self->_bz_schema->get_table_list();
@@ -458,7 +476,7 @@ sub bz_setup_foreign_keys {
                 $add_fks{$column} = $def->{REFERENCES};
             }
         }
-        $self->bz_add_fks($table, \%add_fks);
+        $self->bz_add_fks($table, \%add_fks, { silently => !$activity_fk });
     }
 }
 
@@ -516,7 +534,7 @@ sub bz_add_fk {
 }
 
 sub bz_add_fks {
-    my ($self, $table, $column_fks) = @_;
+    my ($self, $table, $column_fks, $options) = @_;
 
     my %add_these;
     foreach my $column (keys %$column_fks) {
@@ -525,9 +543,13 @@ sub bz_add_fks {
         my $fk = $column_fks->{$column};
         $self->_check_references($table, $column, $fk);
         $add_these{$column} = $fk;
-        print get_text('install_fk_add',
-                       { table => $table, column => $column, fk => $fk })
-            . "\n" if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
+        if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE 
+            and !$options->{silently}) 
+        {
+            print get_text('install_fk_add',
+                           { table => $table, column => $column, fk => $fk }),
+                  "\n";
+        }
     }
 
     return if !scalar(keys %add_these);
@@ -650,12 +672,12 @@ sub bz_add_index_raw {
 }
 
 sub bz_add_table {
-    my ($self, $name) = @_;
+    my ($self, $name, $options) = @_;
 
     my $table_exists = $self->bz_table_info($name);
 
     if (!$table_exists) {
-        $self->_bz_add_table_raw($name);
+        $self->_bz_add_table_raw($name, $options);
         my $table_def = dclone($self->_bz_schema->get_table_abstract($name));
 
         my %fields = @{$table_def->{FIELDS}};
@@ -686,10 +708,13 @@ sub bz_add_table {
 # Returns:     nothing
 #
 sub _bz_add_table_raw {
-    my ($self, $name) = @_;
+    my ($self, $name, $options) = @_;
     my @statements = $self->_bz_schema->get_table_ddl($name);
-    print "Adding new table $name ...\n"
-        if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
+    if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE
+        and !$options->{silently})
+    {
+        print install_string('db_table_new', { table => $name }), "\n";
+    }
     $self->do($_) foreach (@statements);
 }
 
@@ -1181,7 +1206,7 @@ sub _bz_init_schema_storage {
             $self->_bz_add_table_raw('bz_schema');
         }
 
-        print "Initializing the new Schema storage...\n";
+        print install_string('db_schema_init'), "\n";
         my $sth = $self->prepare("INSERT INTO bz_schema "
                                  ." (schema_data, version) VALUES (?,?)");
         $sth->bind_param(1, $store_me, $self->BLOB_TYPE);
@@ -1284,14 +1309,13 @@ sub _bz_populate_enum_table {
 
     # If the table is empty...
     if (!$table_size) {
+        print " $table";
         my $insert = $self->prepare(
             "INSERT INTO $sql_table (value,sortkey) VALUES (?,?)");
-        print "Inserting values into the '$table' table:\n";
         my $sortorder = 0;
         my $maxlen    = max(map(length($_), @$valuelist)) + 2;
         foreach my $value (@$valuelist) {
             $sortorder += 100;
-            printf "%-${maxlen}s sortkey: $sortorder\n", "'$value'";
             $insert->execute($value, $sortorder);
         }
     }
index 7f3eb2ef8eeede28529a17dc8b068df1b7a76901..66a261c755880fe83c4869162769e4ceb9e33ec8 100644 (file)
@@ -1065,11 +1065,12 @@ this code does.
 sub _bz_build_schema_from_disk {
     my ($self) = @_;
 
-    print "Building Schema object from database...\n";
-
     my $schema = $self->_bz_schema->get_empty_schema();
 
     my @tables = $self->bz_table_list_real();
+    if (@tables) {
+        print "Building Schema object from database...\n"; 
+    }
     foreach my $table (@tables) {
         $schema->add_table($table);
         my @columns = $self->bz_table_columns_real($table);
index a8786034b1568c6f41008713cc0cfaa961f27764..eef0a70cddb4472fc005736e46add39502751880 100644 (file)
@@ -389,8 +389,11 @@ sub create {
     my ($params) = @_;
     my $dbh = Bugzilla->dbh;
 
-    print get_text('install_group_create', { name => $params->{name} }) . "\n" 
-        if Bugzilla->usage_mode == USAGE_MODE_CMDLINE;
+    my $silently = delete $params->{silently};
+    if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE and !$silently) {
+        print get_text('install_group_create', { name => $params->{name} }),
+              "\n";
+    }
 
     $dbh->bz_start_transaction();
 
index 9536f4645ff55b7dc414713cd47f7c8671c435a0..ed604d029e353fdcd1114260b217b89709a8a811 100644 (file)
@@ -174,12 +174,21 @@ use constant DEFAULT_COMPONENT => {
 };
 
 sub update_settings {
+    my $dbh = Bugzilla->dbh;
+    # If we're setting up settings for the first time, we want to be quieter.
+    my $any_settings = $dbh->selectrow_array(
+        'SELECT 1 FROM setting ' . $dbh->sql_limit(1));
+    if (!$any_settings) {
+        print get_text('install_setting_setup'), "\n";
+    }
+
     my %settings = %{SETTINGS()};
     foreach my $setting (keys %settings) {
         add_setting($setting,
                     $settings{$setting}->{options}, 
                     $settings{$setting}->{default},
-                    $settings{$setting}->{subclass});
+                    $settings{$setting}->{subclass}, undef,
+                    !$any_settings);
     }
 }
 
@@ -188,11 +197,19 @@ sub update_system_groups {
 
     $dbh->bz_start_transaction();
 
+    # If there is no editbugs group, this is the first time we're
+    # adding groups.
+    my $editbugs_exists = new Bugzilla::Group({ name => 'editbugs' });
+    if (!$editbugs_exists) {
+        print get_text('install_groups_setup'), "\n";
+    }
+
     # Create most of the system groups
     foreach my $definition (SYSTEM_GROUPS) {
         my $exists = new Bugzilla::Group({ name => $definition->{name} });
         if (!$exists) {
             $definition->{isbuggroup} = 0;
+            $definition->{silently} = !$editbugs_exists;
             my $inherited_by = delete $definition->{inherited_by};
             my $created = Bugzilla::Group->create($definition);
             # Each group in inherited_by is automatically a member of this
index 7a6c72fd3fa902924036e0dd46e237fdcb7c92ad..78e64c96b1878a68532aa26e4a22646cce3cc570 100644 (file)
@@ -125,7 +125,8 @@ sub new {
 ###############################
 
 sub add_setting {
-    my ($name, $values, $default_value, $subclass, $force_check) = @_;
+    my ($name, $values, $default_value, $subclass, $force_check,
+        $silently) = @_;
     my $dbh = Bugzilla->dbh;
 
     my $exists = _setting_exists($name);
@@ -146,7 +147,7 @@ sub add_setting {
                       undef, $name);
         }
     }
-    else {
+    elsif (!$silently) {
         print get_text('install_setting_new', { name => $name }) . "\n";
     }
     $dbh->do(q{INSERT INTO setting (name, default_value, is_enabled, subclass)
index 96225e128e3f064aeb9665d14e3985d9169469b6..fa0adbdf72b41fab6d99c9b87ef14808049a3578 100644 (file)
     that have been [% IF action == 'delete' %]deleted[% ELSE %]set to NULL[% END %]:
     [%+ values.join(', ') FILTER html %]
 
+  [% ELSIF message_tag == "install_fk_setup" %]
+    Setting up foreign keys...
+
   [% ELSIF message_tag == "install_group_create" %]
     Creating group [% name FILTER html %]...
 
+  [% ELSIF message_tag == "install_groups_setup" %]
+    Creating default groups...
+
   [% ELSIF message_tag == "install_setting_new" %]
     Adding a new user setting called '[% name FILTER html %]'
 
+  [% ELSIF message_tag == "install_setting_setup" %]
+    Setting up user preferences...
+
   [% ELSIF message_tag == "install_table_drop" %]
     Dropping the '[% name FILTER html %]' table...
 
index 20c5627c95e05a52625432cea023962e389f7e76..7e590cb3ea1df01a342a2f8c7644638f3f72ed6e 100644 (file)
@@ -44,6 +44,10 @@ EOT
 COMMANDS TO INSTALL REQUIRED MODULES (You *must* run all these commands
 and then re-run this script):
 EOT
+    db_enum_setup  => "Setting up choices for standard drop-down fields:",
+    db_schema_init => "Initializing bz_schema...",
+    db_table_new   => "Adding new table ##table##...",
+    db_table_setup => "Creating tables...",
     done => 'done.',
     extension_must_return_name => <<END,
 ##file## returned ##returned##, which is not a valid name for an extension.