Commit 153b14fc authored by Robert Lyon's avatar Robert Lyon
Browse files

Bug 1713806: Handle Webservice error strings with/without args



By checking if extra args are expected

behatnotneeded

Change-Id: I64d4b0bc55323be71fcf11c4455e19190d511ea3
Signed-off-by: default avatarRobert Lyon <robertl@catalyst.net.nz>
parent aa12e3be
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -300,10 +300,20 @@ function string_exists($identifier, $section = 'mahara') {
    return $string !== '[[' . $identifier . '/' . $section . ']]';
}

function _return_string_unchanged($string, $args, $lang='en.utf8') {
function _return_string_unchanged($string, $args=array(), $lang='en.utf8') {
    return $string;
}

/**
 * Find out the number of expected arguments if $identifier for get_string() is
 * passed in by a variable. Eg in webservices error handling.
 */
function count_string_args($identifier, $section = 'mahara') {
    $string = get_string_location($identifier, $section, array(), '_return_string_unchanged');
    preg_match_all('/[^\%]\%[^\%]/', $string, $matches);
    return count($matches[0]);
}

function get_string($identifier, $section='mahara') {

    $variables = func_get_args();
+8 −2
Original line number Diff line number Diff line
@@ -2259,13 +2259,19 @@ class WebserviceException extends MaharaException {
        $this->errorcode = rtrim($errorcode, '0123456789');

        if (string_exists($errorcode, 'auth.webservice')) {
            $count = count_string_args($errorcode, 'auth.webservice');
            if ($count) {
                $message = get_string($errorcode, 'auth.webservice', $debuginfo);
            }
            else {
                $message = get_string($errorcode, 'auth.webservice');
            }
        }
        else {
            $message = $errorcode;
        }

        if ($debuginfo) {
        if ($debuginfo && !$count) {
            $message .= ' : ' . $debuginfo;
        }