moodle-mod_customcert icon indicating copy to clipboard operation
moodle-mod_customcert copied to clipboard

Error thrown attempting to get module context for grade items that are external

Open VOOM108 opened this issue 3 years ago • 21 comments

Update from Moodle 3.5 to 3.9 - Customcerts work except in one course (at least, but not in all of them), where we get this error:

Ungültige Kursmodul-ID
Weitere Informationen über diesen Fehler

×Debug-Info:  SELECT id,course FROM {course_modules} WHERE id IS NULL
[array (
)]
Error code: invalidcoursemodule
×Stack trace: 
line 1599 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
line 1575 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
line 7305 of /lib/accesslib.php: call to moodle_database->get_record()
line 477 of /mod/customcert/classes/element_helper.php: call to context_module::instance()
line 102 of /mod/customcert/element/date/classes/element.php: call to mod_customcert\element_helper::get_grade_items()
line 68 of /mod/customcert/classes/edit_element_form.php: call to customcertelement_date\element->render_form_elements()
line 214 of /lib/formslib.php: call to mod_customcert\edit_element_form->definition()
line 79 of /mod/customcert/edit_element.php: call to moodleform->__construct()
×Ausgabepuffer:  <br /> <b>Notice</b>: Trying to get property 'id' of non-object in <b>/srv/www/develop/public/releases/test/vendor/moodle/moodle/mod/customcert/classes/element_helper.php</b> on line <b>477</b><br />

This happens whenever in that course a date or grade item is touched. Edited, newly added etc. Also with completely new customcert activities added. Anything we can do to get that fixed?

VOOM108 avatar Sep 02 '21 10:09 VOOM108

This is bizarre. Are there issues with any of the other activities?

mdjnelson avatar Sep 13 '21 20:09 mdjnelson

No, everything else seems to work....

VOOM108 avatar Sep 13 '21 20:09 VOOM108

Basically what it is trying to do is get the date for a grade item that doesn't seem to exist. What version of the plugin are you using?

mdjnelson avatar Sep 13 '21 22:09 mdjnelson

3.9.1 on Moodle 3.9.8

VOOM108 avatar Sep 13 '21 22:09 VOOM108

Are you able to tell me the value of $gi on line 477 of /mod/customcert/classes/element_helper.php when this error occurs? This may require some developer help.

mdjnelson avatar Sep 28 '21 12:09 mdjnelson

How would I get this value? In this environment I have no access to the cli, but I could forward that...

VOOM108 avatar Sep 28 '21 13:09 VOOM108

Unfortunately it would require a developer to output the value of that object when the failure occurs. Are you self-hosting or using a partner or .. ?

mdjnelson avatar Sep 28 '21 13:09 mdjnelson

We are in the process of moving the platform, there is an internal server-admin I could contact. He is not familiar with Moodle though, so it would help to relay a more precise info to him.... I just remembered I even do have access to the server via SSH, no root privileges, though....

VOOM108 avatar Sep 28 '21 14:09 VOOM108

This is a crude way of doing it but you could do print_object($gi); in the if statement on line 477 of /mod/customcert/classes/element_helper.php when this error occurs. Then once you have those details remove the print_object line and put the file back to how it was and then paste those details here.

mdjnelson avatar Sep 28 '21 14:09 mdjnelson

That results in over 12000 lines of output into the page - do you need all of that?

VOOM108 avatar Sep 28 '21 15:09 VOOM108

['id', 'courseid', 'categoryid', 'itemname', 'itemtype', 'itemmodule', 'iteminstance',
'itemnumber', 'iteminfo', 'idnumber', 'calculation', 'gradetype', 'grademax', 'grademin',
'scaleid', 'outcomeid', 'gradepass', 'multfactor', 'plusfactor', 'aggregationcoef',
'aggregationcoef2', 'sortorder', 'display', 'decimals', 'hidden', 'locked', 'locktime',
'needsupdate', 'weightoverride', 'timecreated', 'timemodified'];

I think just these fields should be sufficient. :) They should be at the top of the output.

mdjnelson avatar Sep 28 '21 23:09 mdjnelson

[table] => grade_items [required_fields] => Array ( [0] => id [1] => courseid [2] => categoryid [3] => itemname [4] => itemtype [5] => itemmodule [6] => iteminstance [7] => itemnumber [8] => iteminfo [9] => idnumber [10] => calculation [11] => gradetype [12] => grademax [13] => grademin [14] => scaleid [15] => outcomeid [16] => gradepass [17] => multfactor [18] => plusfactor [19] => aggregationcoef [20] => aggregationcoef2 [21] => sortorder [22] => display [23] => decimals [24] => hidden [25] => locked [26] => locktime [27] => needsupdate [28] => weightoverride [29] => timecreated [30] => timemodified )

VOOM108 avatar Sep 29 '21 00:09 VOOM108

Getting close. :) I just need the value of those fields.

mdjnelson avatar Sep 29 '21 00:09 mdjnelson

The 12000 lines are a repetition of the above followed by different values each. This is the first:

`
[courseid] => 77 [categoryid] => 47 [item_category] => [parent_category] => [itemname] => Die bestbezahlten Berufe [itemtype] => mod [itemmodule] => hvp [iteminstance] => 2511 [itemnumber] => 0 [iteminfo] => [idnumber] => [calculation] => [calculation_normalized] => [formula] => [gradetype] => 1 [grademax] => 10.00000 [grademin] => 0.00000 [scaleid] => [scale] => [outcomeid] => [outcome] => [gradepass] => 0.00000 [multfactor] => 1.00000 [plusfactor] => 0.00000 [aggregationcoef] => 0.00000 [aggregationcoef2] => 0.00000 [sortorder] => 3 [display] => 0 [decimals] => [locked] => 0 [locktime] => 0 [needsupdate] => 0 [weightoverride] => 0 [dependson_cache] => [markasoverriddenwhengraded] => 1 [optional_fields] => Array ( )

[id] => 2617
[timecreated] => 1529417909
[timemodified] => 1582728732
[hidden] => 0

) `

VOOM108 avatar Sep 29 '21 09:09 VOOM108

Hm, seems it's an issue pointing to the hvp plugin, which is not a core plugin. I am wondering if perhaps it did not clean up after itself when deleted. Have you run cron?

mdjnelson avatar Oct 18 '21 13:10 mdjnelson

H5P was never deleted, as it is essential for the content of the course. The test that is the sole basis for the certificate is a regular Moodle quiz, though.... So I wonder why H5P would have anything to do with the date element for the certificates....

Cron is running regularly...

VOOM108 avatar Oct 18 '21 13:10 VOOM108

Well something weird is going on because it is attempting to get the value for a hvp object (see [itemmodule] => hvp above). So, it isn't looking for the quiz, but for a hvp activity and can't find it and then explodes. I do not understand why this is happening though. Is this a course from a backup/restore?

mdjnelson avatar Oct 18 '21 15:10 mdjnelson

No, we had a big platform that had to be divided into two parts. So the whole thing was cloned, in order to keep all the IDs...

I will check if there is any relation to an hvp activity, but in the end what was purged from each new platform was ever in any relation to the other half...

VOOM108 avatar Oct 18 '21 15:10 VOOM108

I checked, hvp has nothing to do with the certificate... zertifikatB1

the upper activity is the quiz, the lower one the certificate with the restriction of passing the quiz. That's all....

VOOM108 avatar Oct 18 '21 15:10 VOOM108

I would go and re-edit the date element and click 'Save' again and see if that fixes it.

mdjnelson avatar Oct 19 '21 07:10 mdjnelson

That is the first thing we tried (check my wording in the first post of this thread). You can't add a new date element, or edit an existing one - that already throws the error. I even copied a certificate from a different course that works there (via Sharing Cart plugin) and tried to change it into the one needed... Same thing: error when trying to open it, editing it is possible but not doing anything with a date element.

VOOM108 avatar Oct 19 '21 09:10 VOOM108