http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84691

Revision: 84691
Author:   pdhanda
Date:     2011-03-24 18:33:13 +0000 (Thu, 24 Mar 2011)
Log Message:
-----------
Added weekly report mentioned in bug 25637#c3

Added Paths:
-----------
    trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/
    trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Config.pm
    trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Extension.pm
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/component-report.cgi
    trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/
    trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/hook/
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/hook/README
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/README
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/component-report.html.tmpl
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/weekly-bug-summary.html.tmpl
    
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/weekly-bug-summary.cgi

Added: trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Config.pm
===================================================================
--- trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Config.pm         
                (rev 0)
+++ trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Config.pm 
2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,27 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# See: https://bugzilla.wikimedia.org/show_bug.cgi?id=25637#c3
+# Original Source code from http://websvn.kde.org/trunk/www/sites/bugs/
+
+package Bugzilla::Extension::WeeklyReport;
+use strict;
+
+use constant NAME => 'WeeklyReport';
+
+use constant REQUIRED_MODULES => [
+];
+
+use constant OPTIONAL_MODULES => [
+];
+
+__PACKAGE__->NAME;

Added: trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Extension.pm
===================================================================
--- trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Extension.pm      
                        (rev 0)
+++ trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/Extension.pm      
2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,30 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# See: https://bugzilla.wikimedia.org/show_bug.cgi?id=25637#c3
+# Original Source code from http://websvn.kde.org/trunk/www/sites/bugs/
+
+
+package Bugzilla::Extension::WeeklyReport;
+use strict;
+use base qw(Bugzilla::Extension);
+
+our $VERSION = '0.01';
+
+# See the documentation of Bugzilla::Hook ("perldoc Bugzilla::Hook" 
+# in the bugzilla directory) for a list of all available hooks.
+sub install_update_db {
+    my ($self, $args) = @_;
+
+}
+
+__PACKAGE__->NAME;

Added: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/component-report.cgi
===================================================================
--- 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/component-report.cgi  
                            (rev 0)
+++ 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/component-report.cgi  
    2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,113 @@
+#!/usr/bin/perl -wT
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# The contents of this file are subject to the Mozilla Public
+# License Version 1.1 (the "License"); you may not use this file
+# except in compliance with the License. You may obtain a copy of
+# the License at http://www.mozilla.org/MPL/
+#
+# Software distributed under the License is distributed on an "AS
+# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# rights and limitations under the License.
+#
+# The Original Code is the Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Netscape Communications
+# Corporation. Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation. All
+# Rights Reserved.
+#
+# Contributor(s): Harrison Page <[email protected]>,
+# Terry Weissman <[email protected]>,
+# Dawn Endico <[email protected]>
+# Bryce Nesbitt <[email protected]>,
+#    Added -All- report, change "nobanner" to "banner" (it is strange to have a
+#    list with 2 positive and 1 negative choice), default links on, add show
+#    sql comment.
+# Joe Robins <[email protected]>,
+#    If using the usebuggroups parameter, users shouldn't be able to see
+#    reports for products they don't have access to.
+# Gervase Markham <[email protected]> and Adam Spiers <[email protected]>
+#    Added ability to chart any combination of resolutions/statuses.
+#    Derive the choice of resolutions/statuses from the -All- data file
+#    Removed hardcoded order of resolutions/statuses when reading from
+#    daily stats file, so now works independently of collectstats.pl
+#    version
+#    Added image caching by date and datasets
+# Myk Melez <[email protected]):
+#    Implemented form field validation and reorganized code.
+#
+# Luis Villa <[email protected]>:
+#    modified it to report things in a new format
+# Matt Rogers <[email protected]>:
+#    Rewritten for bugzilla 3.0 including template
+
+use strict;
+use lib qw(.);
+
+use Bugzilla;
+use Bugzilla::Product;
+use Bugzilla::Constants;
+use Bugzilla::Error;
+
+use vars qw($vars $template);
+
+eval "use GD";
+my $use_gd = $@ ? 0 : 1;
+eval "use Chart::Lines";
+$use_gd = 0 if $@;
+
+# If we're using bug groups for products, we should apply those restrictions
+# to viewing reports, as well.  Time to check the login in that case.
+
+my $cgi = Bugzilla->cgi;
+my $template = Bugzilla->template;
+my $vars = {};
+my $user = Bugzilla->login(LOGIN_OPTIONAL);
+
+print $cgi->header(-type => 'text/html', -expires => '+3M');
+
+my $query = <<EOF
+SELECT   count(*), products.name, components.name, bug_severity 
+  FROM   bugs, products, components
+ WHERE   ( bug_status = 'NEW' or bug_status = 'ASSIGNED' or bug_status = 
'REOPENED' or bug_status = 'UNCONFIRMED' )
+   AND   products.name = ?
+   AND   bugs.product_id = products.id
+   AND   bugs.component_id = components.id
+   AND   products.id = components.product_id
+GROUP BY products.name, components.name, bug_severity
+ORDER BY components.name
+EOF
+; 
+
+#Report on components by severity and priority
+my $sth = Bugzilla->dbh->prepare($query);
+my $product = $cgi->param('product');
+if ($product =~ /^([\w.-\s]+)$/) { $product = $1 }
+$sth->execute($product);
+
+my (@bug_counts, %bugs, %total_bugs);
+my $disp_component;
+my $total_bug_count;
+
+my $product_obj = new Bugzilla::Product({ 'name' => $product });
+
+$vars->{'product'} = $product;
+$vars->{'all_severities'} = 
Bugzilla::Field::get_legal_field_values('bug_severity');
+my @compnames;
+for my $comp (@{$product_obj->components}) {
+  push @compnames, $comp->name
+}
+$vars->{'all_components'} = \@compnames;
+
+while (my ($bcount, $product, $component, $sever) = $sth->fetchrow_array) {
+  $bugs{$component}{$sever} = $bcount;
+  $bugs{$component}{'total'} += $bcount;
+}
+
+$vars->{'bug_sev_counts'} = \%bugs;
+
+$template->process("weeklyreport/component-report.html.tmpl", $vars)
+  || ThrowTemplateError($template->error());
+


Property changes on: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/component-report.cgi
___________________________________________________________________
Added: svn:executable
   + *

Added: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/hook/README
===================================================================
--- 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/hook/README
                           (rev 0)
+++ 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/hook/README
   2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,5 @@
+Template hooks go in this directory. Template hooks are called in normal
+Bugzilla templates like [% Hook.process('some-hook') %].
+More information about them can be found in the documentation of 
+Bugzilla::Extension. (Do "perldoc Bugzilla::Extension" from the main
+Bugzilla directory to see that documentation.)
\ No newline at end of file

Added: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/README
===================================================================
--- 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/README
                           (rev 0)
+++ 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/README
   2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,16 @@
+Normal templates go in this directory. You can load them in your
+code like this:
+
+use Bugzilla::Error;
+my $template = Bugzilla->template;
+$template->process('weeklyreport/some-template.html.tmpl')
+  or ThrowTemplateError($template->error());
+
+That would be how to load a file called some-template.html.tmpl that
+was in this directory.
+
+Note that you have to be careful that the full path of your template
+never conflicts with a template that exists in Bugzilla or in 
+another extension, or your template might override that template. That's why
+we created this directory called 'weeklyreport' for you, so you
+can put your templates in here to help avoid conflicts.
\ No newline at end of file

Added: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/component-report.html.tmpl
===================================================================
--- 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/component-report.html.tmpl
                               (rev 0)
+++ 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/component-report.html.tmpl
       2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,33 @@
+[%# KDE component report template  #%]
+
+[% PROCESS global/variables.none.tmpl %]
+
+[% PROCESS global/header.html.tmpl
+   title = "Component Report"
+   h1 = "Report Count by Component and Severity"
+%]
+
+<p align="center">
+<table border="1" cellspacing="2" cellpadding="5" align="center">
+<tr style="background-color: #EEF6FF;">
+<td><b>Component</b></td>
+[% FOREACH sev = all_severities %]
+<td><b>[% sev %]</b></td>
+[% END %]
+<td><b>total</b></td>
+</tr>
+[% FOREACH comp = all_components %]
+<tr>
+    <td>[% product %] - [% comp %]</td>
+    [% FOREACH sev = all_severities %]
+        <td><a href="buglist.cgi?product=[% product %]&amp;component=[% comp 
%]&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;bug_severity=[%
 sev %]">[% bug_sev_counts.$comp.$sev %]</a></td>
+    [% END %]
+    <td><a href="buglist.cgi?product=[% product %]&amp;component=[% comp 
%]&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED">[%
 bug_sev_counts.$comp.total %]</a></td>
+</tr>
+[% END %]
+
+
+</table>
+</p>
+[% PROCESS global/footer.html.tmpl %]
+

Added: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/weekly-bug-summary.html.tmpl
===================================================================
--- 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/weekly-bug-summary.html.tmpl
                             (rev 0)
+++ 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/template/en/default/weeklyreport/weekly-bug-summary.html.tmpl
     2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,95 @@
+[%# Wikimedia weekly bug summary template  #%]
+
+[% PROCESS global/variables.none.tmpl %]
+
+[% PROCESS global/header.html.tmpl
+   title = "Wikimedia Weekly Bug Summary"
+%]
+
+<h3 style="text-align:center;">Total: [% totalbugs %] bugs and [% totalwishes 
%] enhancements</h3>
+
+<h4 style="text-align:center;">[% new_open_bugs %] bugs opened, [% 
new_closed_bugs %] bugs closed in the last [% duration %] days<br>
+([% new_open_wishes %] enhancements opened, [% new_closed_wishes %] 
enhancements closed)</h4>
+
+<form action="weekly-bug-summary.cgi" style="text-align:center;">Report top
+       [% sel = { name => 'tops'} %]
+       [% INCLUDE select %]
+summary over the last
+       [% sel = { name => 'days'} %]
+       [% INCLUDE select %]
+days and <input type="submit" value="Show" />
+</form>
+
+<h3 style="text-align:center;">Top [% top_number %] Wikimedia products with 
the most bugs:</h3>
+
+<table align="center" border="0" cellspacing="2" cellpadding="5">
+<tr style="background-color: #EEF6FF;"><th>Product</th>
+<th>Open<br />bugs</th>
+<th>Opened in<br />last [% duration %] days</th>
+<th>Closed in<br />last [% duration %] days</th>
+<th>Change</th>
+<th>Open<br />enhancements</th>
+<th>Opened in<br />last [% duration %] days</th>
+<th>Closed in<br />last [% duration %] days</th>
+<th>Change</th>
+<th>&nbsp;</th></tr>
+
+[%- FOREACH pr = product_bug_lists %]
+<tr>
+       <td><a href="component-report.cgi?product=[%- pr.name -%]">[%- pr.name 
-%]</a></td>
+       <td style="text-align:right;"><a href="buglist.cgi?product=[%- pr.name 
-%]&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;bug_severity=critical&amp;bug_severity=grave&amp;bug_severity=major&amp;bug_severity=crash&amp;bug_severity=normal&amp;bug_severity=minor">[%-
 pr.count -%]</a></td>
+       <td style="text-align:right;">+[%- pr.bugs_opened -%]</td>
+       <td style="text-align:right;">-[%- pr.bugs_closed -%]</td>
+       <td style="text-align:right; background-color: [%- pr.bugs_change_color 
-%];">[%- pr.bugs_change -%]</td>
+       <td style="text-align:right;"><a href="buglist.cgi?product=[%- pr.name 
-%]&amp;bug_status=UNCONFIRMED&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;bug_severity=enhancement">[%-
 pr.total_wishes -%]</a></td>
+       <td style="text-align:right;">+[%- pr.open_wishes -%]</td>
+       <td style="text-align:right;">-[%- pr.closed_wishes -%]</td>
+       <td style="text-align:right; background-color: [%- 
pr.wishes_change_color -%];">[%- pr.wishes_change -%]</td>
+       <td style="text-align:right;"><a href="reports.cgi?product=[%- pr.name 
-%]&output=show_chart&datasets=NEW%3A&datasets=ASSIGNED%3A&datasets=REOPENED%3A&datasets=UNCONFIRMED%3A&datasets=RESOLVED%3A&banner=1">Graph</a></td>
+</tr>
+[% END %]
+</table>
+
+<h3 style="text-align:center;"><a name="closers">Top [% top_number %] people 
who resolved the most reports in the last [% duration %] days:</a></h3>
+<table align="center" border="0" cellspacing="2" cellpadding="5">
+<tr style="background-color: #EEF6FF;">
+       <th>User</th><th># Resolved</th>
+</tr>
+[%- FOREACH bh = bug_hunters_list %]
+<tr>
+       <td>[% bh.user FILTER html %]</td>
+       <td>[% bh.count %]</td>
+<tr>
+[% END %]
+</table>
+
+<h3 style="text-align:center;"><a name="fixers">Top [% top_number %] people 
who most quickly fixed a report in the last [% duration %] days:</a></h3>
+<table align="center" border="0" cellspacing="2" cellpadding="5">
+<tr style="background-color: #EEF6FF;">
+<th>User</th><th>Elapsed time</th></tr>
+[%- FOREACH bf = bug_fixers_list %]
+<tr>
+       <td>[% bf.name FILTER html %]</td>
+       <td>[% bf.formatted_elapsed %] (<a href="show_bug.cgi?id=[% bf.bugid 
%]">[% bf.bugid %]</a>)</td>
+</tr>
+[% END %]
+</table>
+
+[% PROCESS global/footer.html.tmpl %]
+
+
+[%##########################################################################%]
+[%# Block for SELECT fields                                                #%]
+[%##########################################################################%]
+
+[% BLOCK select %]
+    <select name="[% sel.name %]">
+    [%- FOREACH x = ${sel.name} %]
+      <option value="[% x FILTER html %]"
+        [% " selected=\"selected\"" IF x == default.${sel.name} %]>
+          [% x FILTER html %]
+        </option>
+    [% END %]
+    </select>
+[% END %]
+

Added: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/weekly-bug-summary.cgi
===================================================================
--- 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/weekly-bug-summary.cgi
                            (rev 0)
+++ 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/weekly-bug-summary.cgi
    2011-03-24 18:33:13 UTC (rev 84691)
@@ -0,0 +1,386 @@
+#!/usr/bin/perl -wT
+
+# its stolen from somewhere but was mostly re-written by Dirk Mueller 
<[email protected]>, 08/2006
+# templatized by Matt Rogers <[email protected]>, 12/2007
+use strict;
+use lib ".";
+
+use Bugzilla;
+use Bugzilla::Constants;
+use Bugzilla::Util;
+use Bugzilla::Error;
+use Bugzilla::Field;
+
+sub total_bugs_in_bugzilla()
+{
+    my $dbh = Bugzilla->dbh;
+
+    # figure out total bugs
+    my (@totalbugs) = $dbh->selectrow_array(
+        "SELECT count(bugs.bug_id) FROM bugs WHERE bugs.bug_severity != 
'enhancement' AND
+         ( bugs.bug_status = 'NEW' or bugs.bug_status = 'ASSIGNED' or
+         bugs.bug_status = 'REOPENED' or bugs.bug_status = 'UNCONFIRMED')"
+    );
+
+    # figure out total number of wishes
+    my (@totalwishes) = $dbh->selectrow_array (
+        "SELECT count(bugs.bug_id) FROM bugs WHERE bugs.bug_severity = 
'enhancement' AND
+         ( bugs.bug_status = 'NEW' or bugs.bug_status = 'ASSIGNED' or
+          bugs.bug_status = 'REOPENED' or bugs.bug_status = 'UNCONFIRMED')"
+    );
+
+    return ($totalbugs[0], $totalwishes[0]);
+}
+
+sub bugs_opened()
+{
+    my($product, $days) = @_;
+
+    my $sqlproduct = "";
+    $sqlproduct = "AND bugs.product_id=$product"
+        if(defined $product and $product ne "%");
+
+    my ($count) = Bugzilla->dbh->selectrow_array(
+        "SELECT count(bugs.bug_id) FROM bugs
+         WHERE creation_ts >= from_days(to_days(NOW())-?)
+         $sqlproduct AND bugs.bug_severity != 'enhancement'", undef, ($days)
+    );
+
+    return $count;
+}
+
+sub wishes_opened()
+{
+    my($product, $days) = @_;
+
+    my $sqlproduct = "";
+    $sqlproduct = "AND bugs.product_id=" . Bugzilla->dbh->quote($product)
+        if(defined $product and $product ne "%");
+
+    my ($count) = Bugzilla->dbh->selectrow_array(
+        "SELECT count(bugs.bug_id) FROM bugs
+         WHERE creation_ts >= from_days(to_days(NOW())-?)
+         $sqlproduct AND bugs.bug_severity = 'enhancement'", undef, ($days)
+    );
+
+    return $count;
+}
+
+sub bugs_closed()
+{
+    my($product, $days) = @_;
+    my $query = "";
+    my $sqlproduct = "";
+    $sqlproduct = "AND bugs.product_id=" . Bugzilla->dbh->quote($product)
+        if(defined $product and $product ne "%");
+
+    my ($count) = Bugzilla->dbh->selectrow_array("
+select
+    count(distinct bugs.bug_id)
+from
+    bugs, bugs_activity
+where
+    bugs.bug_severity != 'enhancement' AND
+    (bugs_activity.added='RESOLVED' or bugs_activity.added='CLOSED' or
+     bugs_activity.added='NEEDSINFO')
+and
+    bugs_activity.bug_when >= FROM_DAYS(TO_DAYS(NOW())-?)
+and
+    bugs.bug_id = bugs_activity.bug_id
+    $sqlproduct
+    ", undef, ($days));
+
+    return($count);
+}
+
+sub wishes_closed()
+{
+    my($product, $days) = @_;
+    my $query = "";
+    my $sqlproduct = "";
+    $sqlproduct = "AND bugs.product_id=" . Bugzilla->dbh->quote($product)
+        if(defined $product and $product ne "%");
+
+    # We are going to build a long SQL query.
+    my ($count) = Bugzilla->dbh->selectrow_array("
+select
+    count(distinct bugs.bug_id)
+from
+    bugs, bugs_activity
+where
+    bugs.bug_severity = 'enhancement' AND
+    (bugs_activity.added='RESOLVED' or bugs_activity.added='CLOSED' or
+     bugs_activity.added='NEEDSINFO')
+and
+    bugs_activity.bug_when >= FROM_DAYS(TO_DAYS(NOW())-?)
+and
+    bugs.bug_id = bugs_activity.bug_id
+    $sqlproduct
+    ", undef, ($days));
+
+    return($count);
+}
+
+sub open_wishes()
+{
+    my($product) = @_;
+
+    my $sqlproduct = "";
+    $sqlproduct = "AND bugs.product_id=" . Bugzilla->dbh->quote($product)
+        if(defined $product and $product ne "%");
+
+    # We are going to build a long SQL query.
+    my ($count) = Bugzilla->dbh->selectrow_array("
+SELECT
+    count(bugs.bug_id)
+FROM bugs
+WHERE bugs.bug_severity = 'enhancement' AND
+      (bugs.bug_status = 'NEW' or bugs.bug_status = 'ASSIGNED' or
+       bugs.bug_status = 'REOPENED' or bugs.bug_status = 'UNCONFIRMED')
+$sqlproduct");
+
+    return $count;
+}
+
+
+# $format can be HTML or XML
+sub print_product_bug_lists() {
+    my($number, $days, $format, $fh) = @_;
+
+    my $query;
+
+    my @results;
+
+    # We are going to build a long SQL query.
+    my $sth = Bugzilla->dbh->prepare("
+select
+    products.name, bugs.product_id, count(bugs.product_id) as n
+from
+    bugs, products
+where
+    (bugs.bug_status = 'NEW' or bugs.bug_status = 'ASSIGNED' or
+    bugs.bug_status = 'REOPENED' or bugs.bug_status = 'UNCONFIRMED')
+and
+    bugs.bug_severity != 'enhancement'
+and
+    products.id = bugs.product_id
+
+group by product_id
+order by n desc
+limit $number
+    ");
+    $sth->execute;
+
+    # For each product we want to show the difference in the last period.
+    # But this will involve two sql connections at once, which the bugzilla
+    # functions don't handle too nicely.
+    # So lets collect the data first and then print the table.
+    my %product_count;
+    my %product_id;
+
+    while (my ($product, $p_id, $count) = $sth->fetchrow_array) {
+        $product_count{$product} = $count;
+        $product_id{$product} = $p_id;
+    }
+
+
+    foreach my $product (reverse sort
+                    {$product_count{$a} <=> $product_count{$b}}
+                                    keys (%product_count)) {
+        my %product_results;
+        my $bopened = &bugs_opened($product_id{$product}, $days);
+        my $bclosed = &bugs_closed($product_id{$product}, $days);
+        $product_results{'id'} = $product_id{$product};
+        $product_results{'name'} = $product;
+        $product_results{'count'} = $product_count{$product};
+        $product_results{'bugs_opened'} = $bopened;
+        $product_results{'bugs_closed'} = $bclosed;
+        $product_results{'bugs_change'} = $bopened - $bclosed;
+        if( $product_results{'bugs_change'} > 0 ) {
+            $product_results{'bugs_change_color'} = "#FF9999";
+        } elsif( $product_results{'bugs_change'} < 0 ) {
+            $product_results{'bugs_change_color'} = "#99FF99";
+        }
+        $product_results{'total_wishes'} = &open_wishes($product_id{$product});
+        $product_results{'open_wishes'} = 
&wishes_opened($product_id{$product}, $days);
+        $product_results{'closed_wishes'} = 
&wishes_closed($product_id{$product}, $days);
+        $product_results{'wishes_change'} = $product_results{'open_wishes'} -
+                                            $product_results{'closed_wishes'};
+        if( $product_results{'wishes_change'} > 0 ) {
+            $product_results{'wish_change_color'} = "#FF9999";
+        } elsif( $product_results{'wishes_change'} < 0 ) {
+            $product_results{'wish_change_color'} = "#99FF99";
+        }
+        push @results, \%product_results;
+    }
+
+    return \@results;
+}
+
+sub print_bug_hunters_list() {
+    my($number, $days) = @_;
+    my @results;
+    my $query;
+
+    my $sth = Bugzilla->dbh->prepare("
+select
+    assign.login_name, count(assign.login_name), count(assign.login_name) as n
+from
+    bugs, bugs_activity, profiles assign
+where
+    (bugs_activity.added='RESOLVED' or bugs_activity.added = 'CLOSED' or
+     bugs_activity.added='NEEDSINFO')
+and
+    bugs_activity.bug_when >= from_days(TO_DAYS(NOW()) - ?)
+and
+    bugs_activity.who = assign.userid
+and
+    bugs.bug_id = bugs_activity.bug_id
+and
+    (bugs.bug_status = 'RESOLVED' or bugs.bug_status = 'CLOSED')
+group by assign.login_name
+order by n desc
+limit ?
+    ");
+
+    $sth->execute($days, $number);
+    while (my ($user, $count, $n) = $sth->fetchrow_array()) {
+
+        my %bh_results;
+
+        # defang the email address
+        $user =~ y/\@\./  / if (Bugzilla->user->id == 0);
+        $bh_results{'user'} = $user;
+        $bh_results{'count'} = $count;
+
+        push @results, \%bh_results;
+    }
+
+    return \@results;
+}
+
+sub print_bug_fixers_list() {
+    my($number, $days) = @_;
+    my @results;
+
+    my $sth = Bugzilla->dbh->prepare("
+SELECT
+    profiles.login_name, bugs.bug_id,
+    
MIN(UNIX_TIMESTAMP(bugs_activity.bug_when)-UNIX_TIMESTAMP(bugs.creation_ts))
+        AS open_time
+FROM
+    bugs, bugs_activity, profiles, longdescs
+WHERE
+    bugs.resolution='FIXED'
+AND
+    bugs.bug_status='RESOLVED'
+AND
+    bugs_activity.bug_when  >= FROM_DAYS(TO_DAYS(NOW())-?)
+AND
+    bugs.bug_id=bugs_activity.bug_id
+AND
+    bugs_activity.added='FIXED'
+AND
+    bugs_activity.who=profiles.userid
+AND
+    bugs.reporter != bugs_activity.who
+AND
+    longdescs.bug_id = bugs.bug_id
+AND
+    longdescs.who = bugs_activity.who
+AND
+    longdescs.thetext like \"SVN commit%\"
+GROUP BY
+    profiles.login_name, bugs.bug_id
+ORDER BY
+    open_time ASC
+LIMIT ?");
+
+    $sth->execute($days, $number);
+
+    while (my ($user, $bugid, $elapsed) = $sth->fetchrow_array) {
+
+        my %bf_results;
+
+        # defang the email address
+        $user =~ y/\@\./  / if (Bugzilla->user->id == 0);
+        $bf_results{'name'} = $user;
+        $bf_results{'elapsed'} = ${elapsed};
+        my $html_elapsed = "${elapsed}s";
+        $html_elapsed = int($elapsed/60) . " min" if ($elapsed > 60);
+        $html_elapsed = int($elapsed/(60*60)) . " h" if ($elapsed > (4*60*60));
+        $html_elapsed = int($elapsed/(60*60*24)) . " days" if ($elapsed > 
(58*60*60));
+        $bf_results{'formatted_elapsed'} = $html_elapsed;
+        $bf_results{'bugid'} = $bugid;
+
+        push @results, \%bf_results;
+    }
+
+    return \@results;
+}
+
+
+Bugzilla->login(LOGIN_OPTIONAL);
+
+# For most scripts we don't make $cgi and $template global variables. But
+# when preparing Bugzilla for mod_perl, this script used these
+# variables in so many subroutines that it was easier to just
+# make them globals.
+local our $cgi = Bugzilla->cgi;
+local our $template = Bugzilla->template;
+local our $vars = {};
+
+# Output appropriate HTTP response headers
+print $cgi->header(-type => 'text/html', -expires => '+3M');
+
+my %defaults;
+
+# If they didn't tell us a time period we choose the last week.
+my $current_days = 7;
+$current_days = $cgi->param('days') if (defined $cgi->param('days'));
+$current_days = 7 if (!detaint_natural($current_days));
+$defaults{'days'} = $current_days;
+
+my $current_tops = 20;
+$current_tops = $cgi->param('tops') if (defined $cgi->param('tops'));
+$current_tops = 20 if (!detaint_natural($current_tops));
+$defaults{'tops'} = $current_tops;
+
+$vars->{'duration'} = $current_days;
+$vars->{'top_number'} = $current_tops;
+
+($vars->{'totalbugs'}, $vars->{'totalwishes'}) = &total_bugs_in_bugzilla();
+
+my $bo = &bugs_opened("%", $current_days);
+my $wo = &wishes_opened("%", $current_days);
+my $bc = &bugs_closed("%", $current_days);
+my $wc = &wishes_closed("%", $current_days);
+
+$vars->{'new_open_bugs'} = $bo;
+$vars->{'new_closed_bugs'} = $bc;
+$vars->{'new_open_wishes'} = $wo;
+$vars->{'new_closed_wishes'} = $wc;
+
+my @tops = (10, 20, 30, 50, 100);
+$vars->{'tops'} = \@tops;
+
+my @days = (1, 2, 7, 14, 31, 180, 365);
+$vars->{'days'} = \@days;
+
+$vars->{'default'} = \%defaults;
+
+$vars->{'product_bug_lists'} = &print_product_bug_lists($current_tops, 
$current_days, "HTML");
+
+$vars->{'bug_hunters_list'} = &print_bug_hunters_list($current_tops, 
$current_days);
+
+$vars->{'bug_fixers_list'} = &print_bug_fixers_list($current_tops, 
$current_days);
+
+$template->process("weeklyreport/weekly-bug-summary.html.tmpl", $vars)
+  || ThrowTemplateError($template->error());
+
+
+
+
+
+print "</div>\n";
+


Property changes on: 
trunk/tools/bugzilla/bugzilla-4.0/extensions/WeeklyReport/weekly-bug-summary.cgi
___________________________________________________________________
Added: svn:executable
   + *


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to