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;
$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 });
}
}
}
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();
$add_fks{$column} = $def->{REFERENCES};
}
}
- $self->bz_add_fks($table, \%add_fks);
+ $self->bz_add_fks($table, \%add_fks, { silently => !$activity_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) {
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);
}
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}};
# 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);
}
$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);
# 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);
}
}
};
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);
}
}
$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