aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPerl Tidy <perltidy@bugzilla.org>2019-01-30 20:00:43 -0500
committerDylan William Hardison <dylan@hardison.net>2019-01-30 20:31:44 -0500
commit7f3a749d7bd78a3e4aee163f562d7e95b0954b44 (patch)
treef86271c0b1f3ece6d55d8fa44767d41bb890f1f6 /reports.cgi
parentBug 1226123 - Email addresses with an apostrophe in them break the "Send Mail... (diff)
downloadbugzilla-7f3a749d7bd78a3e4aee163f562d7e95b0954b44.tar.gz
bugzilla-7f3a749d7bd78a3e4aee163f562d7e95b0954b44.tar.bz2
bugzilla-7f3a749d7bd78a3e4aee163f562d7e95b0954b44.zip
no bug - reformat all the code using the new perltidy rules
Diffstat (limited to 'reports.cgi')
-rwxr-xr-xreports.cgi313
1 files changed, 158 insertions, 155 deletions
diff --git a/reports.cgi b/reports.cgi
index 89dee1c9a..a88a4332e 100755
--- a/reports.cgi
+++ b/reports.cgi
@@ -23,91 +23,93 @@ use Digest::SHA qw(hmac_sha256_base64);
# 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 $user = Bugzilla->login();
-my $cgi = Bugzilla->cgi;
+my $user = Bugzilla->login();
+my $cgi = Bugzilla->cgi;
my $template = Bugzilla->template;
-my $vars = {};
+my $vars = {};
# We use a dummy product instance with ID 0, representing all products
my $product_all = {id => 0};
bless($product_all, 'Bugzilla::Product');
if (!Bugzilla->feature('old_charts')) {
- ThrowUserError('feature_disabled', { feature => 'old_charts' });
+ ThrowUserError('feature_disabled', {feature => 'old_charts'});
}
-my $dir = bz_locations()->{'datadir'} . "/mining";
-my $graph_dir = bz_locations()->{'graphsdir'};
-my $graph_url = basename($graph_dir);
+my $dir = bz_locations()->{'datadir'} . "/mining";
+my $graph_dir = bz_locations()->{'graphsdir'};
+my $graph_url = basename($graph_dir);
my $product_id = $cgi->param('product_id');
Bugzilla->switch_to_shadow_db();
-if (! defined($product_id)) {
- # Can we do bug charts?
- (-d $dir && -d $graph_dir)
- || ThrowCodeError('chart_dir_nonexistent',
- {dir => $dir, graph_dir => $graph_dir});
+if (!defined($product_id)) {
- my %default_sel = map { $_ => 1 } BUG_STATE_OPEN;
+ # Can we do bug charts?
+ (-d $dir && -d $graph_dir)
+ || ThrowCodeError('chart_dir_nonexistent',
+ {dir => $dir, graph_dir => $graph_dir});
- my @datasets;
- my @data = get_data($dir);
+ my %default_sel = map { $_ => 1 } BUG_STATE_OPEN;
- foreach my $dataset (@data) {
- my $datasets = {};
- $datasets->{'value'} = $dataset;
- $datasets->{'selected'} = $default_sel{$dataset} ? 1 : 0;
- push(@datasets, $datasets);
- }
+ my @datasets;
+ my @data = get_data($dir);
+
+ foreach my $dataset (@data) {
+ my $datasets = {};
+ $datasets->{'value'} = $dataset;
+ $datasets->{'selected'} = $default_sel{$dataset} ? 1 : 0;
+ push(@datasets, $datasets);
+ }
- $vars->{'datasets'} = \@datasets;
+ $vars->{'datasets'} = \@datasets;
- print $cgi->header();
+ print $cgi->header();
}
else {
- my $product;
- # For security and correctness, validate the value of the "product_id" form
- # variable. Valid values are IDs of those products for which the user has
- # permissions which appear in the "product_id" drop-down menu on the report
- # generation form. The product_id 0 is a special case, meaning "All
- # Products".
- if ($product_id) {
- $product = Bugzilla::Product->new($product_id);
- $product && $user->can_see_product($product->name)
- || ThrowUserError('product_access_denied',
- {id => $product_id});
- }
- else {
- $product = $product_all;
- }
-
- # Make sure there is something to plot.
- my @datasets = $cgi->param('datasets');
- scalar(@datasets) || ThrowUserError('missing_datasets');
-
- if (grep { $_ !~ /^[A-Za-z0-9:_-]+$/ } @datasets) {
- ThrowUserError('invalid_datasets', {'datasets' => \@datasets});
- }
-
- # Filenames must not be guessable as they can point to products
- # you are not allowed to see. Also, different projects can have
- # the same product IDs.
- my $project = bz_locations()->{'project'} || '';
- my $image_file = join(':', ($project, $product->id, @datasets));
- my $key = Bugzilla->localconfig->{'site_wide_secret'};
- $image_file = hmac_sha256_base64($image_file, $key) . '.png';
- $image_file =~ s/\+/-/g;
- $image_file =~ s/\//_/g;
- trick_taint($image_file);
-
- if (! -e "$graph_dir/$image_file") {
- generate_chart($dir, "$graph_dir/$image_file", $product, \@datasets);
- }
-
- $vars->{'url_image'} = "$graph_url/$image_file";
-
- print $cgi->header(-Content_Disposition=>'inline; filename=bugzilla_report.html');
+ my $product;
+
+ # For security and correctness, validate the value of the "product_id" form
+ # variable. Valid values are IDs of those products for which the user has
+ # permissions which appear in the "product_id" drop-down menu on the report
+ # generation form. The product_id 0 is a special case, meaning "All
+ # Products".
+ if ($product_id) {
+ $product = Bugzilla::Product->new($product_id);
+ $product && $user->can_see_product($product->name)
+ || ThrowUserError('product_access_denied', {id => $product_id});
+ }
+ else {
+ $product = $product_all;
+ }
+
+ # Make sure there is something to plot.
+ my @datasets = $cgi->param('datasets');
+ scalar(@datasets) || ThrowUserError('missing_datasets');
+
+ if (grep { $_ !~ /^[A-Za-z0-9:_-]+$/ } @datasets) {
+ ThrowUserError('invalid_datasets', {'datasets' => \@datasets});
+ }
+
+ # Filenames must not be guessable as they can point to products
+ # you are not allowed to see. Also, different projects can have
+ # the same product IDs.
+ my $project = bz_locations()->{'project'} || '';
+ my $image_file = join(':', ($project, $product->id, @datasets));
+ my $key = Bugzilla->localconfig->{'site_wide_secret'};
+ $image_file = hmac_sha256_base64($image_file, $key) . '.png';
+ $image_file =~ s/\+/-/g;
+ $image_file =~ s/\//_/g;
+ trick_taint($image_file);
+
+ if (!-e "$graph_dir/$image_file") {
+ generate_chart($dir, "$graph_dir/$image_file", $product, \@datasets);
+ }
+
+ $vars->{'url_image'} = "$graph_url/$image_file";
+
+ print $cgi->header(
+ -Content_Disposition => 'inline; filename=bugzilla_report.html');
}
$template->process('reports/old-charts.html.tmpl', $vars)
@@ -118,106 +120,107 @@ $template->process('reports/old-charts.html.tmpl', $vars)
#####################
sub get_data {
- my $dir = shift;
+ my $dir = shift;
- my @datasets;
- open(DATA, '<', "$dir/0")
- || ThrowCodeError('chart_file_open_fail', {filename => "$dir/0"});
+ my @datasets;
+ open(DATA, '<', "$dir/0")
+ || ThrowCodeError('chart_file_open_fail', {filename => "$dir/0"});
- while (<DATA>) {
- if (/^# fields?: (.+)\s*$/) {
- @datasets = grep ! /date/i, (split /\|/, $1);
- last;
- }
+ while (<DATA>) {
+ if (/^# fields?: (.+)\s*$/) {
+ @datasets = grep !/date/i, (split /\|/, $1);
+ last;
}
- close(DATA);
- return @datasets;
+ }
+ close(DATA);
+ return @datasets;
}
sub generate_chart {
- my ($dir, $image_file, $product, $datasets) = @_;
- my $data_file = $dir . '/' . $product->id;
-
- if (!open(FILE, '<', $data_file)) {
- ThrowCodeError('chart_data_not_generated', {'product' => $product});
- }
-
- my $product_in_title = $product->id ? $product->name : 'All Products';
- my @fields;
- my @labels = qw(DATE);
- my %datasets = map { $_ => 1 } @$datasets;
-
- my %data = ();
- while (<FILE>) {
- chomp;
- next unless $_;
- if (/^#/) {
- if (/^# fields?: (.*)\s*$/) {
- @fields = split /\||\r/, $1;
- $data{$_} ||= [] foreach @fields;
- unless ($fields[0] =~ /date/i) {
- ThrowCodeError('chart_datafile_corrupt', {'file' => $data_file});
- }
- push @labels, grep($datasets{$_}, @fields);
- }
- next;
- }
-
- unless (@fields) {
- ThrowCodeError('chart_datafile_corrupt', {'file' => $data_file});
- }
-
- my @line = split /\|/;
- my $date = $line[0];
- my ($yy, $mm, $dd) = $date =~ /^\d{2}(\d{2})(\d{2})(\d{2})$/;
- push @{$data{DATE}}, "$mm/$dd/$yy";
-
- for my $i (1 .. $#fields) {
- my $field = $fields[$i];
- if (! defined $line[$i] or $line[$i] eq '') {
- # no data point given, don't plot (this will probably
- # generate loads of Chart::Base warnings, but that's not
- # our fault.)
- push @{$data{$field}}, undef;
- }
- else {
- push @{$data{$field}}, $line[$i];
- }
+ my ($dir, $image_file, $product, $datasets) = @_;
+ my $data_file = $dir . '/' . $product->id;
+
+ if (!open(FILE, '<', $data_file)) {
+ ThrowCodeError('chart_data_not_generated', {'product' => $product});
+ }
+
+ my $product_in_title = $product->id ? $product->name : 'All Products';
+ my @fields;
+ my @labels = qw(DATE);
+ my %datasets = map { $_ => 1 } @$datasets;
+
+ my %data = ();
+ while (<FILE>) {
+ chomp;
+ next unless $_;
+ if (/^#/) {
+ if (/^# fields?: (.*)\s*$/) {
+ @fields = split /\||\r/, $1;
+ $data{$_} ||= [] foreach @fields;
+ unless ($fields[0] =~ /date/i) {
+ ThrowCodeError('chart_datafile_corrupt', {'file' => $data_file});
}
+ push @labels, grep($datasets{$_}, @fields);
+ }
+ next;
}
-
- shift @labels;
-
- close FILE;
- if (! @{$data{DATE}}) {
- ThrowUserError('insufficient_data_points');
+ unless (@fields) {
+ ThrowCodeError('chart_datafile_corrupt', {'file' => $data_file});
}
- my $img = Chart::Lines->new (800, 600);
- my $i = 0;
-
- my $MAXTICKS = 20; # Try not to show any more x ticks than this.
- my $skip = 1;
- if (@{$data{DATE}} > $MAXTICKS) {
- $skip = int((@{$data{DATE}} + $MAXTICKS - 1) / $MAXTICKS);
+ my @line = split /\|/;
+ my $date = $line[0];
+ my ($yy, $mm, $dd) = $date =~ /^\d{2}(\d{2})(\d{2})(\d{2})$/;
+ push @{$data{DATE}}, "$mm/$dd/$yy";
+
+ for my $i (1 .. $#fields) {
+ my $field = $fields[$i];
+ if (!defined $line[$i] or $line[$i] eq '') {
+
+ # no data point given, don't plot (this will probably
+ # generate loads of Chart::Base warnings, but that's not
+ # our fault.)
+ push @{$data{$field}}, undef;
+ }
+ else {
+ push @{$data{$field}}, $line[$i];
+ }
}
-
- my %settings =
- (
- "title" => "Status Counts for $product_in_title",
- "x_label" => "Dates",
- "y_label" => "Bug Counts",
- "legend_labels" => \@labels,
- "skip_x_ticks" => $skip,
- "y_grid_lines" => "true",
- "grey_background" => "false",
- "colors" => {
- # default dataset colours are too alike
- dataset4 => [0, 0, 0], # black
- },
- );
-
- $img->set (%settings);
- $img->png($image_file, [ @data{('DATE', @labels)} ]);
+ }
+
+ shift @labels;
+
+ close FILE;
+
+ if (!@{$data{DATE}}) {
+ ThrowUserError('insufficient_data_points');
+ }
+
+ my $img = Chart::Lines->new(800, 600);
+ my $i = 0;
+
+ my $MAXTICKS = 20; # Try not to show any more x ticks than this.
+ my $skip = 1;
+ if (@{$data{DATE}} > $MAXTICKS) {
+ $skip = int((@{$data{DATE}} + $MAXTICKS - 1) / $MAXTICKS);
+ }
+
+ my %settings = (
+ "title" => "Status Counts for $product_in_title",
+ "x_label" => "Dates",
+ "y_label" => "Bug Counts",
+ "legend_labels" => \@labels,
+ "skip_x_ticks" => $skip,
+ "y_grid_lines" => "true",
+ "grey_background" => "false",
+ "colors" => {
+
+ # default dataset colours are too alike
+ dataset4 => [0, 0, 0], # black
+ },
+ );
+
+ $img->set(%settings);
+ $img->png($image_file, [@data{('DATE', @labels)}]);
}