2003-03-27 00:07:02 +00:00
|
|
|
#!/usr/bin/perl -wT
|
1999-05-27 14:13:41 +00:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
1999-11-01 23:33:56 +00:00
|
|
|
# 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.
|
|
|
|
#
|
1999-05-27 14:13:41 +00:00
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
1999-11-01 23:33:56 +00:00
|
|
|
#
|
1999-05-27 14:13:41 +00:00
|
|
|
# The Initial Developer of the Original Code is Netscape Communications
|
1999-11-01 23:33:56 +00:00
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
1999-05-27 14:13:41 +00:00
|
|
|
# Contributor(s): Terry Weissman <terry@mozilla.org>
|
2001-10-11 23:01:44 +00:00
|
|
|
# Andreas Franke <afranke@mathweb.org>
|
|
|
|
# Christian Reis <kiko@async.com.br>
|
2002-04-17 21:58:30 +00:00
|
|
|
# Myk Melez <myk@mozilla.org>
|
2006-04-17 20:36:34 +00:00
|
|
|
# Frédéric Buclin <LpSolit@gmail.com>
|
1999-05-27 14:13:41 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
2001-10-11 23:01:44 +00:00
|
|
|
use lib qw(.);
|
2005-08-10 01:30:41 +00:00
|
|
|
require "globals.pl";
|
2006-02-21 13:08:24 +00:00
|
|
|
use Bugzilla;
|
2005-07-20 11:29:33 +00:00
|
|
|
use Bugzilla::Bug;
|
1999-05-27 14:13:41 +00:00
|
|
|
|
2006-04-17 20:36:34 +00:00
|
|
|
my $user = Bugzilla->login();
|
2001-05-31 15:52:25 +00:00
|
|
|
|
2003-05-05 01:15:38 +00:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-10-24 23:11:56 +00:00
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $vars = {};
|
2003-01-24 10:59:08 +00:00
|
|
|
# Connect to the shadow database if this installation is using one to improve
|
|
|
|
# performance.
|
2005-11-13 17:50:47 +00:00
|
|
|
my $dbh = Bugzilla->switch_to_shadow_db();
|
2003-01-24 10:59:08 +00:00
|
|
|
|
2002-04-17 21:58:30 +00:00
|
|
|
################################################################################
|
|
|
|
# Data/Security Validation #
|
|
|
|
################################################################################
|
2001-05-31 15:52:25 +00:00
|
|
|
|
|
|
|
# Make sure the bug ID is a positive integer representing an existing
|
2002-04-17 21:58:30 +00:00
|
|
|
# bug that the user is authorized to access.
|
2004-03-26 21:00:11 +00:00
|
|
|
my $id = $cgi->param('id');
|
|
|
|
ValidateBugID($id);
|
2006-04-17 20:36:34 +00:00
|
|
|
my $current_bug = new Bugzilla::Bug($id, $user->id);
|
2001-10-11 23:01:44 +00:00
|
|
|
|
2004-03-26 21:00:11 +00:00
|
|
|
my $hide_resolved = $cgi->param('hide_resolved') ? 1 : 0;
|
1999-05-27 14:13:41 +00:00
|
|
|
|
2004-03-26 21:00:11 +00:00
|
|
|
my $maxdepth = $cgi->param('maxdepth') || 0;
|
2002-04-17 21:58:30 +00:00
|
|
|
if ($maxdepth !~ /^\d+$/) { $maxdepth = 0 };
|
1999-05-27 14:13:41 +00:00
|
|
|
|
2002-04-17 21:58:30 +00:00
|
|
|
################################################################################
|
|
|
|
# Main Section #
|
|
|
|
################################################################################
|
2001-10-16 03:09:52 +00:00
|
|
|
|
2006-02-22 22:02:12 +00:00
|
|
|
# Stores the greatest depth to which either tree goes.
|
2001-10-11 23:01:44 +00:00
|
|
|
my $realdepth = 0;
|
|
|
|
|
2002-04-17 21:58:30 +00:00
|
|
|
# Generate the tree of bugs that this bug depends on and a list of IDs
|
|
|
|
# appearing in the tree.
|
2006-04-17 20:36:34 +00:00
|
|
|
my $dependson_tree = { $id => $current_bug };
|
2002-04-17 21:58:30 +00:00
|
|
|
my $dependson_ids = {};
|
|
|
|
GenerateTree($id, "dependson", 1, $dependson_tree, $dependson_ids);
|
|
|
|
$vars->{'dependson_tree'} = $dependson_tree;
|
|
|
|
$vars->{'dependson_ids'} = [keys(%$dependson_ids)];
|
|
|
|
|
|
|
|
# Generate the tree of bugs that this bug blocks and a list of IDs
|
|
|
|
# appearing in the tree.
|
2006-04-17 20:36:34 +00:00
|
|
|
my $blocked_tree = { $id => $current_bug };
|
2002-04-17 21:58:30 +00:00
|
|
|
my $blocked_ids = {};
|
|
|
|
GenerateTree($id, "blocked", 1, $blocked_tree, $blocked_ids);
|
|
|
|
$vars->{'blocked_tree'} = $blocked_tree;
|
|
|
|
$vars->{'blocked_ids'} = [keys(%$blocked_ids)];
|
|
|
|
|
|
|
|
$vars->{'realdepth'} = $realdepth;
|
|
|
|
|
|
|
|
$vars->{'bugid'} = $id;
|
|
|
|
$vars->{'maxdepth'} = $maxdepth;
|
|
|
|
$vars->{'hide_resolved'} = $hide_resolved;
|
|
|
|
|
2003-05-05 01:15:38 +00:00
|
|
|
print $cgi->header();
|
2002-04-24 07:24:50 +00:00
|
|
|
$template->process("bug/dependency-tree.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2002-04-17 21:58:30 +00:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Recursive Tree Generation Function #
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
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) = @_;
|
2006-04-17 20:36:34 +00:00
|
|
|
|
|
|
|
my @dependencies;
|
|
|
|
if ($relationship eq 'dependson') {
|
|
|
|
@dependencies = @{$bugs->{$bug_id}->dependson};
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
@dependencies = @{$bugs->{$bug_id}->blocked};
|
|
|
|
}
|
|
|
|
|
2002-04-17 21:58:30 +00:00
|
|
|
# Don't do anything if this bug doesn't have any dependencies.
|
|
|
|
return unless scalar(@dependencies);
|
2006-04-17 20:36:34 +00:00
|
|
|
|
2002-04-17 21:58:30 +00:00
|
|
|
# Record this depth in the global $realdepth variable if it's farther
|
|
|
|
# than we've gone before.
|
|
|
|
$realdepth = max($realdepth, $depth);
|
|
|
|
|
|
|
|
foreach my $dep_id (@dependencies) {
|
|
|
|
# Get this dependency's record from the database and generate
|
|
|
|
# its sub-tree if we haven't already done so (which happens
|
|
|
|
# when bugs appear in dependency trees multiple times).
|
|
|
|
if (!$bugs->{$dep_id}) {
|
2006-04-17 20:36:34 +00:00
|
|
|
$bugs->{$dep_id} = new Bugzilla::Bug($dep_id, $user->id);
|
2002-04-17 21:58:30 +00:00
|
|
|
GenerateTree($dep_id, $relationship, $depth+1, $bugs, $ids);
|
|
|
|
}
|
2001-10-11 23:01:44 +00:00
|
|
|
|
2002-04-17 21:58:30 +00:00
|
|
|
# Add this dependency to the list of this bug's dependencies
|
|
|
|
# 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).
|
2006-04-17 20:36:34 +00:00
|
|
|
if (!$bugs->{$dep_id}->{'error'}
|
2002-04-17 21:58:30 +00:00
|
|
|
&& (!$maxdepth || $depth <= $maxdepth)
|
2006-04-17 20:36:34 +00:00
|
|
|
&& ($bugs->{$dep_id}->{'isopened'} || !$hide_resolved))
|
2002-04-17 21:58:30 +00:00
|
|
|
{
|
2006-04-17 20:36:34 +00:00
|
|
|
# Due to AUTOLOAD in Bug.pm, we cannot add 'dependencies'
|
|
|
|
# as a bug object attribute from here.
|
|
|
|
push(@{$bugs->{'dependencies'}->{$bug_id}}, $dep_id);
|
2002-04-17 21:58:30 +00:00
|
|
|
$ids->{$dep_id} = 1;
|
1999-05-27 14:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|