Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-52574

get_role_users() fails with specific fields on PostgreSQL

    XMLWordPrintable

    Details

    • Database:
      PostgreSQL
    • Testing Instructions:
      Hide

      (difficulty: medium, requires a Moodle installation with PHPUnit installed and PostgreSQL)
      1. Navigate to the Moodle root directory
      2. From a terminal execute

      php vendor/bin/phpunit lib/tests/accesslib_test.php

      The test should pass if the patch works correctly.

      Show
      (difficulty: medium, requires a Moodle installation with PHPUnit installed and PostgreSQL) 1. Navigate to the Moodle root directory 2. From a terminal execute php vendor/bin/phpunit lib/tests/accesslib_test.php The test should pass if the patch works correctly.
    • Affected Branches:
      MOODLE_30_STABLE
    • Fixed Branches:
      MOODLE_31_STABLE
    • Pull Master Branch:
      MDL_52574_master

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  23/May/16