summaryrefslogtreecommitdiffstats
path: root/Bugzilla/WebService/Util.pm
diff options
context:
space:
mode:
authorJulien Heyman <jheyman@portaildulibre.fr>2011-08-09 23:59:35 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2011-08-09 23:59:35 +0200
commitbffbe0c95c01c9878c620fe7a55657e802f0637c (patch)
tree46b3893638271990885bcb66377ba9ce656e12d4 /Bugzilla/WebService/Util.pm
parent4b113460e54775cbd3e5e412ad37b9ba7ab66edc (diff)
downloadbugzilla-bffbe0c95c01c9878c620fe7a55657e802f0637c.tar.gz
bugzilla-bffbe0c95c01c9878c620fe7a55657e802f0637c.tar.xz
Bug 647980: Implement a Product.update WebService method.
r=mkanat, a=mkanat
Diffstat (limited to 'Bugzilla/WebService/Util.pm')
-rw-r--r--Bugzilla/WebService/Util.pm43
1 files changed, 43 insertions, 0 deletions
diff --git a/Bugzilla/WebService/Util.pm b/Bugzilla/WebService/Util.pm
index adb7fb43a..41dd07c1e 100644
--- a/Bugzilla/WebService/Util.pm
+++ b/Bugzilla/WebService/Util.pm
@@ -32,6 +32,8 @@ our @EXPORT_OK = qw(
filter_wants
taint_data
validate
+ translate
+ params_to_objects
);
sub filter ($$) {
@@ -108,6 +110,31 @@ sub validate {
return ($self, $params);
}
+sub translate {
+ my ($params, $mapped) = @_;
+ my %changes;
+ while (my ($key,$value) = each (%$params)) {
+ my $new_field = $mapped->{$key} || $key;
+ $changes{$new_field} = $value;
+ }
+ return \%changes;
+}
+
+sub params_to_objects {
+ my ($params, $class) = @_;
+
+ my @objects = map { $class->check($_) }
+ @{ $params->{names} } if $params->{names};
+
+ my @objects_by_ids = map { $class->check({ id => $_ }) }
+ @{ $params->{ids} } if $params->{ids};
+
+ push(@objects, @objects_by_ids);
+ my %seen;
+ @objects = grep { !$seen{$_->id}++ } @objects;
+ return \@objects;
+}
+
__END__
=head1 NAME
@@ -147,3 +174,19 @@ This helps in the validation of parameters passed into the WebSerice
methods. Currently it converts listed parameters into an array reference
if the client only passed a single scalar value. It modifies the parameters
hash in place so other parameters should be unaltered.
+
+=head2 translate
+
+WebService methods frequently take parameters with different names than
+the ones that we use internally in Bugzilla. This function takes a hashref
+that has field names for keys and returns a hashref with those keys renamed
+according to the mapping passed in with the second parameter (which is also
+a hashref).
+
+=head2 params_to_objects
+
+Creates objects of the type passed in as the second parameter, using the
+parameters passed to a WebService method (the first parameter to this function).
+Helps make life simpler for WebService methods that internally create objects
+via both "ids" and "names" fields. Also de-duplicates objects that were loaded
+by both "ids" and "names". Returns an arrayref of objects.