Commit ef925d69 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 975896: Bugzilla crashes when editing a flag type which is not specifically requestable

r/a=glob
parent 97cd64da
...@@ -935,10 +935,10 @@ sub remove_from_db { ...@@ -935,10 +935,10 @@ sub remove_from_db {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
$dbh->bz_start_transaction(); $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); 'SELECT id FROM flags WHERE attach_id = ?', undef, $self->id);
$dbh->do('DELETE FROM flags WHERE ' . $dbh->sql_in('id', \@flag_ids)) $dbh->do('DELETE FROM flags WHERE ' . $dbh->sql_in('id', $flag_ids))
if @flag_ids; if @$flag_ids;
$dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $self->id); $dbh->do('DELETE FROM attach_data WHERE id = ?', undef, $self->id);
$dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isobsolete = ? $dbh->do('UPDATE attachments SET mimetype = ?, ispatch = ?, isobsolete = ?
WHERE attach_id = ?', undef, ('text/plain', 0, 1, $self->id)); WHERE attach_id = ?', undef, ('text/plain', 0, 1, $self->id));
...@@ -952,7 +952,7 @@ sub remove_from_db { ...@@ -952,7 +952,7 @@ sub remove_from_db {
# As we don't call SUPER->remove_from_db we need to manually clear # As we don't call SUPER->remove_from_db we need to manually clear
# memcached here. # memcached here.
Bugzilla->memcached->clear({ table => 'attachments', id => $self->id }); 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 }); Bugzilla->memcached->clear({ table => 'flags', id => $flag_id });
} }
} }
......
...@@ -48,6 +48,7 @@ use constant VALIDATORS => { ...@@ -48,6 +48,7 @@ use constant VALIDATORS => {
############################### ###############################
#### Constructors ##### #### Constructors #####
############################### ###############################
sub remove_from_db { sub remove_from_db {
my $self = shift; my $self = shift;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
...@@ -57,13 +58,13 @@ sub remove_from_db { ...@@ -57,13 +58,13 @@ sub remove_from_db {
$dbh->bz_start_transaction(); $dbh->bz_start_transaction();
# Reclassify products to the default classification, if needed. # Reclassify products to the default classification, if needed.
my @product_ids = $dbh->selectrow_array( my $product_ids = $dbh->selectcol_arrayref(
"SELECT id FROM products WHERE classification_id = ?", 'SELECT id FROM products WHERE classification_id = ?', undef, $self->id);
undef, $self->id);
if (@product_ids) { if (@$product_ids) {
$dbh->do("UPDATE products SET classification_id = 1 WHERE " . $dbh->do('UPDATE products SET classification_id = 1 WHERE '
$dbh->sql_in('id', \@product_ids)); . $dbh->sql_in('id', $product_ids));
foreach my $id (@product_ids) { foreach my $id (@$product_ids) {
Bugzilla->memcached->clear({ table => 'products', id => $id }); Bugzilla->memcached->clear({ table => 'products', id => $id });
} }
} }
......
...@@ -185,12 +185,15 @@ sub update { ...@@ -185,12 +185,15 @@ sub update {
# Silently remove requestees from flags which are no longer # Silently remove requestees from flags which are no longer
# specifically requestable. # specifically requestable.
if (!$self->is_requesteeble) { if (!$self->is_requesteeble) {
my @ids = $dbh->selectrow_array( my $ids = $dbh->selectcol_arrayref(
"SELECT id FROM flags WHERE type_id = ?", undef, $self->id); 'SELECT id FROM flags WHERE type_id = ? AND requestee_id IS NOT NULL',
$dbh->do("UPDATE flags SET requestee_id = NULL WHERE " undef, $self->id);
. $dbh->sql_in('type_id', \@ids));
foreach my $id (@ids) { if (@$ids) {
Bugzilla->memcached->clear({ table => 'flags', id => $id }); $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 });
}
} }
} }
......
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