$a{'datasize'}) = &::FetchSQLData();
# Retrieve a list of flags for this attachment.
- $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'} });
+ $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'},
+ 'is_active' => 1 });
# We will display the edit link if the user can edit the attachment;
# ie the are the submitter, or they have canedit.
$flag_type->{'flags'} =
Bugzilla::Flag::match({ 'bug_id' => $self->{bug_id},
'type_id' => $flag_type->{'id'},
- 'target_type' => 'bug' });
+ 'target_type' => 'bug',
+ 'is_active' => 1 });
}
$self->{'flag_types'} = $flag_types;
$self->{'any_flags_requesteeble'} = grep($_->{'is_requesteeble'}, @$flag_types);
my $num_attachment_flag_types =
Bugzilla::FlagType::count({ 'target_type' => 'attachment',
'product_id' => $self->{'product_id'},
- 'component_id' => $self->{'component_id'},
- 'is_active' => 1 });
+ 'component_id' => $self->{'component_id'} });
my $num_attachment_flags =
Bugzilla::Flag::count({ 'target_type' => 'attachment',
- 'bug_id' => $self->{bug_id} });
+ 'bug_id' => $self->{bug_id},
+ 'is_active' => 1 });
$self->{'show_attachment_flags'}
= $num_attachment_flag_types || $num_attachment_flags;
# Rights Reserved.
#
# Contributor(s): Myk Melez <myk@mozilla.org>
+# Jouni Heikniemi <jouni@heikniemi.net>
################################################################################
# Module Initialization
# basic sets of columns and tables for getting flags from the database
my @base_columns =
- ("1", "id", "type_id", "bug_id", "attach_id", "requestee_id", "setter_id",
- "status");
+ ("is_active", "id", "type_id", "bug_id", "attach_id", "requestee_id",
+ "setter_id", "status");
# Note: when adding tables to @base_tables, make sure to include the separator
# (i.e. a comma or words like "LEFT OUTER JOIN") before the table name,
my $flag = get($id);
$flag || ThrowCodeError("flag_nonexistent", { id => $id });
+ # Note that the deletedness of the flag (is_active or not) is not
+ # checked here; we do want to allow changes to deleted flags in
+ # certain cases. Flag::modify() will revive the modified flags.
+ # See bug 223878 for details.
+
# Make sure the user chose a valid status.
grep($status eq $_, qw(X + - ?))
|| ThrowCodeError("flag_status_invalid",
# Take a snapshot of flags before any changes.
my $flags = match({ 'bug_id' => $target->{'bug'}->{'id'} ,
- 'attach_id' => $target->{'attachment'}->{'id'} });
+ 'attach_id' => $target->{'attachment'}->{'id'} ,
+ 'is_active' => 1 });
my @old_summaries;
foreach my $flag (@$flags) {
my $summary = $flag->{'type'}->{'name'} . $flag->{'status'};
AND (bugs.product_id = i.product_id OR i.product_id IS NULL)
AND (bugs.component_id = i.component_id OR i.component_id IS NULL))
WHERE bugs.bug_id = $target->{'bug'}->{'id'}
+ AND flags.is_active = 1
AND i.type_id IS NULL
");
clear(&::FetchOneColumn()) while &::MoreSQLData();
FROM flags, bugs, flagexclusions e
WHERE bugs.bug_id = $target->{'bug'}->{'id'}
AND flags.bug_id = bugs.bug_id
- AND flags.type_id = e.type_id
+ AND flags.type_id = e.type_id
+ AND flags.is_active = 1
AND (bugs.product_id = e.product_id OR e.product_id IS NULL)
AND (bugs.component_id = e.component_id OR e.component_id IS NULL)
");
# Take a snapshot of flags after changes.
$flags = match({ 'bug_id' => $target->{'bug'}->{'id'} ,
- 'attach_id' => $target->{'attachment'}->{'id'} });
+ 'attach_id' => $target->{'attachment'}->{'id'} ,
+ 'is_active' => 1 });
my @new_summaries;
foreach my $flag (@$flags) {
my $summary = $flag->{'type'}->{'name'} . $flag->{'status'};
sub modify {
# Modifies flags in the database when a user changes them.
+ # Note that modified flags are always set active (is_active = 1) -
+ # this will revive deleted flags that get changed through
+ # attachment.cgi midairs. See bug 223878 for details.
my ($data, $timestamp) = @_;
SET setter_id = $::userid ,
requestee_id = NULL ,
status = '$status' ,
- modification_date = $timestamp
+ modification_date = $timestamp ,
+ is_active = 1
WHERE id = $flag->{'id'}");
# Send an email notifying the relevant parties about the fulfillment.
SET setter_id = $::userid ,
requestee_id = $requestee_id ,
status = '$status' ,
- modification_date = $timestamp
+ modification_date = $timestamp ,
+ is_active = 1
WHERE id = $flag->{'id'}");
# Send an email notifying the relevant parties about the request.
notify($flag, "request/email.txt.tmpl");
}
}
- # The user unset the flag, so delete it from the database.
+ # The user unset the flag; set is_active = 0
elsif ($status eq 'X') {
clear($flag->{'id'});
}
my $flag = get($id);
&::PushGlobalSQLState();
- &::SendSQL("DELETE FROM flags WHERE id = $id");
+ &::SendSQL("UPDATE flags SET is_active = 0 WHERE id = $id");
&::PopGlobalSQLState();
-
+
+ $flag->{'exists'} = 0;
# Set the flag's status to "cleared" so the email template
# knows why email is being sent about the request.
$flag->{'status'} = "X";
elsif ($field eq 'requestee_id') { push(@criteria, "requestee_id = $value") }
elsif ($field eq 'setter_id') { push(@criteria, "setter_id = $value") }
elsif ($field eq 'status') { push(@criteria, "status = '$value'") }
+ elsif ($field eq 'is_active') { push(@criteria, "is_active = $value") }
}
return @criteria;
my ($exists, $id, $type_id, $bug_id, $attach_id,
$requestee_id, $setter_id, $status) = @_;
+ return undef unless defined($exists);
+
my $flag =
{
exists => $exists ,
AND (bugs.product_id = i.product_id OR i.product_id IS NULL)
AND (bugs.component_id = i.component_id OR i.component_id IS NULL))
WHERE flags.type_id IN ($ids)
+ AND flags.is_active = 1
AND i.type_id IS NULL
");
Bugzilla::Flag::clear(&::FetchOneColumn()) while &::MoreSQLData();
WHERE flags.type_id IN ($ids)
AND flags.bug_id = bugs.bug_id
AND flags.type_id = e.type_id
+ AND flags.is_active = 1
AND (bugs.product_id = e.product_id OR e.product_id IS NULL)
AND (bugs.component_id = e.component_id OR e.component_id IS NULL)
");
# negative conditions (f.e. "flag isn't review+").
my $flags = "flags_$chartid";
push(@supptables, "LEFT JOIN flags $flags " .
- "ON bugs.bug_id = $flags.bug_id");
+ "ON bugs.bug_id = $flags.bug_id " .
+ "AND $flags.is_active = 1");
my $flagtypes = "flagtypes_$chartid";
push(@supptables, "LEFT JOIN flagtypes $flagtypes " .
"ON $flags.type_id = $flagtypes.id");
$a{'description'}, $a{'ispatch'}, $a{'isobsolete'}, $a{'isprivate'},
$a{'datasize'}) = FetchSQLData();
$a{'isviewable'} = isViewable($a{'contenttype'});
- $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'} });
+ $a{'flags'} = Bugzilla::Flag::match({ 'attach_id' => $a{'attachid'},
+ 'is_active' => 1 });
# Add the hash representing the attachment to the array of attachments.
push @attachments, \%a;
SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added)
VALUES ($::FORM{'bugid'}, $obsolete_id, $::userid, NOW(), $fieldid, '0', '1')");
# If the obsolete attachment has pending flags, migrate them to the new attachment.
- if (Bugzilla::Flag::count({ 'attach_id' => $obsolete_id , 'status' => 'pending' })) {
+ if (Bugzilla::Flag::count({ 'attach_id' => $obsolete_id ,
+ 'status' => 'pending',
+ 'is_active' => 1 })) {
Bugzilla::Flag::migrate($obsolete_id, $attachid);
}
}
'component_id' => $component_id });
foreach my $flag_type (@$flag_types) {
$flag_type->{'flags'} = Bugzilla::Flag::match({ 'type_id' => $flag_type->{'id'},
- 'attach_id' => $::FORM{'id'} });
+ 'attach_id' => $::FORM{'id'},
+ 'is_active' => 1 });
}
$vars->{'flag_types'} = $flag_types;
$vars->{'any_flags_requesteeble'} = grep($_->{'is_requesteeble'}, @$flag_types);
setter_id MEDIUMINT NULL ,
requestee_id MEDIUMINT NULL ,
+
+ is_active TINYINT NOT NULL DEFAULT 1,
INDEX(bug_id, attach_id) ,
INDEX(setter_id) ,
}
}
+# 2004-07-03 - Make it possible to disable flags without deleting them
+# from the database. Bug 223878, jouni@heikniemi.net
+
+AddField('flags', 'is_active', 'tinyint not null default 1');
+
# If you had to change the --TABLE-- definition in any way, then add your
AND (bugs.component_id = i.component_id OR i.component_id IS NULL))
WHERE flags.type_id = $::FORM{'id'}
AND flags.bug_id = bugs.bug_id
+ AND flags.is_active = 1
AND i.type_id IS NULL
");
Bugzilla::Flag::clear(FetchOneColumn()) while MoreSQLData();
WHERE flags.type_id = $::FORM{'id'}
AND flags.bug_id = bugs.bug_id
AND flags.type_id = e.type_id
+ AND flags.is_active = 1
AND (bugs.product_id = e.product_id OR e.product_id IS NULL)
AND (bugs.component_id = e.component_id OR e.component_id IS NULL)
");
validateID();
# check if we need confirmation to delete:
- my $count = Bugzilla::Flag::count({ 'type_id' => $::FORM{'id'} });
+ my $count = Bugzilla::Flag::count({ 'type_id' => $::FORM{'id'},
+ 'is_active' => 1 });
if ($count > 0) {
$vars->{'flag_type'} = Bugzilla::FlagType::get($::FORM{'id'});
AND flags.bug_id = bugs.bug_id
";
+ # Non-deleted flags only
+ $query .= " AND flags.is_active = 1 ";
+
# Limit query to pending requests.
$query .= " AND flags.status = '?' " unless $cgi->param('status');