Activity completion bug...

Activity completion bug...

by Arnould Olivier -
Number of replies: 2
Hello,
I'm using moodle during 8 years. I've made lot of plugins changes and upgrades.

Today, I'm using the 4.2 version. 

I have a problem (before this last upgrade) with activity completion.
The message is the next : 

"dmlreadexception
Erreur de lecture de la base de données
File  /lib/dml/moodle_database.php
Line  494
Unknown column 'cm.completionpassgrade' in 'where clause'
SELECT DISTINCT c.id AS course,
                                cr.id AS criteriaid,
                                ra.userid AS userid,
                                mc.timemodified AS timecompleted
                  FROM doksvtal_course_completion_criteria cr
            INNER JOIN doksvtal_course c ON cr.course = c.id
            INNER JOIN doksvtal_context con ON con.instanceid = c.id
            INNER JOIN doksvtal_role_assignments ra ON ra.contextid = con.id
            INNER JOIN doksvtal_course_modules cm ON cm.id = cr.moduleinstance
            INNER JOIN doksvtal_course_modules_completion mc ON mc.coursemoduleid = cr.moduleinstance AND mc.userid = ra.userid
             LEFT JOIN doksvtal_course_completion_crit_compl cc ON cc.criteriaid = cr.id AND cc.userid = ra.userid
                 WHERE cr.criteriatype = ?
                       AND con.contextlevel = ?
                       AND c.enablecompletion = 1
                       AND cc.id IS NULL
                       AND (
                            mc.completionstate = ?
                            OR (cm.completionpassgrade = 1 AND mc.completionstate = ?)
                            OR (cm.completionpassgrade = 0 AND (mc.completionstate = ?
                                                                OR mc.completionstate = ?))
                            ) AND c.id = ? AND ra.userid = ?
[array (
  0 => 4,
  1 => 50,
  2 => 1,
  3 => 2,
  4 => 2,
  5 => 3,
  6 => '527',
  7 => '2',
)]
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 1375 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
* line 1679 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
* line 173 of /completion/classes/api.php: call to moodle_database->get_record_sql()
* line 1325 of /lib/completionlib.php: call to core_completion\api::mark_course_completions_activity_criteria()
* line 679 of /lib/completionlib.php: call to completion_info->internal_set_data()
* line 100 of /completion/classes/external.php: call to completion_info->update_state()
* line ? of unknownfile: call to core_completion_external::update_activity_completion_status_manually()
* line 251 of /lib/external/classes/external_api.php: call to call_user_func_array()
* line 83 of /lib/ajax/service.php: call to core_external\external_api::call_external_function()"
After many tests and researches, I really don't know how I can solve it. 

Maybe somebody have the solution ?

Thanks in advance !
Long life to moodle and thanks to the community.
Oliver
Average of ratings: -
In reply to Arnould Olivier

Re: Activity completion bug...

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Check the columns in the doksvtal_course_modules table, is completionpassgrade present? For example:

DESC doksvtal_course_modules;
+---------------------------+--------------+------+-----+---------+----------------+
| Field                     | Type         | Null | Key | Default | Extra          |
+---------------------------+--------------+------+-----+---------+----------------+
  ⋮
| completionexpected        | bigint(10)   | NO   |     | 0       |                |
| completionpassgrade       | tinyint(1)   | NO   |     | 0       |                |
| showdescription           | tinyint(1)   | NO   |     | 0       |                |
  ⋮

Your error indicates this is missing. This column was added in Moodle 4.0 so it should have been added during the upgrade. You could add it with the following statement (backup your database first):

ALTER TABLE doksvtal_course_modules
  ADD COLUMN completionpassgrade TINYINT(1) NOT NULL DEFAULT 0
    AFTER completionexpected;

There have been two other columns added to this table since Moodle 3.11.0: downloadcontent and lang, are you missing these too? I've attached the CREATE TABLE statement for this table in case you need the definitions for other columns.

If one table is missing columns it suggests the upgrade script did not complete successfully, so other tables may be affected. This page describes how to verify the database schema.

Average of ratings: Useful (2)
In reply to Leon Stringer

Re: Activity completion bug...

by Arnould Olivier -
Thanks a lot !
Usually I don't dare use the forum because I don't want wasted community time about noob questions (I'm french and, as you can expect... .My english is awful).
I'm just a biology teacher who love Moodle. It's a great way for personal learnings.
This kind of adventices are gold for me.
Regards,