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

Wrong "ul" prefix in get_users_by_capability() causes queries to break sometimes...

    XMLWordPrintable

    Details

    • Database:
      Any
    • Affected Branches:
      MOODLE_19_STABLE, MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_19_STABLE

      Description

      I was looking to CONTRIB-317 ... and, after looking the first error reported there:

      Unknown table 'ul' in field list

      SELECT u.*, ul.timeaccess as lastaccess FROM tmdl_user u JOIN (SELECT DISTINCT ssra.userid FROM tmdl_role_assignments ssra WHERE ssra.contextid IN (1,4,5) AND ssra.roleid IN (3,8) ) ra ON ra.userid = u.id WHERE u.deleted = 0 ORDER BY ul.timeaccess DESC

      line 686 of lib/dmllib.php: call to debugging()
      line 944 of lib/dmllib.php: call to get_recordset_sql()
      line 4576 of lib/accesslib.php: call to get_records_sql()
      line 749 of lib/deprecatedlib.php: call to get_users_by_capability()
      line 324 of mod/certificate/lib.php: call to get_course_teachers()
      line 570 of mod/certificate/lib.php: call to certificate_email_teachers()
      line 112 of mod/certificate/view.php: call to certificate_issue()

      I've taken a look to get_users_by_capability()

      And it seems that the ul.timeaccess is added both to the select list and the order by clause, while the ul alias hasn't been defined at all in the query.

      I really don't know what's the solution for this (adding a table in the join above...) but seems clearly that sometimes it can generate wrong SQL.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dougiamas Martin Dougiamas
              Reporter:
              stronk7 Eloy Lafuente (stronk7)
              Tester:
              Dan Poltawski
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                15/May/08