Commit 1c2902ec authored by Max Kanat-Alexander's avatar Max Kanat-Alexander

Bug 578587: Make checksetup be way quieter when creating a new install

r=mkanat, a=mkanat (module owner)
parent 32b3964d
......@@ -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);
}
}
......
......@@ -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);
......
......@@ -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();
......
......@@ -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
......
......@@ -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)
......
......@@ -666,12 +666,21 @@
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...
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment