2222# Andreas Franke <afranke@mathweb.org>
2323# Christian Reis <kiko@async.com.br>
2424# Myk Melez <myk@mozilla.org>
25+ # Frédéric Buclin <LpSolit@gmail.com>
2526
2627use strict;
2728
2829use lib qw( .) ;
2930require " globals.pl" ;
3031use Bugzilla;
31- use Bugzilla::User;
3232use Bugzilla::Bug;
3333
34- Bugzilla-> login();
34+ my $user = Bugzilla-> login();
3535
3636my $cgi = Bugzilla-> cgi;
3737my $template = Bugzilla-> template;
@@ -48,6 +48,7 @@ my $dbh = Bugzilla->switch_to_shadow_db();
4848# bug that the user is authorized to access.
4949my $id = $cgi -> param(' id' );
5050ValidateBugID($id );
51+ my $current_bug = new Bugzilla::Bug($id , $user -> id);
5152
5253my $hide_resolved = $cgi -> param(' hide_resolved' ) ? 1 : 0;
5354
@@ -58,27 +59,20 @@ if ($maxdepth !~ /^\d+$/) { $maxdepth = 0 };
5859# Main Section #
5960# ###############################################################################
6061
61- # The column/value to select as the target milestone for bugs,
62- # either the target_milestone column or the empty string value
63- # (for installations that don't use target milestones). Makes
64- # it easier to query the database for bugs because we don't
65- # have to embed a conditional statement into each query.
66- my $milestone_column = Param(' usetargetmilestone' ) ? " target_milestone" : " ''" ;
67-
6862# Stores the greatest depth to which either tree goes.
6963my $realdepth = 0;
7064
7165# Generate the tree of bugs that this bug depends on and a list of IDs
7266# appearing in the tree.
73- my $dependson_tree = { $id => GetBug( $id ) };
67+ my $dependson_tree = { $id => $current_bug };
7468my $dependson_ids = {};
7569GenerateTree($id , " dependson" , 1, $dependson_tree , $dependson_ids );
7670$vars -> {' dependson_tree' } = $dependson_tree ;
7771$vars -> {' dependson_ids' } = [keys (%$dependson_ids )];
7872
7973# Generate the tree of bugs that this bug blocks and a list of IDs
8074# appearing in the tree.
81- my $blocked_tree = { $id => GetBug( $id ) };
75+ my $blocked_tree = { $id => $current_bug };
8276my $blocked_ids = {};
8377GenerateTree($id , " blocked" , 1, $blocked_tree , $blocked_ids );
8478$vars -> {' blocked_tree' } = $blocked_tree ;
@@ -89,7 +83,6 @@ $vars->{'realdepth'} = $realdepth;
8983$vars -> {' bugid' } = $id ;
9084$vars -> {' maxdepth' } = $maxdepth ;
9185$vars -> {' hide_resolved' } = $hide_resolved ;
92- $vars -> {' canedit' } = UserInGroup(" editbugs" );
9386
9487print $cgi -> header();
9588$template -> process(" bug/dependency-tree.html.tmpl" , $vars )
@@ -102,15 +95,19 @@ $template->process("bug/dependency-tree.html.tmpl", $vars)
10295sub GenerateTree {
10396 # Generates a dependency tree for a given bug. Calls itself recursively
10497 # to generate sub-trees for the bug's dependencies.
105-
10698 my ($bug_id , $relationship , $depth , $bugs , $ids ) = @_ ;
107-
108- # Query the database for bugs with the given dependency relationship.
109- my @dependencies = GetDependencies($bug_id , $relationship );
110-
99+
100+ my @dependencies ;
101+ if ($relationship eq ' dependson' ) {
102+ @dependencies = @{$bugs -> {$bug_id }-> dependson};
103+ }
104+ else {
105+ @dependencies = @{$bugs -> {$bug_id }-> blocked};
106+ }
107+
111108 # Don't do anything if this bug doesn't have any dependencies.
112109 return unless scalar (@dependencies );
113-
110+
114111 # Record this depth in the global $realdepth variable if it's farther
115112 # than we've gone before.
116113 $realdepth = max($realdepth , $depth );
@@ -120,71 +117,22 @@ sub GenerateTree {
120117 # its sub-tree if we haven't already done so (which happens
121118 # when bugs appear in dependency trees multiple times).
122119 if (!$bugs -> {$dep_id }) {
123- $bugs -> {$dep_id } = GetBug ($dep_id );
120+ $bugs -> {$dep_id } = new Bugzilla::Bug ($dep_id , $user -> id );
124121 GenerateTree($dep_id , $relationship , $depth +1, $bugs , $ids );
125122 }
126123
127124 # Add this dependency to the list of this bug's dependencies
128125 # if it exists, if we haven't exceeded the maximum depth the user
129126 # wants the tree to go, and if the dependency isn't resolved
130127 # (if we're ignoring resolved dependencies).
131- if ($bugs -> {$dep_id }-> {' exists ' }
128+ if (! $bugs -> {$dep_id }-> {' error ' }
132129 && (!$maxdepth || $depth <= $maxdepth )
133- && ($bugs -> {$dep_id }-> {' open ' } || !$hide_resolved ))
130+ && ($bugs -> {$dep_id }-> {' isopened ' } || !$hide_resolved ))
134131 {
135- push (@{$bugs -> {$bug_id }-> {' dependencies' }}, $dep_id );
132+ # Due to AUTOLOAD in Bug.pm, we cannot add 'dependencies'
133+ # as a bug object attribute from here.
134+ push (@{$bugs -> {' dependencies' }-> {$bug_id }}, $dep_id );
136135 $ids -> {$dep_id } = 1;
137136 }
138137 }
139138}
140-
141- sub GetBug {
142- # Retrieves the necessary information about a bug, stores it in the bug cache,
143- # and returns it to the calling code.
144- my ($id ) = @_ ;
145- my $dbh = Bugzilla-> dbh;
146-
147- my $bug = {};
148- if (Bugzilla-> user-> can_see_bug($id )) {
149- ($bug -> {' exists' },
150- $bug -> {' status' },
151- $bug -> {' resolution' },
152- $bug -> {' summary' },
153- $bug -> {' milestone' },
154- $bug -> {' assignee_id' },
155- $bug -> {' assignee_email' }) = $dbh -> selectrow_array(
156- " SELECT 1,
157- bug_status,
158- resolution,
159- short_desc,
160- $milestone_column ,
161- assignee.userid,
162- assignee.login_name
163- FROM bugs
164- INNER JOIN profiles AS assignee
165- ON bugs.assigned_to = assignee.userid
166- WHERE bugs.bug_id = ?" , undef , $id );
167- }
168-
169- $bug -> {' open' } = $bug -> {' exists' } && is_open_state($bug -> {' status' });
170- $bug -> {' dependencies' } = [];
171-
172- return $bug ;
173- }
174-
175- sub GetDependencies {
176- # Returns a list of dependencies for a given bug.
177- my ($id , $relationship ) = @_ ;
178- my $dbh = Bugzilla-> dbh;
179-
180- my $bug_type = ($relationship eq " blocked" ) ? " dependson" : " blocked" ;
181-
182- my $dependencies = $dbh -> selectcol_arrayref(
183- " SELECT $relationship
184- FROM dependencies
185- WHERE $bug_type = ?
186- ORDER BY $relationship " , undef , $id );
187-
188- return @$dependencies ;
189- }
190-
0 commit comments