Open isacsonk opened 10 years ago
5) enter one question and change something in the question, the answer statements or the responses, save changes --> the responses the student made are lost
Before the question was changed (you can get to the question by clicking on the test and then click in the left navigation on Results and then Responses):
The image with the radio buttons is ok. But the History of the question doesn't show, what the student actually responded. It should save the responses of the student as written in red above. (see also #10).
After the question was changed as a teacher (for example: click on review attempt and then edit the question):
This should not happen. Even if a teacher changes a question, the responses should persist as in the first screenshot and the history of the question should make sense, that is, it should be clear, which responses where chosen by the student.
Even though the backup was made before the question was changed, it seems that not all information is stored in the backup, since this very question doesn't have any responses saved anymore, when the backup is restored.
OK I think this is happening because when you restore into an existing course and one of the questions in the pre-existing course has been edited then a new question will created to "contain" the one from the backup. Then the attempts are transferred correctly, but the IDs to the new rows/columns are not mapped properly: in the table question_attempt_step_data.
Backup and restore should work with all options: when just backuping and restoring the test and when backuping and restoring the whole course. To be able to restore a course or a test with results of the students included you need to have manager or admin rights.
It should also work whether you restore into a new course or into the old.
So the good news is that the backup contains all the data. The problem lies with the restore process of matrix attempts, which links old attempts to new questions. I've just spent some four hours looking for exactly where this happens (so that I can fix it) but I couldn't find it yet. I'll try some more tomorrow but I'm not very optimistic that I can pull it off in the time allotted.
So I have a solution, which according to my preliminary testing works. The problem with this solution is that it uses a very ugly feature of PHP (global variables) to achieve something that I couldn't figure out how to do using the "moodle" way. In general things should work, but if you ever want to publish this plugin to the greater community you will need to avoid using global variables. As a clue to the next person working on this: figure out how to make $this->get_mappingid('row', $oldrowid) work. For some reason now it doesn't, despite $this->set_mapping('row', $oldid, $newitemid); being in function process_row($data) {}.
The fix seems to work. Not too sure why the fix makes use of $GLOBALS. Need to be further tested.
Has this fix been added to the main release yet? I'm unable to restore matrix questions currently.
Has been partially solved in commit https://github.com/ndunand/moodle-qtype_matrix/commit/bbaabda02343f38c42daa139e05f3101c034704e.
The downside is that it only works in 3.x versions. When testing with Moodle 4.x I get the following error:
Notice: Undefined offset: 21 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php on line 206
Notice: Undefined offset: 18 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php on line 206
Notice: Undefined offset: 19 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php at line 206
Notice: Undefined offset: 20 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php at line 206
Notice: Undefined offset: 21 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php at line 180
Notice: Undefined offset: 18 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php at line 180
Notice: Undefined offset: 19 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php at line 180
Notice: Undefined offset: 20 in /var/www/html/question/type/matrix/backup/moodle2/restore_qtype_matrix_plugin.class.php at line 180
This means that the $GLOBALS are not filled with the new mapping values. If this is the case, we know that some or all of the process_xyz functions are not always called.
I assume that during recovery, it also checks to see if the question is already mapped. If so, the process_xyz function is not called again because it assumes it is not needed. Then it simply tries to recover the answers and we get our error.
The best way would be to avoid using globals/statics for mappings and use setMapping/getMapping instead. The question type kprime for example works.
How to reproduce
requirement
Backup and restore a course with a test with kprime should not result in loss of data (responses). All of the information needed for a restore of a solved kprime question should be saved in the backup.
Result of Kprime questions should make sense, as to that responses made are saved as selection of the radio buttons and also as text. see also Issue #10.