summaryrefslogtreecommitdiffstats
path: root/Bugzilla
diff options
context:
space:
mode:
authorDavid Lawrence <dlawrence@mozilla.com>2011-09-02 21:50:06 +0200
committerDavid Lawrence <dlawrence@mozilla.com>2011-09-02 21:50:06 +0200
commitd3144ccde7c1d3c432baaf43fe0b79a6c30eb7b0 (patch)
tree8f7fac4d4b98c80a090e74934a754443c127d846 /Bugzilla
parent9344a458c830ba066b9004c301d0fc6cabc8f229 (diff)
parentbf9156ad5f0a57a467dd46292efb2f0a47ec845e (diff)
downloadbugzilla-d3144ccde7c1d3c432baaf43fe0b79a6c30eb7b0.tar.gz
bugzilla-d3144ccde7c1d3c432baaf43fe0b79a6c30eb7b0.tar.xz
merged with bugzilla/4.2
Diffstat (limited to 'Bugzilla')
-rw-r--r--Bugzilla/Bug.pm8
-rw-r--r--Bugzilla/DB.pm14
-rw-r--r--Bugzilla/DB/Schema.pm6
-rw-r--r--Bugzilla/DB/Schema/Sqlite.pm17
-rw-r--r--Bugzilla/DB/Sqlite.pm45
-rw-r--r--Bugzilla/Install/DB.pm20
-rw-r--r--Bugzilla/Migrate.pm1
-rw-r--r--Bugzilla/Search.pm4
-rw-r--r--Bugzilla/User.pm4
9 files changed, 103 insertions, 16 deletions
diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm
index 6fdab3645..8beecdcd2 100644
--- a/Bugzilla/Bug.pm
+++ b/Bugzilla/Bug.pm
@@ -2918,10 +2918,10 @@ sub add_tag {
my $tag_id = $user->tags->{$tag}->{id};
# If this tag doesn't exist for this user yet, create it.
if (!$tag_id) {
- $dbh->do('INSERT INTO tags (user_id, name) VALUES (?, ?)',
+ $dbh->do('INSERT INTO tag (user_id, name) VALUES (?, ?)',
undef, ($user->id, $tag));
- $tag_id = $dbh->selectrow_array('SELECT id FROM tags
+ $tag_id = $dbh->selectrow_array('SELECT id FROM tag
WHERE name = ? AND user_id = ?',
undef, ($tag, $user->id));
# The list has changed.
@@ -2957,7 +2957,7 @@ sub remove_tag {
# Decrement the counter, and delete the tag if no bugs are using it anymore.
if (!--$user->tags->{$tag}->{bug_count}) {
- $dbh->do('DELETE FROM tags WHERE name = ? AND user_id = ?',
+ $dbh->do('DELETE FROM tag WHERE name = ? AND user_id = ?',
undef, ($tag, $user->id));
# The list has changed.
@@ -2974,7 +2974,7 @@ sub tags {
if (!exists $self->{tags}) {
$self->{tags} = $dbh->selectcol_arrayref(
'SELECT name FROM bug_tag
- INNER JOIN tags ON tags.id = bug_tag.tag_id
+ INNER JOIN tag ON tag.id = bug_tag.tag_id
WHERE bug_id = ? AND user_id = ?',
undef, ($self->id, $user->id));
}
diff --git a/Bugzilla/DB.pm b/Bugzilla/DB.pm
index 8d1cf32a0..a537d6131 100644
--- a/Bugzilla/DB.pm
+++ b/Bugzilla/DB.pm
@@ -93,6 +93,12 @@ use constant FULLTEXT_OR => '';
use constant WORD_START => '(^|[^[:alnum:]])';
use constant WORD_END => '($|[^[:alnum:]])';
+# On most databases, in order to drop an index, you have to first drop
+# the foreign keys that use that index. However, on some databases,
+# dropping the FK immediately before dropping the index causes problems
+# and doesn't need to be done anyway, so those DBs set this to 0.
+use constant INDEX_DROPS_REQUIRE_FK_DROPS => 1;
+
#####################################################################
# Overridden Superclass Methods
#####################################################################
@@ -947,9 +953,11 @@ sub bz_drop_index {
my $index_exists = $self->bz_index_info($table, $name);
if ($index_exists) {
- # We cannot delete an index used by a FK.
- foreach my $column (@{$index_exists->{FIELDS}}) {
- $self->bz_drop_related_fks($table, $column);
+ if ($self->INDEX_DROPS_REQUIRE_FK_DROPS) {
+ # We cannot delete an index used by a FK.
+ foreach my $column (@{$index_exists->{FIELDS}}) {
+ $self->bz_drop_related_fks($table, $column);
+ }
}
$self->bz_drop_index_raw($table, $name);
$self->_bz_real_schema->delete_index($table, $name);
diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm
index fb62965e3..33527c367 100644
--- a/Bugzilla/DB/Schema.pm
+++ b/Bugzilla/DB/Schema.pm
@@ -1000,7 +1000,7 @@ use constant ABSTRACT_SCHEMA => {
],
},
- tags => {
+ tag => {
FIELDS => [
id => {TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1},
name => {TYPE => 'varchar(64)', NOTNULL => 1},
@@ -1010,7 +1010,7 @@ use constant ABSTRACT_SCHEMA => {
DELETE => 'CASCADE'}},
],
INDEXES => [
- tags_user_id_idx => {FIELDS => [qw(user_id name)], TYPE => 'UNIQUE'},
+ tag_user_id_idx => {FIELDS => [qw(user_id name)], TYPE => 'UNIQUE'},
],
},
@@ -1021,7 +1021,7 @@ use constant ABSTRACT_SCHEMA => {
COLUMN => 'bug_id',
DELETE => 'CASCADE'}},
tag_id => {TYPE => 'INT3', NOTNULL => 1,
- REFERENCES => {TABLE => 'tags',
+ REFERENCES => {TABLE => 'tag',
COLUMN => 'id',
DELETE => 'CASCADE'}},
],
diff --git a/Bugzilla/DB/Schema/Sqlite.pm b/Bugzilla/DB/Schema/Sqlite.pm
index 4730c4f9f..aad1f17bc 100644
--- a/Bugzilla/DB/Schema/Sqlite.pm
+++ b/Bugzilla/DB/Schema/Sqlite.pm
@@ -162,6 +162,23 @@ sub get_create_database_sql {
die "Reached an unreachable point";
}
+sub _get_create_table_ddl {
+ my $self = shift;
+ my ($table) = @_;
+ my $ddl = $self->SUPER::_get_create_table_ddl(@_);
+
+ # TheSchwartz uses its own driver to access its tables, meaning
+ # that it doesn't understand "COLLATE bugzilla" and in fact
+ # SQLite throws an error when TheSchwartz tries to access its
+ # own tables, if COLLATE bugzilla is on them. We don't have
+ # to fix this elsewhere currently, because we only create
+ # TheSchwartz's tables, we never modify them.
+ if ($table =~ /^ts_/) {
+ $ddl =~ s/ COLLATE bugzilla//g;
+ }
+ return $ddl;
+}
+
sub get_type_ddl {
my $self = shift;
my $def = dclone($_[0]);
diff --git a/Bugzilla/DB/Sqlite.pm b/Bugzilla/DB/Sqlite.pm
index e40a264f0..fb6aaba97 100644
--- a/Bugzilla/DB/Sqlite.pm
+++ b/Bugzilla/DB/Sqlite.pm
@@ -25,6 +25,7 @@ use base qw(Bugzilla::DB);
use Bugzilla::Constants;
use Bugzilla::Error;
+use Bugzilla::Install::Util qw(install_string);
use DateTime;
use POSIX ();
@@ -39,6 +40,10 @@ use constant ISOLATION_LEVEL => undef;
use constant WORD_START => '(?:^|\W)';
use constant WORD_END => '(?:$|\W)';
+# For some reason, dropping the related FKs causes the index to
+# disappear early, which causes all sorts of problems.
+use constant INDEX_DROPS_REQUIRE_FK_DROPS => 0;
+
####################################
# Functions Added To SQLite Itself #
####################################
@@ -242,6 +247,46 @@ sub sql_string_until {
# bz_ methods #
###############
+sub bz_setup_database {
+ my $self = shift;
+ $self->SUPER::bz_setup_database(@_);
+
+ # If we created TheSchwartz tables with COLLATE bugzilla (during the
+ # 4.1.x development series) re-create them without it.
+ my @tables = $self->bz_table_list();
+ my @ts_tables = grep { /^ts_/ } @tables;
+ my $drop_ok;
+ foreach my $table (@ts_tables) {
+ my $create_table =
+ $self->_bz_real_schema->_sqlite_create_table($table);
+ if ($create_table =~ /COLLATE bugzilla/) {
+ if (!$drop_ok) {
+ _sqlite_jobqueue_drop_message();
+ $drop_ok = 1;
+ }
+ $self->bz_drop_table($table);
+ $self->bz_add_table($table);
+ }
+ }
+}
+
+sub _sqlite_jobqueue_drop_message {
+ # This is not translated because this situation will only happen if
+ # you are updating from a 4.1.x development version of Bugzilla using
+ # SQLite, and we don't want to maintain this string in strings.txt.pl
+ # forever for just this one uncommon circumstance.
+ print <<END;
+WARNING: We have to re-create all the database tables used by jobqueue.pl.
+If there are any pending jobs in the database (that is, emails that
+haven't been sent), they will be deleted.
+
+END
+ unless (Bugzilla->installation_answers->{NO_PAUSE}) {
+ print install_string('enter_or_ctrl_c');
+ getc;
+ }
+}
+
# XXX This needs to be implemented.
sub bz_explain { }
diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm
index af276882c..5ce3c7a4e 100644
--- a/Bugzilla/Install/DB.pm
+++ b/Bugzilla/Install/DB.pm
@@ -646,6 +646,8 @@ sub update_table_definitions {
$dbh->bz_add_column('bug_see_also', 'id',
{TYPE => 'MEDIUMSERIAL', NOTNULL => 1, PRIMARYKEY => 1});
+ _rename_tags_to_tag();
+
# 2011-01-29 LpSolit@gmail.com - Bug 616185
_migrate_user_tags();
@@ -3485,9 +3487,9 @@ sub _migrate_user_tags {
WHERE query_type != 0');
my $sth_tags = $dbh->prepare(
- 'INSERT INTO tags (user_id, name) VALUES (?, ?)');
+ 'INSERT INTO tag (user_id, name) VALUES (?, ?)');
my $sth_tag_id = $dbh->prepare(
- 'SELECT id FROM tags WHERE user_id = ? AND name = ?');
+ 'SELECT id FROM tag WHERE user_id = ? AND name = ?');
my $sth_bug_tag = $dbh->prepare('INSERT INTO bug_tag (bug_id, tag_id)
VALUES (?, ?)');
my $sth_nq = $dbh->prepare('UPDATE namedqueries SET query = ?
@@ -3586,6 +3588,20 @@ sub _migrate_disabledtext_boolean {
}
}
+sub _rename_tags_to_tag {
+ my $dbh = Bugzilla->dbh;
+ if ($dbh->bz_table_info('tags')) {
+ # If we get here, it's because the schema created "tag" as an empty
+ # table while "tags" still exists. We get rid of the empty
+ # tag table so we can do the rename over the top of it.
+ $dbh->bz_drop_table('tag');
+ $dbh->bz_drop_index('tags', 'tags_user_id_idx');
+ $dbh->bz_rename_table('tags','tag');
+ $dbh->bz_add_index('tag', 'tag_user_id_idx',
+ {FIELDS => [qw(user_id name)], TYPE => 'UNIQUE'});
+ }
+}
+
1;
__END__
diff --git a/Bugzilla/Migrate.pm b/Bugzilla/Migrate.pm
index 4d7637527..ee0dcab95 100644
--- a/Bugzilla/Migrate.pm
+++ b/Bugzilla/Migrate.pm
@@ -294,6 +294,7 @@ sub check_requirements {
my $missing = Bugzilla::Install::Requirements::_check_missing(
$self->REQUIRED_MODULES, 1);
my %results = (
+ apache => [],
pass => @$missing ? 0 : 1,
missing => $missing,
any_missing => @$missing ? 1 : 0,
diff --git a/Bugzilla/Search.pm b/Bugzilla/Search.pm
index a5c3e032d..d47e0ae99 100644
--- a/Bugzilla/Search.pm
+++ b/Bugzilla/Search.pm
@@ -2525,8 +2525,8 @@ sub _multiselect_table {
" ON keywords.keywordid = keyworddefs.id";
}
elsif ($field eq 'tag') {
- $args->{full_field} = 'tags.name';
- return "bug_tag INNER JOIN tags ON bug_tag.tag_id = tags.id"
+ $args->{full_field} = 'tag.name';
+ return "bug_tag INNER JOIN tag ON bug_tag.tag_id = tag.id"
. " AND user_id = " . $self->_user->id;
}
elsif ($field eq 'bug_group') {
diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm
index 3a3edcb5b..ea186a0fd 100644
--- a/Bugzilla/User.pm
+++ b/Bugzilla/User.pm
@@ -423,8 +423,8 @@ sub tags {
# in which case there are no bugs with this tag yet.
$self->{tags} = $dbh->selectall_hashref(
'SELECT name, id, COUNT(bug_id) AS bug_count
- FROM tags
- LEFT JOIN bug_tag ON bug_tag.tag_id = tags.id
+ FROM tag
+ LEFT JOIN bug_tag ON bug_tag.tag_id = tag.id
WHERE user_id = ? ' . $dbh->sql_group_by('id', 'name'),
'name', undef, $self->id);
}