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.
|
|
|
|
#
|
2006-02-23 07:38:56 +03:00
|
|
|
# (basically replace each occurrence of 'milestone' with 'version', and
|
2000-03-21 19:47:06 +03:00
|
|
|
# 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>
|
2006-06-21 04:44:48 +04:00
|
|
|
# Frédé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
|
|
|
|
2006-02-21 16:08:24 +03:00
|
|
|
use Bugzilla;
|
2004-03-27 06:51:44 +03:00
|
|
|
use Bugzilla::Constants;
|
2006-06-21 04:44:48 +04:00
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Error;
|
2005-07-28 04:35:50 +04:00
|
|
|
use Bugzilla::Milestone;
|
2005-07-20 19:58:45 +04:00
|
|
|
use Bugzilla::Bug;
|
2006-10-15 02:02:13 +04:00
|
|
|
use Bugzilla::Token;
|
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')
|
2006-11-10 19:51:30 +03:00
|
|
|
|| scalar(@{$user->get_products_by_permission('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'));
|
2006-10-15 02:02:13 +04:00
|
|
|
my $token = $cgi->param('token');
|
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) {
|
2006-11-10 19:51:30 +03:00
|
|
|
my $selectable_products = $user->get_selectable_products;
|
|
|
|
# If the user has editcomponents privs for some products only,
|
|
|
|
# we have to restrict the list of products to display.
|
|
|
|
unless ($user->in_group('editcomponents')) {
|
|
|
|
$selectable_products = $user->get_products_by_permission('editcomponents');
|
|
|
|
}
|
|
|
|
$vars->{'products'} = $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;
|
|
|
|
}
|
|
|
|
|
2006-11-10 19:51:30 +03:00
|
|
|
my $product = $user->check_can_admin_product($product_name);
|
2005-12-12 06:12:26 +03:00
|
|
|
|
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;
|
2006-03-02 01:10:24 +03:00
|
|
|
$vars->{'product'} = $product;
|
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') {
|
2006-10-15 02:02:13 +04:00
|
|
|
$vars->{'token'} = issue_session_token('add_milestone');
|
2006-03-02 01:10:24 +03:00
|
|
|
$vars->{'product'} = $product;
|
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') {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'add_milestone');
|
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);
|
|
|
|
|
2006-12-19 13:35:43 +03:00
|
|
|
my $milestone = new Bugzilla::Milestone(
|
|
|
|
{ product => $product, name => $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
|
|
|
|
2006-12-19 13:35:43 +03:00
|
|
|
$milestone = new Bugzilla::Milestone(
|
|
|
|
{ product => $product, name => $milestone_name });
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
|
|
|
|
2006-03-02 01:10:24 +03:00
|
|
|
$vars->{'milestone'} = $milestone;
|
|
|
|
$vars->{'product'} = $product;
|
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);
|
|
|
|
|
2006-03-02 01:10:24 +03:00
|
|
|
$vars->{'milestone'} = $milestone;
|
|
|
|
$vars->{'product'} = $product;
|
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);
|
|
|
|
}
|
2006-10-15 02:02:13 +04:00
|
|
|
$vars->{'token'} = issue_session_token('delete_milestone');
|
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') {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'delete_milestone');
|
2005-07-28 04:35:50 +04:00
|
|
|
my $milestone =
|
|
|
|
Bugzilla::Milestone::check_milestone($product,
|
|
|
|
$milestone_name);
|
2006-03-02 01:10:24 +03:00
|
|
|
$vars->{'milestone'} = $milestone;
|
|
|
|
$vars->{'product'} = $product;
|
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
|
|
|
|
2006-03-02 01:10:24 +03:00
|
|
|
if ($milestone->bug_count) {
|
|
|
|
# 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 = ?",
|
|
|
|
undef, ($product->id, $milestone->name));
|
2005-04-06 04:19:56 +04:00
|
|
|
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
|
|
|
$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
|
|
|
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
|
|
|
|
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
|
|
|
|
2006-03-02 01:10:24 +03:00
|
|
|
$vars->{'milestone'} = $milestone;
|
|
|
|
$vars->{'product'} = $product;
|
2006-10-15 02:02:13 +04:00
|
|
|
$vars->{'token'} = issue_session_token('edit_milestone');
|
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') {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'edit_milestone');
|
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
|
|
|
|
|
|
|
$vars->{'updated_sortkey'} = 1;
|
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
|
|
|
}
|
2006-12-19 13:35:43 +03:00
|
|
|
my $milestone = new Bugzilla::Milestone(
|
|
|
|
{ product => $product, name => $milestone_name });
|
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
|
|
|
}
|
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
|
|
|
|
|
|
|
$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
|
|
|
|
2006-03-02 01:10:24 +03:00
|
|
|
my $milestone =
|
|
|
|
Bugzilla::Milestone::check_milestone($product,
|
|
|
|
$milestone_name);
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
|
|
|
|
2006-03-02 01:10:24 +03:00
|
|
|
$vars->{'milestone'} = $milestone;
|
|
|
|
$vars->{'product'} = $product;
|
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"});
|