Skip to content

Commit 5f4feee

Browse files
author
wurblzap%gmail.com
committed
Bug 300473: "All Closed" for components missing bug_status= in series.query.
Patch by Marc Schumann <wurblzap@gmail.com>, r=wicked, a=justdave
1 parent 418fb4b commit 5f4feee

3 files changed

Lines changed: 134 additions & 13 deletions

File tree

checksetup.pl

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# Joel Peshkin <bugreport@peshkin.net>
3535
# Lance Larsh <lance.larsh@oracle.com>
3636
# A. Karl Kornel <karl@kornel.name>
37+
# Marc Schumann <wurblzap@gmail.com>
3738
#
3839
#
3940
#
@@ -4089,6 +4090,128 @@ sub CloneEmailEvent {
40894090
$dbh->bz_drop_column("attachments", "thedata");
40904091
}
40914092

4093+
# 2005-11-26 - wurblzap@gmail.com - Bug 300473
4094+
# Repair broken automatically generated series queries for non-open bugs.
4095+
my $broken_series_indicator =
4096+
'field0-0-0=resolution&type0-0-0=notequals&value0-0-0=---';
4097+
my $broken_nonopen_series =
4098+
$dbh->selectall_arrayref("SELECT series_id, query FROM series
4099+
WHERE query LIKE '$broken_series_indicator%'");
4100+
if (@$broken_nonopen_series) {
4101+
print 'Repairing broken series...';
4102+
my $sth_nuke =
4103+
$dbh->prepare('DELETE FROM series_data WHERE series_id = ?');
4104+
# This statement is used to repair a series by replacing the broken query
4105+
# with the correct one.
4106+
my $sth_repair =
4107+
$dbh->prepare('UPDATE series SET query = ? WHERE series_id = ?');
4108+
# The corresponding series for open bugs look like one of these two
4109+
# variations (bug 225687 changed the order of bug states).
4110+
# This depends on the set of bug states representing open bugs not to have
4111+
# changed since series creation.
4112+
my $open_bugs_query_base_old =
4113+
join("&", map { "bug_status=" . url_quote($_) }
4114+
('UNCONFIRMED', 'NEW', 'ASSIGNED', 'REOPENED'));
4115+
my $open_bugs_query_base_new =
4116+
join("&", map { "bug_status=" . url_quote($_) } OpenStates());
4117+
my $sth_openbugs_series =
4118+
$dbh->prepare("SELECT series_id FROM series
4119+
WHERE query IN (?, ?)");
4120+
# Statement to find the series which has collected the most data.
4121+
my $sth_data_collected =
4122+
$dbh->prepare('SELECT count(*) FROM series_data WHERE series_id = ?');
4123+
# Statement to select a broken non-open bugs count data entry.
4124+
my $sth_select_broken_nonopen_data =
4125+
$dbh->prepare('SELECT series_date, series_value FROM series_data' .
4126+
' WHERE series_id = ?');
4127+
# Statement to select an open bugs count data entry.
4128+
my $sth_select_open_data =
4129+
$dbh->prepare('SELECT series_value FROM series_data' .
4130+
' WHERE series_id = ? AND series_date = ?');
4131+
# Statement to fix a broken non-open bugs count data entry.
4132+
my $sth_fix_broken_nonopen_data =
4133+
$dbh->prepare('UPDATE series_data SET series_value = ?' .
4134+
' WHERE series_id = ? AND series_date = ?');
4135+
# Statement to delete an unfixable broken non-open bugs count data entry.
4136+
my $sth_delete_broken_nonopen_data =
4137+
$dbh->prepare('DELETE FROM series_data' .
4138+
' WHERE series_id = ? AND series_date = ?');
4139+
4140+
foreach (@$broken_nonopen_series) {
4141+
my ($broken_series_id, $nonopen_bugs_query) = @$_;
4142+
4143+
# Determine the product-and-component part of the query.
4144+
if ($nonopen_bugs_query =~ /^$broken_series_indicator(.*)$/) {
4145+
my $prodcomp = $1;
4146+
4147+
# If there is more than one series for the corresponding open-bugs
4148+
# series, we pick the one with the most data, which should be the
4149+
# one which was generated on creation.
4150+
# It's a pity we can't do subselects.
4151+
$sth_openbugs_series->execute($open_bugs_query_base_old . $prodcomp,
4152+
$open_bugs_query_base_new . $prodcomp);
4153+
my ($found_open_series_id, $datacount) = (undef, -1);
4154+
foreach my $open_series_id ($sth_openbugs_series->fetchrow_array()) {
4155+
$sth_data_collected->execute($open_series_id);
4156+
my ($this_datacount) = $sth_data_collected->fetchrow_array();
4157+
if ($this_datacount > $datacount) {
4158+
$datacount = $this_datacount;
4159+
$found_open_series_id = $open_series_id;
4160+
}
4161+
}
4162+
4163+
if ($found_open_series_id) {
4164+
# Move along corrupted series data and correct it. The
4165+
# corruption consists of it being the number of all bugs
4166+
# instead of the number of non-open bugs, so we calculate the
4167+
# correct count by subtracting the number of open bugs.
4168+
# If there is no corresponding open-bugs count for some reason
4169+
# (shouldn't happen), we drop the data entry.
4170+
print " $broken_series_id...";
4171+
$sth_select_broken_nonopen_data->execute($broken_series_id);
4172+
while (my $rowref =
4173+
$sth_select_broken_nonopen_data->fetchrow_arrayref()) {
4174+
my ($date, $broken_value) = @$rowref;
4175+
my ($openbugs_value) =
4176+
$dbh->selectrow_array($sth_select_open_data, undef,
4177+
$found_open_series_id, $date);
4178+
if (defined($openbugs_value)) {
4179+
$sth_fix_broken_nonopen_data->execute
4180+
($broken_value - $openbugs_value,
4181+
$broken_series_id, $date);
4182+
}
4183+
else {
4184+
print "\nWARNING - During repairs of series " .
4185+
"$broken_series_id, the irreparable data\n" .
4186+
"entry for date $date was encountered and is " .
4187+
"being deleted.\n" .
4188+
"Continuing repairs...";
4189+
$sth_delete_broken_nonopen_data->execute
4190+
($broken_series_id, $date);
4191+
}
4192+
}
4193+
4194+
# Fix the broken query so that it collects correct data in the
4195+
# future.
4196+
$nonopen_bugs_query =~
4197+
s/^$broken_series_indicator/field0-0-0=resolution&type0-0-0=regexp&value0-0-0=./;
4198+
$sth_repair->execute($nonopen_bugs_query, $broken_series_id);
4199+
}
4200+
else {
4201+
print "\nWARNING - Series $broken_series_id was meant to\n" .
4202+
"collect non-open bug counts, but it has counted\n" .
4203+
"all bugs instead. It cannot be repaired\n" .
4204+
"automatically because no series that collected open\n" .
4205+
"bug counts was found. You'll probably want to delete\n" .
4206+
"or repair collected data for series $broken_series_id " .
4207+
"manually.\n" .
4208+
"Continuing repairs...";
4209+
}
4210+
}
4211+
}
4212+
print " done.\n";
4213+
}
4214+
40924215
# 2005-09-15 lance.larsh@oracle.com Bug 308717
40934216
if ($dbh->bz_column_info("series", "public")) {
40944217
# PUBLIC is a reserved word in Oracle, so renaming the column

editcomponents.cgi

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,21 @@ if ($action eq 'new') {
185185
# For localisation reasons, we get the title of the queries from the
186186
# submitted form.
187187
my $open_name = $cgi->param('open_name');
188-
my $closed_name = $cgi->param('closed_name');
189-
my @openedstatuses = OpenStates();
190-
my $statuses =
191-
join("&", map { "bug_status=" . url_quote($_) } @openedstatuses) .
192-
$prodcomp;
193-
my $resolved = "field0-0-0=resolution&type0-0-0=notequals&value0-0-0=---" .
194-
$prodcomp;
188+
my $nonopen_name = $cgi->param('nonopen_name');
189+
my $open_query = "field0-0-0=resolution&type0-0-0=notregexp&value0-0-0=." .
190+
$prodcomp;
191+
my $nonopen_query = "field0-0-0=resolution&type0-0-0=regexp&value0-0-0=." .
192+
$prodcomp;
195193

196194
# trick_taint is ok here, as these variables aren't used as a command
197195
# or in SQL unquoted
198196
trick_taint($open_name);
199-
trick_taint($closed_name);
200-
trick_taint($statuses);
201-
trick_taint($resolved);
197+
trick_taint($nonopen_name);
198+
trick_taint($open_query);
199+
trick_taint($nonopen_query);
202200

203-
push(@series, [$open_name, $statuses]);
204-
push(@series, [$closed_name, $resolved]);
201+
push(@series, [$open_name, $open_query]);
202+
push(@series, [$nonopen_name, $nonopen_query]);
205203

206204
foreach my $sdata (@series) {
207205
my $series = new Bugzilla::Series(undef, $product->name,

template/en/default/admin/components/create.html.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<input type="submit" value="Add">
7777
<input type="hidden" name="action" value="new">
7878
<input type="hidden" name='open_name' value='All Open'>
79-
<input type="hidden" name='closed_name' value='All Closed'>
79+
<input type="hidden" name='nonopen_name' value='All Closed'>
8080
<input type="hidden" name='product' value="[% product FILTER html %]">
8181

8282
</form>

0 commit comments

Comments
 (0)