summaryrefslogtreecommitdiffstats
path: root/editclassifications.cgi
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2009-01-02 14:59:22 +0100
committerlpsolit%gmail.com <>2009-01-02 14:59:22 +0100
commitf6c2d743d87f86cdc206ab4bc772639b4569eebe (patch)
treee4740db3fee1b4b67e30bcc0271696af1b4ab280 /editclassifications.cgi
parent4c1a9a42e60496cde0565c512eec18d81050cccb (diff)
downloadbugzilla-f6c2d743d87f86cdc206ab4bc772639b4569eebe.tar.gz
bugzilla-f6c2d743d87f86cdc206ab4bc772639b4569eebe.tar.xz
Bug 313126: Clean up editclassification.cgi and make it use Bugzilla::Classification methods - Patch by Frédéric Buclin <LpSolit@gmail.com> r=wicked a=LpSolit
Diffstat (limited to 'editclassifications.cgi')
-rwxr-xr-xeditclassifications.cgi104
1 files changed, 15 insertions, 89 deletions
diff --git a/editclassifications.cgi b/editclassifications.cgi
index f2a91a68e..61b014c8d 100755
--- a/editclassifications.cgi
+++ b/editclassifications.cgi
@@ -100,34 +100,15 @@ if ($action eq 'add') {
if ($action eq 'new') {
check_token_data($token, 'add_classification');
- $class_name || ThrowUserError("classification_not_specified");
-
my $classification =
- new Bugzilla::Classification({name => $class_name});
-
- if ($classification) {
- ThrowUserError("classification_already_exists",
- { name => $classification->name });
- }
-
- my $description = trim($cgi->param('description') || '');
-
- my $sortkey = trim($cgi->param('sortkey') || 0);
- my $stored_sortkey = $sortkey;
- detaint_natural($sortkey)
- || ThrowUserError('classification_invalid_sortkey', {'sortkey' => $stored_sortkey});
-
- trick_taint($description);
- trick_taint($class_name);
-
- # Add the new classification.
- $dbh->do("INSERT INTO classifications (name, description, sortkey)
- VALUES (?, ?, ?)", undef, ($class_name, $description, $sortkey));
+ Bugzilla::Classification->create({name => $class_name,
+ description => scalar $cgi->param('description'),
+ sortkey => scalar $cgi->param('sortkey')});
delete_token($token);
$vars->{'message'} = 'classification_created';
- $vars->{'classification'} = new Bugzilla::Classification({name => $class_name});
+ $vars->{'classification'} = $classification;
$vars->{'classifications'} = [Bugzilla::Classification->get_all];
$vars->{'token'} = issue_session_token('reclassify_classifications');
LoadTemplate('reclassify');
@@ -165,27 +146,11 @@ if ($action eq 'delete') {
check_token_data($token, 'delete_classification');
my $classification = Bugzilla::Classification->check($class_name);
-
- if ($classification->id == 1) {
- ThrowUserError("classification_not_deletable");
- }
-
- # lock the tables before we start to change everything:
- $dbh->bz_start_transaction();
-
- # update products just in case
- $dbh->do("UPDATE products SET classification_id = 1
- WHERE classification_id = ?", undef, $classification->id);
-
- # delete
- $dbh->do("DELETE FROM classifications WHERE id = ?", undef,
- $classification->id);
-
- $dbh->bz_commit_transaction();
+ $classification->remove_from_db;
+ delete_token($token);
$vars->{'message'} = 'classification_deleted';
- $vars->{'classification'} = $class_name;
- delete_token($token);
+ $vars->{'classification'} = $classification;
LoadTemplate('select');
}
@@ -196,7 +161,6 @@ if ($action eq 'delete') {
#
if ($action eq 'edit') {
-
my $classification = Bugzilla::Classification->check($class_name);
$vars->{'classification'} = $classification;
@@ -212,57 +176,19 @@ if ($action eq 'edit') {
if ($action eq 'update') {
check_token_data($token, 'edit_classification');
- $class_name || ThrowUserError("classification_not_specified");
-
my $class_old_name = trim($cgi->param('classificationold') || '');
+ my $classification = Bugzilla::Classification->check($class_old_name);
- my $class_old = Bugzilla::Classification->check($class_old_name);
-
- my $description = trim($cgi->param('description') || '');
-
- my $sortkey = trim($cgi->param('sortkey') || 0);
- my $stored_sortkey = $sortkey;
- detaint_natural($sortkey)
- || ThrowUserError('classification_invalid_sortkey', {'sortkey' => $stored_sortkey});
-
- $dbh->bz_start_transaction();
-
- if ($class_name ne $class_old->name) {
-
- my $class = new Bugzilla::Classification({name => $class_name});
- if ($class) {
- ThrowUserError("classification_already_exists",
- { name => $class->name });
- }
- trick_taint($class_name);
- $dbh->do("UPDATE classifications SET name = ? WHERE id = ?",
- undef, ($class_name, $class_old->id));
-
- $vars->{'updated_classification'} = 1;
- }
+ $classification->set_name($class_name);
+ $classification->set_description(scalar $cgi->param('description'));
+ $classification->set_sortkey(scalar $cgi->param('sortkey'));
- if ($description ne $class_old->description) {
- trick_taint($description);
- $dbh->do("UPDATE classifications SET description = ?
- WHERE id = ?", undef,
- ($description, $class_old->id));
-
- $vars->{'updated_description'} = 1;
- }
-
- if ($sortkey ne $class_old->sortkey) {
- $dbh->do("UPDATE classifications SET sortkey = ?
- WHERE id = ?", undef,
- ($sortkey, $class_old->id));
-
- $vars->{'updated_sortkey'} = 1;
- }
-
- $dbh->bz_commit_transaction();
+ my $changes = $classification->update;
+ delete_token($token);
$vars->{'message'} = 'classification_updated';
- $vars->{'classification'} = $class_name;
- delete_token($token);
+ $vars->{'classification'} = $classification;
+ $vars->{'changes'} = $changes;
LoadTemplate('select');
}