Closed matthewhilton closed 3 months ago
This error will happen at least with elements of types "date" and "grade". The reason for this is that both of these store gradeitem in the data JSON. The select dropdown for the gradeitems can contain activities (which have integer IDs), but also other "gradeitems" (which are written as "gradeitem": "gradeitem:XYZ", where XYZ is an integer).
Backups correctly stores the JSON, but then the restore process for "date" and "grade" doesn't do anything to extract the integer from that string, see https://github.com/mdjnelson/moodle-mod_customcert/blob/22a84c5703e3e26d06d3ce5a1568178206e97c32/element/date/classes/element.php#L326-L334 (for date) and https://github.com/mdjnelson/moodle-mod_customcert/blob/22a84c5703e3e26d06d3ce5a1568178206e97c32/element/grade/classes/element.php#L193-L201 (for grade).
The functions assume that $gradeitem->gradeitem is an integer, which "gradeitem:XYZ" is not. Before looking for the appropriate ID in the backup table, it should extract the integer.
~What does "gradeitem:XYZ" represent? Is the gradeitem something that's even restored with a course or a customcert activity? Or is that something that should be ignored when restoring or even already when backing up?~
I've just looked at the backup file of the course that couldn't be restored, the grade items are backed up, I've found the item with ID XYZ. So the restore probably only needs to respect that the $gradeitem->gradeitem could contain the string, check for it, and if it finds it, act accordingly.
Anyone willing to do a PR? :)
Also, thanks for your detailed research into this.
This took me down a rabbit hole and ended up being way more work than I thought. Fortunately it is done, I think. Pushing fix soon.
Fixed. Pushed to 4.2 and 4.1.
Eh, seems I already knew about this but did not get round to fixing it, whoops. See https://github.com/mdjnelson/moodle-mod_customcert/issues/347.
The
date
element has the ability to link a grade item, e.g. show date when grade item was graded.The way this is stored is in the json as something like:
{ "dateitem":"gradeitem:12345" ...}
However when you attempt to restore a customcert instance, it gives an error
This is because itemid is an integer, but its trying to search for a string.
Happens when using backup/restore or course copy
This comes from this line https://github.com/mdjnelson/moodle-mod_customcert/blob/c3942c3b756df0b2a894c6b041be3799c0d749bc/element/date/classes/element.php#L291
Likely related to #149