summaryrefslogtreecommitdiffstats
path: root/collectstats.pl
diff options
context:
space:
mode:
authorMarc Schumann <wurblzap@gmail.com>2012-10-16 20:26:54 +0200
committerMarc Schumann <wurblzap@gmail.com>2012-10-16 20:26:54 +0200
commitaf38912df5c0f57ad40377119b91dd03d8f9b520 (patch)
treebd04fc880184f7b063e17d12af2d13ef1f5998cc /collectstats.pl
parentb60afed2cc7c8776217444049e5ebfadf5839a24 (diff)
downloadbugzilla-af38912df5c0f57ad40377119b91dd03d8f9b520.tar.gz
bugzilla-af38912df5c0f57ad40377119b91dd03d8f9b520.tar.xz
Bug 604388 - Filenames used to store data for Old Charts should be based on product IDs, not names (avoid dataloss when renaming products).
r/a=LpSolit
Diffstat (limited to 'collectstats.pl')
-rwxr-xr-xcollectstats.pl56
1 files changed, 21 insertions, 35 deletions
diff --git a/collectstats.pl b/collectstats.pl
index 7336714bb..e1a4603f3 100755
--- a/collectstats.pl
+++ b/collectstats.pl
@@ -38,6 +38,10 @@ $| = 1;
my $datadir = bz_locations()->{'datadir'};
my $graphsdir = bz_locations()->{'graphsdir'};
+# We use a dummy product instance with ID 0, representing all products
+my $product_all = {id => 0, name => '-All-'};
+bless($product_all, 'Bugzilla::Product');
+
# Tidy up after graphing module
my $cwd = Cwd::getcwd();
if (chdir($graphsdir)) {
@@ -120,7 +124,7 @@ if ($switch{'regenerate'}) {
my $tstart = time;
my @myproducts = Bugzilla::Product->get_all;
-unshift(@myproducts, "-All-");
+unshift(@myproducts, $product_all);
my $dir = "$datadir/mining";
if (!-d $dir) {
@@ -149,18 +153,8 @@ sub collect_stats {
my $product = shift;
my $when = localtime (time);
my $dbh = Bugzilla->dbh;
- my $product_id;
-
- if (ref $product) {
- $product_id = $product->id;
- $product = $product->name;
- }
- # NB: Need to mangle the product for the filename, but use the real
- # product name in the query
- my $file_product = $product;
- $file_product =~ s/\//-/gs;
- my $file = join '/', $dir, $file_product;
+ my $file = join '/', $dir, $product->id;
my $exists = -f $file;
# if the file exists, get the old status and resolution list for that product.
@@ -186,7 +180,7 @@ sub collect_stats {
my $status_sql = q{SELECT COUNT(*) FROM bugs WHERE bug_status = ?};
my $reso_sql = q{SELECT COUNT(*) FROM bugs WHERE resolution = ?};
- if ($product ne '-All-') {
+ if ($product->id) {
$status_sql .= q{ AND product_id = ?};
$reso_sql .= q{ AND product_id = ?};
}
@@ -197,13 +191,13 @@ sub collect_stats {
my @values ;
foreach my $status (@statuses) {
@values = ($status);
- push (@values, $product_id) if ($product ne '-All-');
+ push (@values, $product->id) if ($product->id);
my $count = $dbh->selectrow_array($sth_status, undef, @values);
push(@row, $count);
}
foreach my $resolution (@resolutions) {
@values = ($resolution);
- push (@values, $product_id) if ($product ne '-All-');
+ push (@values, $product->id) if ($product->id);
my $count = $dbh->selectrow_array($sth_reso, undef, @values);
push(@row, $count);
}
@@ -216,7 +210,7 @@ sub collect_stats {
# Do not edit me! This file is generated.
#
# fields: $fields
-# Product: $product
+# Product: $product->name
# Created: $when
FIN
}
@@ -285,24 +279,14 @@ sub regenerate_stats {
my $when = localtime(time());
my $tstart = time();
- # NB: Need to mangle the product for the filename, but use the real
- # product name in the query
- if (ref $product) {
- $product = $product->name;
- }
- my $file_product = $product;
- $file_product =~ s/\//-/gs;
- my $file = join '/', $dir, $file_product;
+ my $file = join '/', $dir, $product->id;
my $and_product = "";
- my $from_product = "";
my @values = ();
- if ($product ne '-All-') {
- $and_product = q{ AND products.name = ?};
- $from_product = q{ INNER JOIN products
- ON bugs.product_id = products.id};
- push (@values, $product);
+ if ($product->id) {
+ $and_product = q{ AND product_id = ?};
+ push (@values, $product->id);
}
# Determine the start date from the date the first bug in the
@@ -312,7 +296,7 @@ sub regenerate_stats {
$dbh->sql_to_days('creation_ts') . q{ AS start_day, } .
$dbh->sql_to_days('current_date') . q{ AS end_day, } .
$dbh->sql_to_days("'1970-01-01'") .
- qq{ FROM bugs $from_product
+ qq{ FROM bugs
WHERE } . $dbh->sql_to_days('creation_ts') .
qq{ IS NOT NULL $and_product
ORDER BY start_day } . $dbh->sql_limit(1);
@@ -330,7 +314,7 @@ sub regenerate_stats {
# Do not edit me! This file is generated.
#
# fields: $fields
-# Product: $product
+# Product: $product->name
# Created: $when
FIN
# For each day, generate a line of statistics.
@@ -339,12 +323,13 @@ FIN
for (my $day = $start + 1; $day <= $end; $day++) {
# Some output feedback
my $percent_done = ($day - $start - 1) * 100 / $total_days;
- printf "\rRegenerating $product \[\%.1f\%\%]", $percent_done;
+ printf "\rRegenerating %s \[\%.1f\%\%]", $product->name,
+ $percent_done;
# Get a list of bugs that were created the previous day, and
# add those bugs to the list of bugs for this product.
$query = qq{SELECT bug_id
- FROM bugs $from_product
+ FROM bugs
WHERE bugs.creation_ts < } .
$dbh->sql_from_days($day - 1) .
q{ AND bugs.creation_ts >= } .
@@ -387,7 +372,8 @@ FIN
# Finish up output feedback for this product.
my $tend = time;
- say "\rRegenerating $product \[100.0\%] - " . delta_time($tstart, $tend);
+ say "\rRegenerating " . $product->name . ' [100.0%] - ' .
+ delta_time($tstart, $tend);
close DATA;
}