ndunand / moodle-qtype_matrix

Source code of https://moodle.org/plugins/qtype_matrix
2 stars 10 forks source link

Backup/Restore Kprime doesn't work #19

Open isacsonk opened 10 years ago

isacsonk commented 10 years ago

How to reproduce

  1. Create a test with kprime questions
  2. Solve the test as a student
  3. log in as teacher and go to the test
  4. as admin backup the course with the test and download it
  5. as a teacher go back to the test, in the results review attempt and go to one question and change something in the question, the answer statements or the responses, save changes --> the responses the student made are lost (see also #18)
  6. login as Admin and restore the backup you made into the same course --> although the backup was made before the change in one question, the results of that very question are lost. (It doesn't matter whether you backuped the whole course or just the test, the results are lost) --> Also the response found in the table if you navigate to result --> responses should make sense Now it says something like "a : Richtig / a : Falsch / d : Richtig / d : Falsch / b : Richtig / b : Falsch / c : Richtig / c : Falsch" for a question, which was responded to correctly and where a, b, c and d should be marked as "Richtig" (see also screenshot in comment)

    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.

isacsonk commented 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):

resultsresponses 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): aftereditingasolvedquestion

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.

ghost commented 10 years ago

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.

isacsonk commented 10 years ago

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.

isacsonk commented 10 years ago

It should also work whether you restore into a new course or into the old.

ghost commented 10 years ago

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.

ghost commented 10 years ago

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) {}.

laurentopprecht commented 9 years ago

The fix seems to work. Not too sure why the fix makes use of $GLOBALS. Need to be further tested.

systemnova commented 6 years ago

Has this fix been added to the main release yet? I'm unable to restore matrix questions currently.

cli-ish commented 1 year ago

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.