Invalid parameter in core_get_string call

Invalid parameter in core_get_string call

by Bill Antonia -
Number of replies: 3

When calling:

 http://server/moodle/webservice/rest/server.php?wstoken=averylongstringforatoken&wsfunction=core_get_string&stringid=actionchoice

I get an invalid parameter error. In theory the rest of the possible parameters should use the defaults, the only required parameter according to the API is the stringid. The above value for string id has been taken from the lang/en/moodle.php file, the component defaulting to "moodle" and the lang defaulting to "en".

Are there any issues with this call? Any clues?

Average of ratings: -
In reply to Bill Antonia

Re: Invalid parameter in core_get_string call

by Bill Antonia -

Discovered if you comment out line 90 in moodle/lib/external/externallib.php which is:

'lang' => new external_value(PARAM_LANG, 'lang', VALUE_DEFAULT, null),

Then this call works.

I'm using Moodle 2.6

In reply to Bill Antonia

Re: Invalid parameter in core_get_string call

by Bill Antonia -
By the way, this call did not work even though I did try to pass lang=en as a parameter, the parameter validation code does not function correctly as it does not appear to be passed to the routine to be checked.
In reply to Bill Antonia

Re: Invalid parameter in core_get_string call

by David Balme -

I discovered this issue as well.

The problem is a mismatch between the external function parameters returned by get_string_parameters() and the actual method signature of get_string:  get_string does not have a lang parameter.  However the definition below specifies one (see below).

    public static function get_string_parameters() {
        return new external_function_parameters(
            array('stringid' => new external_value(PARAM_STRINGID, 'string identifier'),
                  'component' => new external_value(PARAM_COMPONENT,'component', VALUE_DEFAULT, 'moodle'),
                  'lang' => new external_value(PARAM_LANG, 'lang', VALUE_DEFAULT, null),
                  'stringparams' => new external_multiple_structure (
                      new external_single_structure(array(
                          'name' => new external_value(PARAM_ALPHANUMEXT, 'param name
                            - if the string expect only one $a parameter then don\'t send this field, just send the value.', VALUE_OPTIONAL),
                          'value' => new external_value(PARAM_TEXT,'param value'))),
                          'the definition of a string param (i.e. {$a->name})', VALUE_DEFAULT, array()
                   )
            )
        );
    }

I will do as Bill suggested, ie comment out the 'lang' parameter definition from the get_string web service call.  However that only addresses this issue temporarily ( and only for me .. and Bill smile ).

Has this been resolved in a later version of Moodle?  I too am using version 2.6.

I'm not a PHP developer (I spend most of my time in java) and I'm more used to stronger typed languages and so not at all used to this type of scenario.  Nonetheless I have a suggestion that could help guard against this parameter/mismatch and create a more tightly checked system.

Is it possible to write a unit (or integration) test that iterates through all the externally defined functions (SELECT * FROM mdl_external_functions) and validates that all the function parameter definitions actually match up with the function signatures.  Not being a PHP dev I'm not sure if you can extract that sort of meta data.  Anyhow, just a thought.  No idea if this is doable.  smile