From e24b38a78773e0810b40e0905bca5563252eb49c Mon Sep 17 00:00:00 2001 From: "mkanat%bugzilla.org" <> Date: Sat, 18 Oct 2008 21:30:20 +0000 Subject: Bug 460293: Implement Bugzilla::Object::set_all and have editkeywords.cgi use it Patch By Max Kanat-Alexander r=LpSolit, a=LpSolit --- Bugzilla/Object.pm | 39 +++++++++++++++++++++++++++++++++++---- editkeywords.cgi | 6 ++++-- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Bugzilla/Object.pm b/Bugzilla/Object.pm index 532b2c5bc..1e624e5f7 100644 --- a/Bugzilla/Object.pm +++ b/Bugzilla/Object.pm @@ -240,6 +240,14 @@ sub set { $self->{$field} = $value; } +sub set_all { + my ($self, $params) = @_; + foreach my $key (keys %$params) { + my $method = "set_$key"; + $self->$method($params->{$key}); + } +} + sub update { my $self = shift; @@ -743,10 +751,10 @@ not safe to use the object after it has been removed from the database. =back -=head2 Subclass Helpers +=head2 Mutators -These functions are intended only for use by subclasses. If -you call them from anywhere else, they will throw a C. +These are used for updating the values in objects, before calling +C. =over @@ -767,9 +775,11 @@ C will call it with C<($value, $field)> as arguments, after running the validator for this particular field. C<_set_global_validator> does not return anything. - See L for more information. +B: This function is intended only for use by subclasses. If +you call it from anywhere else, it will throw a C. + =item B =over @@ -785,6 +795,27 @@ be the same as the name of the field in L, if it exists there. =back + +=item C + +=over + +=item B + +This is a convenience function which is simpler than calling many different +C functions in a row. You pass a hashref of parameters and it calls +C for every item in the hashref. + +=item B + +Takes a hashref of the fields that need to be set, pointing to the value +that should be passed to the C function that is called. + +=item B (nothing) + +=back + + =back =head2 Simple Validators diff --git a/editkeywords.cgi b/editkeywords.cgi index 1e5d77296..dbc92971d 100755 --- a/editkeywords.cgi +++ b/editkeywords.cgi @@ -131,8 +131,10 @@ if ($action eq 'update') { my $keyword = new Bugzilla::Keyword($key_id) || ThrowCodeError('invalid_keyword_id', { id => $key_id }); - $keyword->set_name($cgi->param('name')); - $keyword->set_description($cgi->param('description')); + $keyword->set_all({ + name => scalar $cgi->param('name'), + description => scalar $cgi->param('description'), + }); my $changes = $keyword->update(); delete_token($token); -- cgit v1.2.1