Getting moodle version info, no admin access

Viewed 26785

Is there a way to obtain version info for a moodle site using only "teacher" level access? It seems as though this ability was removed in versions 1.9.7 and above. I'm trying to automate the process of uploading tests and having the version info would be rather handy.

7 Answers

If you don't even have an account on the instance, you may still be able to find out the version. Any authentication errors in the API will return an error message of the form:

[{
   "error":true,
   "exception":{
       "message":"Course or activity not accessible.",
       "errorcode":"requireloginerror",
       "link":"https:\/\/moodle.example.com\/",
       "moreinfourl":"http:\/\/docs.moodle.org\/36\/en\/error\/moodle\/requireloginerror"
   }
}]

And the moreinfourl contains an approximate version number (in this case 3.6). For me, this page was requested when I visited the login page for the instance - a POST request to

https://moodle.example.com/lib/ajax/service.php?sesskey=JQrdIcgMn4&info=core_fetch_notifications

My helper function here: https://gist.github.com/tigusigalpa/af051a9112512b1b0369572b5dbea2fd

function checkMoodleVersion($version, $checkfor = 'all', $compare = '<=') {
    global $CFG;

    $versions = [
        '3.1' => [
            'version' => '2016052300',
            'release' => '3.1'
        ],
        '3.2' => [
            'version' => '2016120500',
            'release' => '3.2'
        ],
        '3.3' => [
            'version' => '2017051500',
            'release' => '3.3'
        ],
        '3.4' => [
            'version' => '2017111300',
            'release' => '3.4'
        ],
        '3.5' => [
            'version' => '2018051700',
            'release' => '3.5'
        ],
        '3.6' => [
            'version' => '2018120300',
            'release' => '3.6'
        ]
    ];
    switch ($checkfor) {
        case 'all':
            if (isset($versions[$version]['version'])) {
                return version_compare($versions[$version]['version'], $CFG->version, $compare) &&
                    version_compare($version, $CFG->release, $compare);
            }
            break;
        case 'version':
        case 'release':
            if (isset($versions[$version][$checkfor])) {
                return version_compare($versions[$version][$checkfor], $CFG->$checkfor, $compare);
            }
            break;
    }
    return false;

}

Related