MDL-53962 webservices: Make XML-RPC backwards compatible

This commit is contained in:
Cameron Ball 2016-05-17 00:39:05 +08:00
parent 65cbefc403
commit ad1bfe6a9c
3 changed files with 10 additions and 7 deletions

View file

@ -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. on the string returned by the getMessage() method of the thrown exception.
* With Zend_SOAP dropped, moodle_zend_soap_server is now also deprecated. * 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. * 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 === === 3.0 ===

View file

@ -79,6 +79,8 @@ class webservice_xmlrpc_client {
); );
// Encode the request. // Encode the request.
// See MDL-53962 - needed for backwards compatibility on <= 3.0
$params = array_values($params);
$request = xmlrpc_encode_request($functionname, $params, $outputoptions); $request = xmlrpc_encode_request($functionname, $params, $outputoptions);
// Set the headers. // Set the headers.

View file

@ -78,16 +78,15 @@ class webservice_xmlrpc_server extends webservice_base_server {
// Decode the request to get the decoded parameters and the name of the method to be called. // Decode the request to get the decoded parameters and the name of the method to be called.
$decodedparams = xmlrpc_decode_request($rawpostdata, $methodname); $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. // Add the decoded parameters to the methodvariables array.
if (is_array($decodedparams)) { if (is_array($decodedparams)) {
foreach ($decodedparams as $param) { foreach ($decodedparams as $index => $param) {
// Check if decoded param is an associative array. // See MDL-53962 - XML-RPC requests will usually be sent as an array (as in, one with indicies).
if (is_array($param) && array_keys($param) !== range(0, count($param) - 1)) { // We need to use a bit of "magic" to add the correct index back. Zend used to do this for us.
$methodvariables = array_merge($methodvariables, $param); $methodvariables[$methodparams[$index]] = $param;
} else {
$methodvariables[] = $param;
}
} }
} }