|
34 | 34 | # Joel Peshkin <bugreport@peshkin.net> |
35 | 35 | # Lance Larsh <lance.larsh@oracle.com> |
36 | 36 | # A. Karl Kornel <karl@kornel.name> |
| 37 | +# Marc Schumann <wurblzap@gmail.com> |
37 | 38 | # |
38 | 39 | # |
39 | 40 | # |
@@ -4089,6 +4090,128 @@ sub CloneEmailEvent { |
4089 | 4090 | $dbh->bz_drop_column("attachments", "thedata"); |
4090 | 4091 | } |
4091 | 4092 |
|
| 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 | + |
4092 | 4215 | # 2005-09-15 lance.larsh@oracle.com Bug 308717 |
4093 | 4216 | if ($dbh->bz_column_info("series", "public")) { |
4094 | 4217 | # PUBLIC is a reserved word in Oracle, so renaming the column |
|
0 commit comments