mdjnelson / moodle-mod_customcert

Enables the creation of dynamically generated certificates with complete customisation via the web browser.
https://moodle.org/plugins/mod_customcert
GNU General Public License v3.0
91 stars 158 forks source link

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

Open VOOM108 opened 3 years ago

VOOM108 commented 3 years ago

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?

mdjnelson commented 3 years ago

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

VOOM108 commented 3 years ago

No, everything else seems to work....

mdjnelson commented 3 years ago

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?

VOOM108 commented 3 years ago

3.9.1 on Moodle 3.9.8

mdjnelson commented 2 years ago

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.

VOOM108 commented 2 years ago

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

mdjnelson commented 2 years ago

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 .. ?

VOOM108 commented 2 years ago

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....

mdjnelson commented 2 years ago

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.

VOOM108 commented 2 years ago

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

mdjnelson commented 2 years ago
['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.

VOOM108 commented 2 years ago

[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 )

mdjnelson commented 2 years ago

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

VOOM108 commented 2 years ago

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

) `

mdjnelson commented 2 years ago

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?

VOOM108 commented 2 years ago

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...

mdjnelson commented 2 years ago

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?

VOOM108 commented 2 years ago

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 commented 2 years ago

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....

mdjnelson commented 2 years ago

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

VOOM108 commented 2 years ago

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.