From d8573c816018973c60316d955616c19ab803959a Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Tue, 18 Apr 2006 03:36:34 +0000 Subject: Bug 330718: showdependencytree.cgi needs some cleanup - Patch by Frédéric Buclin r=wicked a=justdave MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- showdependencytree.cgi | 94 +++++++++++--------------------------------------- 1 file changed, 21 insertions(+), 73 deletions(-) (limited to 'showdependencytree.cgi') diff --git a/showdependencytree.cgi b/showdependencytree.cgi index 1a1e51d3a..b2cf29a57 100755 --- a/showdependencytree.cgi +++ b/showdependencytree.cgi @@ -22,16 +22,16 @@ # Andreas Franke # Christian Reis # Myk Melez +# Frédéric Buclin use strict; use lib qw(.); require "globals.pl"; use Bugzilla; -use Bugzilla::User; use Bugzilla::Bug; -Bugzilla->login(); +my $user = Bugzilla->login(); my $cgi = Bugzilla->cgi; my $template = Bugzilla->template; @@ -48,6 +48,7 @@ my $dbh = Bugzilla->switch_to_shadow_db(); # bug that the user is authorized to access. my $id = $cgi->param('id'); ValidateBugID($id); +my $current_bug = new Bugzilla::Bug($id, $user->id); my $hide_resolved = $cgi->param('hide_resolved') ? 1 : 0; @@ -58,19 +59,12 @@ if ($maxdepth !~ /^\d+$/) { $maxdepth = 0 }; # Main Section # ################################################################################ -# The column/value to select as the target milestone for bugs, -# either the target_milestone column or the empty string value -# (for installations that don't use target milestones). Makes -# it easier to query the database for bugs because we don't -# have to embed a conditional statement into each query. -my $milestone_column = Param('usetargetmilestone') ? "target_milestone" : "''"; - # Stores the greatest depth to which either tree goes. my $realdepth = 0; # Generate the tree of bugs that this bug depends on and a list of IDs # appearing in the tree. -my $dependson_tree = { $id => GetBug($id) }; +my $dependson_tree = { $id => $current_bug }; my $dependson_ids = {}; GenerateTree($id, "dependson", 1, $dependson_tree, $dependson_ids); $vars->{'dependson_tree'} = $dependson_tree; @@ -78,7 +72,7 @@ $vars->{'dependson_ids'} = [keys(%$dependson_ids)]; # Generate the tree of bugs that this bug blocks and a list of IDs # appearing in the tree. -my $blocked_tree = { $id => GetBug($id) }; +my $blocked_tree = { $id => $current_bug }; my $blocked_ids = {}; GenerateTree($id, "blocked", 1, $blocked_tree, $blocked_ids); $vars->{'blocked_tree'} = $blocked_tree; @@ -89,7 +83,6 @@ $vars->{'realdepth'} = $realdepth; $vars->{'bugid'} = $id; $vars->{'maxdepth'} = $maxdepth; $vars->{'hide_resolved'} = $hide_resolved; -$vars->{'canedit'} = UserInGroup("editbugs"); print $cgi->header(); $template->process("bug/dependency-tree.html.tmpl", $vars) @@ -102,15 +95,19 @@ $template->process("bug/dependency-tree.html.tmpl", $vars) sub GenerateTree { # Generates a dependency tree for a given bug. Calls itself recursively # to generate sub-trees for the bug's dependencies. - my ($bug_id, $relationship, $depth, $bugs, $ids) = @_; - - # Query the database for bugs with the given dependency relationship. - my @dependencies = GetDependencies($bug_id, $relationship); - + + my @dependencies; + if ($relationship eq 'dependson') { + @dependencies = @{$bugs->{$bug_id}->dependson}; + } + else { + @dependencies = @{$bugs->{$bug_id}->blocked}; + } + # Don't do anything if this bug doesn't have any dependencies. return unless scalar(@dependencies); - + # Record this depth in the global $realdepth variable if it's farther # than we've gone before. $realdepth = max($realdepth, $depth); @@ -120,7 +117,7 @@ sub GenerateTree { # its sub-tree if we haven't already done so (which happens # when bugs appear in dependency trees multiple times). if (!$bugs->{$dep_id}) { - $bugs->{$dep_id} = GetBug($dep_id); + $bugs->{$dep_id} = new Bugzilla::Bug($dep_id, $user->id); GenerateTree($dep_id, $relationship, $depth+1, $bugs, $ids); } @@ -128,63 +125,14 @@ sub GenerateTree { # if it exists, if we haven't exceeded the maximum depth the user # wants the tree to go, and if the dependency isn't resolved # (if we're ignoring resolved dependencies). - if ($bugs->{$dep_id}->{'exists'} + if (!$bugs->{$dep_id}->{'error'} && (!$maxdepth || $depth <= $maxdepth) - && ($bugs->{$dep_id}->{'open'} || !$hide_resolved)) + && ($bugs->{$dep_id}->{'isopened'} || !$hide_resolved)) { - push (@{$bugs->{$bug_id}->{'dependencies'}}, $dep_id); + # Due to AUTOLOAD in Bug.pm, we cannot add 'dependencies' + # as a bug object attribute from here. + push(@{$bugs->{'dependencies'}->{$bug_id}}, $dep_id); $ids->{$dep_id} = 1; } } } - -sub GetBug { - # Retrieves the necessary information about a bug, stores it in the bug cache, - # and returns it to the calling code. - my ($id) = @_; - my $dbh = Bugzilla->dbh; - - my $bug = {}; - if (Bugzilla->user->can_see_bug($id)) { - ($bug->{'exists'}, - $bug->{'status'}, - $bug->{'resolution'}, - $bug->{'summary'}, - $bug->{'milestone'}, - $bug->{'assignee_id'}, - $bug->{'assignee_email'}) = $dbh->selectrow_array( - "SELECT 1, - bug_status, - resolution, - short_desc, - $milestone_column, - assignee.userid, - assignee.login_name - FROM bugs - INNER JOIN profiles AS assignee - ON bugs.assigned_to = assignee.userid - WHERE bugs.bug_id = ?", undef, $id); - } - - $bug->{'open'} = $bug->{'exists'} && is_open_state($bug->{'status'}); - $bug->{'dependencies'} = []; - - return $bug; -} - -sub GetDependencies { - # Returns a list of dependencies for a given bug. - my ($id, $relationship) = @_; - my $dbh = Bugzilla->dbh; - - my $bug_type = ($relationship eq "blocked") ? "dependson" : "blocked"; - - my $dependencies = $dbh->selectcol_arrayref( - "SELECT $relationship - FROM dependencies - WHERE $bug_type = ? - ORDER BY $relationship", undef, $id); - - return @$dependencies; -} - -- cgit v1.2.3-24-g4f1b