-
Bug
-
Resolution: Fixed
-
Minor
-
3.0, 3.0.1
-
PostgreSQL
-
MOODLE_30_STABLE
-
MOODLE_31_STABLE
-
MDL_52574_master
-
get_role_users(), without a $sort argument, fails on PostgreSQL when requesting fields that are absent from the default value for the $sort argument.
The default value for the $sort argument (when it is missing from the function call) is returned by the function users_order_by_sql('u') and it is 'u.lastname,u.firstname,u.id'. If any of these fields are missing from the $fields argument for the get_role_users() function call then a dmlreadexception is thrown.
You can paste the following code snipped in a file located in the moodle root directory to replicate the issue:
<?php
|
define('CLI_SCRIPT', true); |
|
require(__DIR__ . '/config.php'); |
require_once($CFG->libdir . '/moodlelib.php'); |
require_once($CFG->libdir . '/coursecatlib.php'); |
|
$courses = get_courses(); |
// Get the context from the first course in the list, the actual courses doesn't matter.
|
$firstcoursecontext = context_course::instance(reset($courses)->id); |
$roles = get_all_roles(); |
// Get the role id for the first role in the role list, the actual role doesn't matter.
|
$firstroleid = reset($roles)->id; |
$userfields = 'u.firstname'; |
|
$usersassigned = get_role_users($firstroleid, $firstcoursecontext, false, $userfields); |
echo "no exception thrown\n"; |
The snippet should print 'no exception thrown', instead I get a dmlreadexception.
I am using PostgreSQL version 9.2.14 on centos7.
- caused a regression
-
MDL-55423 get_role_users() does not recognise "u.*" and "u.fieldname AS fieldalias" in the fields list (regression from MDL-52574)
-
- Closed
-