From ef925d6942a3462a9c1d52406a6145b5e31faefb Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Mon, 24 Feb 2014 18:14:08 +0100 Subject: Bug 975896: Bugzilla crashes when editing a flag type which is not specifically requestable r/a=glob --- Bugzilla/Attachment.pm | 8 ++++---- Bugzilla/Classification.pm | 15 ++++++++------- Bugzilla/FlagType.pm | 15 +++++++++------ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Bugzilla/Attachment.pm b/Bugzilla/Attachment.pm index d0bd8e4c2..0f3db8896 100644 --- a/Bugzilla/Attachment.pm +++ b/Bugzilla/Attachment.pm @@ -935,10 +935,10 @@ sub remove_from_db { my $dbh = Bugzilla->dbh; $dbh->bz_start_transaction(); - my @flag_ids = $dbh->selectrow_array( + my $flag_ids = $dbh->selectcol_arrayref( 'SELECT id FROM flags WHERE attach_id = ?', undef, $self->id); - $dbh->do('DELETE FROM flags WHERE ' . $dbh->sql_in('id', \@flag_ids)) - if @flag_ids; + $dbh->do('DELETE FROM flags WHERE ' . $dbh->sql_in('id', $flag_ids)) + if @$flag_ids; $dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $self->id); $dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isobsolete = ? WHERE attach_id = ?', undef, ('text/plain', 0, 1, $self->id)); @@ -952,7 +952,7 @@ sub remove_from_db { # As we don't call SUPER->remove_from_db we need to manually clear # memcached here. Bugzilla->memcached->clear({ table => 'attachments', id => $self->id }); - foreach my $flag_id (@flag_ids) { + foreach my $flag_id (@$flag_ids) { Bugzilla->memcached->clear({ table => 'flags', id => $flag_id }); } } diff --git a/Bugzilla/Classification.pm b/Bugzilla/Classification.pm index 5d488e3b9..6e88bdc63 100644 --- a/Bugzilla/Classification.pm +++ b/Bugzilla/Classification.pm @@ -48,6 +48,7 @@ use constant VALIDATORS => { ############################### #### Constructors ##### ############################### + sub remove_from_db { my $self = shift; my $dbh = Bugzilla->dbh; @@ -57,13 +58,13 @@ sub remove_from_db { $dbh->bz_start_transaction(); # Reclassify products to the default classification, if needed. - my @product_ids = $dbh->selectrow_array( - "SELECT id FROM products WHERE classification_id = ?", - undef, $self->id); - if (@product_ids) { - $dbh->do("UPDATE products SET classification_id = 1 WHERE " . - $dbh->sql_in('id', \@product_ids)); - foreach my $id (@product_ids) { + my $product_ids = $dbh->selectcol_arrayref( + 'SELECT id FROM products WHERE classification_id = ?', undef, $self->id); + + if (@$product_ids) { + $dbh->do('UPDATE products SET classification_id = 1 WHERE ' + . $dbh->sql_in('id', $product_ids)); + foreach my $id (@$product_ids) { Bugzilla->memcached->clear({ table => 'products', id => $id }); } } diff --git a/Bugzilla/FlagType.pm b/Bugzilla/FlagType.pm index c70c1598c..773996b2e 100644 --- a/Bugzilla/FlagType.pm +++ b/Bugzilla/FlagType.pm @@ -185,12 +185,15 @@ sub update { # Silently remove requestees from flags which are no longer # specifically requestable. if (!$self->is_requesteeble) { - my @ids = $dbh->selectrow_array( - "SELECT id FROM flags WHERE type_id = ?", undef, $self->id); - $dbh->do("UPDATE flags SET requestee_id = NULL WHERE " - . $dbh->sql_in('type_id', \@ids)); - foreach my $id (@ids) { - Bugzilla->memcached->clear({ table => 'flags', id => $id }); + my $ids = $dbh->selectcol_arrayref( + 'SELECT id FROM flags WHERE type_id = ? AND requestee_id IS NOT NULL', + undef, $self->id); + + if (@$ids) { + $dbh->do('UPDATE flags SET requestee_id = NULL WHERE ' . $dbh->sql_in('id', $ids)); + foreach my $id (@$ids) { + Bugzilla->memcached->clear({ table => 'flags', id => $id }); + } } } -- cgit v1.2.3-24-g4f1b