Skip to content

Commit

Permalink
MDL-53962 webservices: Make XML-RPC backwards compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
cameorn1730 committed May 17, 2016
1 parent 65cbefc commit ad1bfe6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions webservice/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ This information is intended for authors of webservices, not people writing webs
on the string returned by the getMessage() method of the thrown exception.
* With Zend_SOAP dropped, moodle_zend_soap_server is now also deprecated.
* As mentioned in the 2.9 notes, deprecated web service functions have now been removed.
* Since our new XML-RPC server implementation does not support introspection, it is critical that all clients send
parameters in the correct order.

=== 3.0 ===

Expand Down
2 changes: 2 additions & 0 deletions webservice/xmlrpc/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public function call($functionname, $params = array()) {
);

// Encode the request.
// See MDL-53962 - needed for backwards compatibility on <= 3.0
$params = array_values($params);
$request = xmlrpc_encode_request($functionname, $params, $outputoptions);

// Set the headers.
Expand Down
13 changes: 6 additions & 7 deletions webservice/xmlrpc/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ protected function parse_request() {

// Decode the request to get the decoded parameters and the name of the method to be called.
$decodedparams = xmlrpc_decode_request($rawpostdata, $methodname);
$methodinfo = external_api::external_function_info($methodname);
$methodparams = array_keys($methodinfo->parameters_desc->keys);

// Add the decoded parameters to the methodvariables array.
if (is_array($decodedparams)) {
foreach ($decodedparams as $param) {
// Check if decoded param is an associative array.
if (is_array($param) && array_keys($param) !== range(0, count($param) - 1)) {
$methodvariables = array_merge($methodvariables, $param);
} else {
$methodvariables[] = $param;
}
foreach ($decodedparams as $index => $param) {
// See MDL-53962 - XML-RPC requests will usually be sent as an array (as in, one with indicies).
// We need to use a bit of "magic" to add the correct index back. Zend used to do this for us.
$methodvariables[$methodparams[$index]] = $param;
}
}

Expand Down

0 comments on commit ad1bfe6

Please sign in to comment.