diff options
author | mkanat%bugzilla.org <> | 2008-10-03 06:30:38 +0000 |
---|---|---|
committer | mkanat%bugzilla.org <> | 2008-10-03 06:30:38 +0000 |
commit | fab5d3a38aadaed1e6153c0fbd820449258586b2 (patch) | |
tree | 2e1f8816d56aaf213fd9b4e6812b28ed3cbf8527 /Bugzilla/Field | |
parent | 931bd3b651ccca832a618f7b28bbc35e503665d4 (diff) | |
download | bugs-fab5d3a38aadaed1e6153c0fbd820449258586b2.tar bugs-fab5d3a38aadaed1e6153c0fbd820449258586b2.tar.gz bugs-fab5d3a38aadaed1e6153c0fbd820449258586b2.tar.bz2 bugs-fab5d3a38aadaed1e6153c0fbd820449258586b2.tar.xz bugs-fab5d3a38aadaed1e6153c0fbd820449258586b2.zip |
Bug 455641: Implement Bugzilla::Field::Choice->update and have editvalues.cgi use it
Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=bbaetz, a=mkanat
Diffstat (limited to 'Bugzilla/Field')
-rw-r--r-- | Bugzilla/Field/Choice.pm | 84 |
1 files changed, 83 insertions, 1 deletions
diff --git a/Bugzilla/Field/Choice.pm b/Bugzilla/Field/Choice.pm index 7705258eb..9db5c5efd 100644 --- a/Bugzilla/Field/Choice.pm +++ b/Bugzilla/Field/Choice.pm @@ -24,6 +24,7 @@ package Bugzilla::Field::Choice; use base qw(Bugzilla::Object); +use Bugzilla::Config qw(SetParam write_params); use Bugzilla::Constants; use Bugzilla::Error; use Bugzilla::Field; @@ -41,6 +42,11 @@ use constant DB_COLUMNS => qw( sortkey ); +use constant UPDATE_COLUMNS => qw( + value + sortkey +); + use constant NAME_FIELD => 'value'; use constant LIST_ORDER => 'sortkey, value'; @@ -55,6 +61,13 @@ use constant CLASS_MAP => { bug_status => 'Bugzilla::Status', }; +use constant DEFAULT_MAP => { + op_sys => 'defaultopsys', + rep_platform => 'defaultplatform', + priority => 'defaultpriority', + bug_severity => 'defaultseverity', +}; + ################# # Class Factory # ################# @@ -127,6 +140,37 @@ sub create { return $class->SUPER::create(@_); } +sub update { + my $self = shift; + my $dbh = Bugzilla->dbh; + my $fname = $self->field->name; + + $dbh->bz_start_transaction(); + + my ($changes, $old_self) = $self->SUPER::update(@_); + if (exists $changes->{value}) { + my ($old, $new) = @{ $changes->{value} }; + if ($self->field->type == FIELD_TYPE_MULTI_SELECT) { + $dbh->do("UPDATE bug_$fname SET value = ? WHERE value = ?", + undef, $new, $old); + } + else { + $dbh->do("UPDATE bugs SET $fname = ? WHERE $fname = ?", + undef, $new, $old); + } + + if ($old_self->is_default) { + my $param = $self->DEFAULT_MAP->{$self->field->name}; + SetParam($param, $self->name); + write_params(); + } + } + + $dbh->bz_commit_transaction(); + return $changes; +} + + ############# # Accessors # ############# @@ -143,6 +187,35 @@ sub field { return $cache->{"field_$class"}; } +sub is_default { + my $self = shift; + my $param_value = + Bugzilla->params->{ $self->DEFAULT_MAP->{$self->field->name} }; + return 0 if !defined $param_value; + return $self->name eq $param_value ? 1 : 0; +} + +sub is_static { + my $self = shift; + # If we need to special-case Resolution for *anything* else, it should + # get its own subclass. + if ($self->field->name eq 'resolution') { + return grep($_ eq $self->name, ('', 'FIXED', 'MOVED', 'DUPLICATE')) + ? 1 : 0; + } + elsif ($self->field->custom) { + return $self->name eq '---' ? 1 : 0; + } + return 0; +} + +############ +# Mutators # +############ + +sub set_name { $_[0]->set('value', $_[1]); } +sub set_sortkey { $_[0]->set('sortkey', $_[1]); } + ############## # Validators # ############## @@ -153,12 +226,21 @@ sub _check_value { my $field = $invocant->field; $value = trim($value); + + # Make sure people don't rename static values + if (blessed($invocant) && $value ne $invocant->name + && $invocant->is_static) + { + ThrowUserError('fieldvalue_not_editable', + { field => $field, old_value => $invocant->name }); + } + ThrowUserError('fieldvalue_undefined') if !defined $value || $value eq ""; ThrowUserError('fieldvalue_name_too_long', { value => $value }) if length($value) > MAX_FIELD_VALUE_SIZE; my $exists = $invocant->type($field)->new({ name => $value }); - if ($exists) { + if ($exists && (!blessed($invocant) || $invocant->id != $exists->id)) { ThrowUserError('fieldvalue_already_exists', { field => $field, value => $value }); } |