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 {
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 });
}
}
......
......@@ -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 });
}
}
......
......@@ -185,14 +185,17 @@ 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) {
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 });
}
}
}
$dbh->bz_commit_transaction();
return $changes;
......
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