2004-05-23 11:22:32 +04:00
|
|
|
|
#!/usr/bin/perl -wT
|
2000-03-21 19:47:06 +03:00
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# This is a script to edit the target milestones. It is largely a copy of
|
|
|
|
|
# the editversions.cgi script, since the two fields were set up in a
|
|
|
|
|
# very similar fashion.
|
|
|
|
|
#
|
|
|
|
|
# (basically replace each occurance of 'milestone' with 'version', and
|
|
|
|
|
# you'll have the original script)
|
|
|
|
|
#
|
|
|
|
|
# Matt Masson <matthew@zeroknowledge.com>
|
|
|
|
|
#
|
2004-09-11 10:48:14 +04:00
|
|
|
|
# Contributors : Gavin Shelley <bugzilla@chimpychompy.org>
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# Fr<46>d<EFBFBD>ric Buclin <LpSolit@gmail.com>
|
2004-09-11 10:48:14 +04:00
|
|
|
|
#
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use strict;
|
2002-04-29 23:32:29 +04:00
|
|
|
|
use lib ".";
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
require "globals.pl";
|
|
|
|
|
|
2006-02-21 16:08:24 +03:00
|
|
|
|
use Bugzilla;
|
2004-03-27 06:51:44 +03:00
|
|
|
|
use Bugzilla::Constants;
|
2003-11-22 06:50:42 +03:00
|
|
|
|
use Bugzilla::Config qw(:DEFAULT $datadir);
|
2005-07-28 04:35:50 +04:00
|
|
|
|
use Bugzilla::Product;
|
|
|
|
|
use Bugzilla::Milestone;
|
2005-07-20 19:58:45 +04:00
|
|
|
|
use Bugzilla::Bug;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-10-25 03:11:56 +04:00
|
|
|
|
my $template = Bugzilla->template;
|
|
|
|
|
my $vars = {};
|
2005-05-03 23:41:23 +04:00
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
#
|
|
|
|
|
# Preliminary checks:
|
|
|
|
|
#
|
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
my $user = Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
|
my $whoid = $user->id;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
print $cgi->header();
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-09-16 02:01:56 +04:00
|
|
|
|
$user->in_group('editcomponents')
|
2005-01-16 17:07:31 +03:00
|
|
|
|
|| ThrowUserError("auth_failure", {group => "editcomponents",
|
|
|
|
|
action => "edit",
|
|
|
|
|
object => "milestones"});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# often used variables
|
|
|
|
|
#
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $product_name = trim($cgi->param('product') || '');
|
|
|
|
|
my $milestone_name = trim($cgi->param('milestone') || '');
|
|
|
|
|
my $sortkey = trim($cgi->param('sortkey') || 0);
|
|
|
|
|
my $action = trim($cgi->param('action') || '');
|
2005-09-28 02:08:14 +04:00
|
|
|
|
my $showbugcounts = (defined $cgi->param('showbugcounts'));
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
#
|
2005-07-28 04:35:50 +04:00
|
|
|
|
# product = '' -> Show nice list of products
|
2000-03-21 19:47:06 +03:00
|
|
|
|
#
|
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
unless ($product_name) {
|
2005-12-12 06:12:26 +03:00
|
|
|
|
$vars->{'products'} = $user->get_selectable_products;
|
2005-09-28 02:08:14 +04:00
|
|
|
|
$vars->{'showbugcounts'} = $showbugcounts;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-12-12 06:12:26 +03:00
|
|
|
|
$template->process("admin/milestones/select-product.html.tmpl", $vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
2005-12-12 06:12:26 +03:00
|
|
|
|
# First make sure the product name is valid.
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $product = Bugzilla::Product::check_product($product_name);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-12-12 06:12:26 +03:00
|
|
|
|
# Then make sure the user is allowed to edit properties of this product.
|
|
|
|
|
$user->can_see_product($product->name)
|
|
|
|
|
|| ThrowUserError('product_access_denied', {product => $product->name});
|
|
|
|
|
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
#
|
|
|
|
|
# action='' -> Show nice list of milestones
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
unless ($action) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-09-28 02:08:14 +04:00
|
|
|
|
$vars->{'showbugcounts'} = $showbugcounts;
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$vars->{'product'} = $product->name;
|
2005-10-06 22:45:46 +04:00
|
|
|
|
$vars->{'milestones'} = $product->milestones;
|
2005-08-28 21:41:53 +04:00
|
|
|
|
$vars->{'default_milestone'} = $product->default_milestone;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$template->process("admin/milestones/list.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='add' -> present form for parameters for new milestone
|
|
|
|
|
#
|
|
|
|
|
# (next action will be 'new')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'add') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$vars->{'product'} = $product->name;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$template->process("admin/milestones/create.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='new' -> add milestone entered in the 'action=add' screen
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'new') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$milestone_name || ThrowUserError('milestone_blank_name');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
if (length($milestone_name) > 20) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
ThrowUserError('milestone_name_too_long',
|
2005-07-28 04:35:50 +04:00
|
|
|
|
{'name' => $milestone_name});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$sortkey = Bugzilla::Milestone::check_sort_key($milestone_name,
|
|
|
|
|
$sortkey);
|
|
|
|
|
|
|
|
|
|
my $milestone = new Bugzilla::Milestone($product->id,
|
|
|
|
|
$milestone_name);
|
2005-05-03 23:41:23 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
if ($milestone) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
ThrowUserError('milestone_already_exists',
|
2005-07-28 04:35:50 +04:00
|
|
|
|
{'name' => $milestone->name,
|
|
|
|
|
'product' => $product->name});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Add the new milestone
|
2005-07-28 04:35:50 +04:00
|
|
|
|
trick_taint($milestone_name);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$dbh->do('INSERT INTO milestones ( value, product_id, sortkey )
|
|
|
|
|
VALUES ( ?, ?, ? )',
|
2005-07-28 04:35:50 +04:00
|
|
|
|
undef, $milestone_name, $product->id, $sortkey);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
# Make versioncache flush
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$vars->{'name'} = $milestone_name;
|
|
|
|
|
$vars->{'product'} = $product->name;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$template->process("admin/milestones/created.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='del' -> ask if user really wants to delete
|
|
|
|
|
#
|
|
|
|
|
# (next action would be 'delete')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'del') {
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $milestone = Bugzilla::Milestone::check_milestone($product,
|
|
|
|
|
$milestone_name);
|
|
|
|
|
|
|
|
|
|
$vars->{'name'} = $milestone->name;
|
|
|
|
|
$vars->{'product'} = $product->name;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# The default milestone cannot be deleted.
|
2005-07-28 04:35:50 +04:00
|
|
|
|
if ($product->default_milestone eq $milestone->name) {
|
2005-04-06 04:19:56 +04:00
|
|
|
|
ThrowUserError("milestone_is_default", $vars);
|
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$vars->{'bug_count'} = $milestone->bug_count;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$template->process("admin/milestones/confirm-delete.html.tmpl", $vars)
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='delete' -> really delete the milestone
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $milestone =
|
|
|
|
|
Bugzilla::Milestone::check_milestone($product,
|
|
|
|
|
$milestone_name);
|
|
|
|
|
$vars->{'name'} = $milestone->name;
|
|
|
|
|
$vars->{'product'} = $product->name;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# The default milestone cannot be deleted.
|
2005-07-28 04:35:50 +04:00
|
|
|
|
if ($milestone->name eq $product->default_milestone) {
|
2005-04-06 04:19:56 +04:00
|
|
|
|
ThrowUserError("milestone_is_default", $vars);
|
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# We don't want to delete bugs when deleting a milestone.
|
|
|
|
|
# Bugs concerned are reassigned to the default milestone.
|
|
|
|
|
my $bug_ids =
|
|
|
|
|
$dbh->selectcol_arrayref("SELECT bug_id FROM bugs
|
|
|
|
|
WHERE product_id = ? AND target_milestone = ?",
|
2005-07-28 04:35:50 +04:00
|
|
|
|
undef, ($product->id, $milestone->name));
|
2005-04-06 04:19:56 +04:00
|
|
|
|
|
|
|
|
|
my $nb_bugs = scalar(@$bug_ids);
|
|
|
|
|
if ($nb_bugs) {
|
|
|
|
|
my $timestamp = $dbh->selectrow_array("SELECT NOW()");
|
|
|
|
|
foreach my $bug_id (@$bug_ids) {
|
|
|
|
|
$dbh->do("UPDATE bugs SET target_milestone = ?,
|
|
|
|
|
delta_ts = ? WHERE bug_id = ?",
|
2005-07-28 04:35:50 +04:00
|
|
|
|
undef, ($product->default_milestone, $timestamp,
|
|
|
|
|
$bug_id));
|
2005-04-06 04:19:56 +04:00
|
|
|
|
# We have to update the 'bugs_activity' table too.
|
2005-07-28 04:35:50 +04:00
|
|
|
|
LogActivityEntry($bug_id, 'target_milestone',
|
|
|
|
|
$milestone->name,
|
|
|
|
|
$product->default_milestone,
|
|
|
|
|
$whoid, $timestamp);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$vars->{'bug_count'} = $nb_bugs;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$dbh->do("DELETE FROM milestones WHERE product_id = ? AND value = ?",
|
2005-07-28 04:35:50 +04:00
|
|
|
|
undef, ($product->id, $milestone->name));
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-04-06 04:19:56 +04:00
|
|
|
|
$template->process("admin/milestones/deleted.html.tmpl", $vars)
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='edit' -> present the edit milestone form
|
|
|
|
|
#
|
|
|
|
|
# (next action would be 'update')
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'edit') {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $milestone =
|
|
|
|
|
Bugzilla::Milestone::check_milestone($product,
|
|
|
|
|
$milestone_name);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$vars->{'sortkey'} = $milestone->sortkey;
|
|
|
|
|
$vars->{'name'} = $milestone->name;
|
|
|
|
|
$vars->{'product'} = $product->name;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$template->process("admin/milestones/edit.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# action='update' -> update the milestone
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
if ($action eq 'update') {
|
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $milestone_old_name = trim($cgi->param('milestoneold') || '');
|
|
|
|
|
my $milestone_old =
|
|
|
|
|
Bugzilla::Milestone::check_milestone($product,
|
|
|
|
|
$milestone_old_name);
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
if (length($milestone_name) > 20) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
ThrowUserError('milestone_name_too_long',
|
2005-07-28 04:35:50 +04:00
|
|
|
|
{'name' => $milestone_name});
|
2004-09-11 10:48:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-18 00:57:27 +03:00
|
|
|
|
$dbh->bz_lock_tables('bugs WRITE',
|
|
|
|
|
'milestones WRITE',
|
|
|
|
|
'products WRITE');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
if ($sortkey ne $milestone_old->sortkey) {
|
|
|
|
|
$sortkey = Bugzilla::Milestone::check_sort_key($milestone_name,
|
|
|
|
|
$sortkey);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
$dbh->do('UPDATE milestones SET sortkey = ?
|
|
|
|
|
WHERE product_id = ?
|
|
|
|
|
AND value = ?',
|
|
|
|
|
undef,
|
|
|
|
|
$sortkey,
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$product->id,
|
|
|
|
|
$milestone_old->name);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$vars->{'updated_sortkey'} = 1;
|
|
|
|
|
$vars->{'sortkey'} = $sortkey;
|
2001-04-06 20:47:49 +04:00
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
if ($milestone_name ne $milestone_old->name) {
|
|
|
|
|
unless ($milestone_name) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
ThrowUserError('milestone_blank_name');
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
2005-07-28 04:35:50 +04:00
|
|
|
|
my $milestone =
|
|
|
|
|
new Bugzilla::Milestone($product->id, $milestone_name);
|
|
|
|
|
if ($milestone) {
|
2004-09-11 10:48:14 +04:00
|
|
|
|
ThrowUserError('milestone_already_exists',
|
2005-07-28 04:35:50 +04:00
|
|
|
|
{'name' => $milestone->name,
|
|
|
|
|
'product' => $product->name});
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
trick_taint($milestone_name);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
$dbh->do('UPDATE bugs
|
2005-02-08 19:51:03 +03:00
|
|
|
|
SET target_milestone = ?
|
2004-09-11 10:48:14 +04:00
|
|
|
|
WHERE target_milestone = ?
|
|
|
|
|
AND product_id = ?',
|
|
|
|
|
undef,
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$milestone_name,
|
|
|
|
|
$milestone_old->name,
|
|
|
|
|
$product->id);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
$dbh->do("UPDATE milestones
|
|
|
|
|
SET value = ?
|
|
|
|
|
WHERE product_id = ?
|
|
|
|
|
AND value = ?",
|
|
|
|
|
undef,
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$milestone_name,
|
|
|
|
|
$product->id,
|
|
|
|
|
$milestone_old->name);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
$dbh->do("UPDATE products
|
|
|
|
|
SET defaultmilestone = ?
|
|
|
|
|
WHERE id = ?
|
|
|
|
|
AND defaultmilestone = ?",
|
|
|
|
|
undef,
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$milestone_name,
|
|
|
|
|
$product->id,
|
|
|
|
|
$milestone_old->name);
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2003-11-22 06:50:42 +03:00
|
|
|
|
unlink "$datadir/versioncache";
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
|
|
|
|
$vars->{'updated_name'} = 1;
|
2000-03-21 19:47:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
2005-02-18 00:57:27 +03:00
|
|
|
|
$dbh->bz_unlock_tables();
|
2004-09-11 10:48:14 +04:00
|
|
|
|
|
2005-07-28 04:35:50 +04:00
|
|
|
|
$vars->{'name'} = $milestone_name;
|
|
|
|
|
$vars->{'product'} = $product->name;
|
2004-09-11 10:48:14 +04:00
|
|
|
|
$template->process("admin/milestones/updated.html.tmpl",
|
|
|
|
|
$vars)
|
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
|
|
2000-03-21 19:47:06 +03:00
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# No valid action found
|
|
|
|
|
#
|
2005-02-16 19:35:54 +03:00
|
|
|
|
ThrowUserError('no_valid_action', {'field' => "target_milestone"});
|