Commit 5de2bb1d authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 303690: Eliminate deprecated Bugzilla::DB routines from collectstats.pl and…

Bug 303690: Eliminate deprecated Bugzilla::DB routines from collectstats.pl and whineatnews.pl - Patch by Gabriel Sales de Oliveira <gabriel@async.com.br> r=LpSolit a=justdave
parent 6d348ff9
...@@ -126,6 +126,7 @@ sub collect_stats { ...@@ -126,6 +126,7 @@ sub collect_stats {
my $product = shift; my $product = shift;
my $when = localtime (time); my $when = localtime (time);
my $product_id = get_product_id($product) unless $product eq '-All-'; my $product_id = get_product_id($product) unless $product eq '-All-';
my $dbh = Bugzilla->dbh;
die "Unknown product $product" unless ($product_id or $product eq '-All-'); die "Unknown product $product" unless ($product_id or $product eq '-All-');
...@@ -137,26 +138,35 @@ sub collect_stats { ...@@ -137,26 +138,35 @@ sub collect_stats {
my $exists = -f $file; my $exists = -f $file;
if (open DATA, ">>$file") { if (open DATA, ">>$file") {
push my @row, &today; push (my @row, &today);
my $status_sql = q{SELECT COUNT(*)
FROM bugs
WHERE bug_status = ?};
foreach my $status ('NEW', 'ASSIGNED', 'REOPENED', 'UNCONFIRMED', 'RESOLVED', 'VERIFIED', 'CLOSED') { my $reso_sql = q{SELECT COUNT(*)
if( $product eq "-All-" ) { FROM bugs
SendSQL("SELECT COUNT(bug_status) FROM bugs WHERE bug_status='$status'"); WHERE resolution = ?};
} else {
SendSQL("SELECT COUNT(bug_status) FROM bugs WHERE bug_status='$status' AND product_id=$product_id");
}
push @row, FetchOneColumn(); if ($product ne '-All-') {
$status_sql .= q{ AND product_id = ?};
$reso_sql .= q{ AND product_id = ?};
} }
foreach my $resolution ('FIXED', 'INVALID', 'WONTFIX', 'LATER', 'REMIND', 'DUPLICATE', 'WORKSFORME', 'MOVED') { my $sth_status = $dbh->prepare($status_sql);
if( $product eq "-All-" ) { my $sth_reso = $dbh->prepare($reso_sql);
SendSQL("SELECT COUNT(resolution) FROM bugs WHERE resolution='$resolution'");
} else {
SendSQL("SELECT COUNT(resolution) FROM bugs WHERE resolution='$resolution' AND product_id=$product_id");
}
push @row, FetchOneColumn(); my @values ;
foreach my $status ('NEW', 'ASSIGNED', 'REOPENED', 'UNCONFIRMED', 'RESOLVED', 'VERIFIED', 'CLOSED') {
@values = ($status);
push (@values, $product_id) if ($product ne '-All-');
my $count = $dbh->selectrow_array($sth_status, undef, @values);
push(@row, $count);
}
foreach my $resolution ('FIXED', 'INVALID', 'WONTFIX', 'LATER', 'REMIND', 'DUPLICATE', 'WORKSFORME', 'MOVED') {
@values = ($resolution);
push (@values, $product_id) if ($product ne '-All-');
my $count = $dbh->selectrow_array($sth_reso, undef, @values);
push(@row, $count);
} }
if (! $exists) { if (! $exists) {
...@@ -272,24 +282,27 @@ sub regenerate_stats { ...@@ -272,24 +282,27 @@ sub regenerate_stats {
my $and_product = ""; my $and_product = "";
my $from_product = ""; my $from_product = "";
my @values = ();
if ($product ne '-All-') { if ($product ne '-All-') {
$and_product = " AND products.name = " . SqlQuote($product); $and_product = q{AND products.name = ?};
$from_product = "INNER JOIN products " . $from_product = q{INNER JOIN products
"ON bugs.product_id = products.id"; ON bugs.product_id = products.id};
push (@values, $product);
} }
# Determine the start date from the date the first bug in the # Determine the start date from the date the first bug in the
# database was created, and the end date from the current day. # database was created, and the end date from the current day.
# If there were no bugs in the search, return early. # If there were no bugs in the search, return early.
SendSQL("SELECT " . $dbh->sql_to_days('creation_ts') . " AS start, " . my $query = q{SELECT } .
$dbh->sql_to_days('current_date') . " AS end, " . $dbh->sql_to_days('creation_ts') . q{ AS start, } .
$dbh->sql_to_days('current_date') . q{ AS end, } .
$dbh->sql_to_days("'1970-01-01'") . $dbh->sql_to_days("'1970-01-01'") .
" FROM bugs $from_product WHERE " . qq{ FROM bugs $from_product
$dbh->sql_to_days('creation_ts') . " IS NOT NULL " . WHERE } . $dbh->sql_to_days('creation_ts') .
$and_product . qq{ IS NOT NULL $and_product
" ORDER BY start " . $dbh->sql_limit(1)); ORDER BY start } . $dbh->sql_limit(1);
my ($start, $end, $base) = $dbh->selectrow_array($query, undef, @values);
my ($start, $end, $base) = FetchSQLData();
if (!defined $start) { if (!defined $start) {
return; return;
} }
...@@ -314,16 +327,17 @@ FIN ...@@ -314,16 +327,17 @@ FIN
# Get a list of bugs that were created the previous day, and # Get a list of bugs that were created the previous day, and
# add those bugs to the list of bugs for this product. # add those bugs to the list of bugs for this product.
SendSQL("SELECT bug_id FROM bugs $from_product " . $query = qq{SELECT bug_id
" WHERE bugs.creation_ts < " . $dbh->sql_from_days($day - 1) . FROM bugs $from_product
" AND bugs.creation_ts >= " . $dbh->sql_from_days($day - 2) . WHERE bugs.creation_ts < } .
$and_product . $dbh->sql_from_days($day - 1) .
" ORDER BY bug_id"); q{ AND bugs.creation_ts >= } .
$dbh->sql_from_days($day - 2) .
$and_product . q{ ORDER BY bug_id};
my @row; my $bug_ids = $dbh->selectcol_arrayref($query, undef, @values);
while (@row = FetchSQLData()) {
push @bugs, $row[0]; push(@bugs, @$bug_ids);
}
# For each bug that existed on that day, determine its status # For each bug that existed on that day, determine its status
# at the beginning of the day. If there were no status # at the beginning of the day. If there were no status
...@@ -344,51 +358,45 @@ FIN ...@@ -344,51 +358,45 @@ FIN
foreach (@logresolutions) { foreach (@logresolutions) {
$bugcount{$_} = 0; $bugcount{$_} = 0;
} }
# Get information on bug states and resolutions.
for my $bug (@bugs) { $query = qq{SELECT bugs_activity.removed
# First, get information on various bug states. FROM bugs_activity
SendSQL("SELECT bugs_activity.removed " . INNER JOIN fielddefs
" FROM bugs_activity " . ON bugs_activity.fieldid = fielddefs.fieldid
"INNER JOIN fielddefs " . WHERE fielddefs.name = ?
" ON bugs_activity.fieldid = fielddefs.fieldid " . AND bugs_activity.bug_id = ?
" WHERE fielddefs.name = 'bug_status' " . AND bugs_activity.bug_when >= } .
" AND bugs_activity.bug_id = $bug " . $dbh->sql_from_days($day) .
" AND bugs_activity.bug_when >= " . $dbh->sql_from_days($day) .
" ORDER BY bugs_activity.bug_when " . " ORDER BY bugs_activity.bug_when " .
$dbh->sql_limit(1)); $dbh->sql_limit(1);
my $status; my $sth_bug = $dbh->prepare($query);
if (@row = FetchSQLData()) { my $sth_status = $dbh->prepare(q{SELECT bug_status
$status = $row[0]; FROM bugs
} else { WHERE bug_id = ?});
SendSQL("SELECT bug_status FROM bugs WHERE bug_id = $bug");
$status = FetchOneColumn(); my $sth_reso = $dbh->prepare(q{SELECT resolution
FROM bugs
WHERE bug_id = ?});
for my $bug (@bugs) {
my $status = $dbh->selectrow_array($sth_bug, undef,
'bug_status', $bug);
unless ($status) {
$status = $dbh->selectrow_array($sth_status, undef, $bug);
} }
if (defined $bugcount{$status}) { if (defined $bugcount{$status}) {
$bugcount{$status}++; $bugcount{$status}++;
} }
my $resolution = $dbh->selectrow_array($sth_bug, undef,
# Next, get information on various bug resolutions. 'resolution', $bug);
SendSQL("SELECT bugs_activity.removed " . unless ($resolution) {
" FROM bugs_activity " . $resolution = $dbh->selectrow_array($sth_reso, undef, $bug);
"INNER JOIN fielddefs " .
" ON bugs_activity.fieldid = fielddefs.fieldid " .
" WHERE fielddefs.name = 'resolution' " .
" AND bugs_activity.bug_id = $bug " .
" AND bugs_activity.bug_when >= " . $dbh->sql_from_days($day) .
" ORDER BY bugs_activity.bug_when " .
$dbh->sql_limit(1));
if (@row = FetchSQLData()) {
$status = $row[0];
} else {
SendSQL("SELECT resolution FROM bugs WHERE bug_id = $bug");
$status = FetchOneColumn();
} }
if (defined $bugcount{$status}) { if (defined $bugcount{$resolution}) {
$bugcount{$status}++; $bugcount{$resolution}++;
} }
} }
......
...@@ -32,6 +32,7 @@ use lib '.'; ...@@ -32,6 +32,7 @@ use lib '.';
require "globals.pl"; require "globals.pl";
use Bugzilla;
use Bugzilla::BugMail; use Bugzilla::BugMail;
use Bugzilla::Util; use Bugzilla::Util;
...@@ -39,20 +40,23 @@ use Bugzilla::Util; ...@@ -39,20 +40,23 @@ use Bugzilla::Util;
exit unless Param('whinedays') >= 1; exit unless Param('whinedays') >= 1;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
SendSQL("SELECT bug_id, short_desc, login_name " . my $query = q{SELECT bug_id, short_desc, login_name
"FROM bugs INNER JOIN profiles ON userid = assigned_to " . FROM bugs
"WHERE (bug_status = 'NEW' OR bug_status = 'REOPENED') " . INNER JOIN profiles
"AND " . $dbh->sql_to_days('NOW()') . " - " . ON userid = assigned_to
WHERE (bug_status = ? OR bug_status = ?)
AND } . $dbh->sql_to_days('NOW()') . " - " .
$dbh->sql_to_days('delta_ts') . " > " . $dbh->sql_to_days('delta_ts') . " > " .
Param('whinedays') . " " . Param('whinedays') .
"ORDER BY bug_id"); " ORDER BY bug_id";
my %bugs; my %bugs;
my %desc; my %desc;
my @row;
while (@row = FetchSQLData()) { my $slt_bugs = $dbh->selectall_arrayref($query, undef, 'NEW', 'REOPENED');
my ($id, $desc, $email) = (@row);
foreach my $bug (@$slt_bugs) {
my ($id, $desc, $email) = @$bug;
if (!defined $bugs{$email}) { if (!defined $bugs{$email}) {
$bugs{$email} = []; $bugs{$email} = [];
} }
......
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