Skip to content

'Forum posts' in My Courses Error #271

Open
@djarran

Description

@djarran

Description

Users who have recent forum posts are receiving an error in their "My courses" overview section with dmlreadexception. The full error message (below) is attempting to find the forum discussions table for the hsuforum plugin despite it not being installed:

dmlreadexception 
ERROR:  relation "mdl_hsuforum_discussions" does not exist
LINE 2:                               FROM mdl_hsuforum_discussions
                                           ^
SELECT id, groupid
                              FROM mdl_hsuforum_discussions
                             WHERE id IN ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10)
[array (
  ....
)]
Error code: dmlreadexception 
* line 494 of /lib/dml/moodle_database.php: dml_read_exception thrown
* line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
* line 341 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->read_slave_query_end()
* line 1027 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
* line 1987 of /theme/snap/classes/local.php: call to pgsql_native_moodle_database->get_records_sql()
* line 2008 of /theme/snap/classes/local.php: call to theme_snap\local::get_groups_ids()
* line 2443 of /theme/snap/classes/local.php: call to theme_snap\local::recent_forum_activity_data()
* line 98 of /theme/snap/classes/webservice/ws_feed.php: call to theme_snap\local::get_feed()
* line ? of unknownfile: call to theme_snap\webservice\ws_feed::service()
* line 262 of /lib/externallib.php: call to call_user_func_array()
* line 81 of /lib/ajax/service.php: call to external_api::call_external_function()

Steps to Reproduce

  1. Setup Moodle 4.1 environment (git clone -b MOODLE_401_STABLE git@github.com:moodle/moodle.git forum-error)
  2. Create small test course at admin/tool/generator/maketestcourse.php. This should also create a forum.
  3. Install theme_snap, upgrade Moodle
  4. Click My Course button
  5. Observe error
    image

Proposed Solution

The error is occuring in the get_groups_ids function in classes/local.php as described in the error in the following conditional starting in line 1970

        if (!get_config('hsuforum')) {
            $groupsid['hsuforum'] = [];
        } else {
            // SQL for hsuforums.
            $sqlhsuforum = "SELECT id, groupid
                              FROM {hsuforum_discussions}
                             WHERE id $insql";

            $groupsid['hsuforum'] = $DB->get_records_sql($sqlhsuforum, $params);
        }
        return $groupsid;
  

get_config('hsuforum') returns an empty object (even though it should return false) if the plugin specified doesn't exist, and since an empty object is considered true, this conditional evaluates to false and the SQL is executed. Changing hsuforum to a random string shows the same behaviour.

Checking if what is returned is an empty object (or false, as that is what get_config() should return) as below solves this issue.

if (get_config('hsuforum') == new stdClass() || !get_config('hsuforum')) {

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions