ndunand / moodle-mod_choicegroup

Moodle "Group Choice" plugin
https://moodle.org/plugins/mod_choicegroup
35 stars 63 forks source link

Group Choice restore from Recycle Bin loses group settings #163

Closed ebithell closed 2 years ago

ebithell commented 2 years ago

Seen in Moodle 3.5.18 (mod_groupchoice version 1.15), 3.9.11 (version 1.33) and 3.11.6 (version 1.33).

When a Group Choice activity is restored from the Course Recycle Bin, the allocated Groups for the activity are not restored.

Steps to reproduce:

  1. Create a group within a course (Group A)
  2. Add a Group Choice activity
  3. Select Group A from the activity's available groups and add it to the selected groups
  4. Save the activity
  5. Delete the Group Choice activity; wait for the cron to run and the activity to appear in the Recycle Bin
  6. Restore the activity from the Recycle Bin

Expected result:

Actual result:

Course backup & restore operate as expected but activity duplication also loses its groups setting, with the same PHP messages.

(description of cause and proposed solution with patch following in comments)

ebithell commented 2 years ago

The issue comes from line 73 of mod/choicegroup/backup/moodle2/restore_choicegroup_stepslib.php: $data->groupid = $this->get_mappingid('group', $data->groupid); If the backup package contains the records for the course groups, this returns an appropriate value of the groupid. This applies to a full course backup. The group references are not included in an activity-level backup (Recycle Bin or activity duplication), so the mappingid return value is false and a zero-valued groupid record is written to mdl_choicegroup_options.

Expected behaviour for different scenarios would be:

Logically the restore process should:

  1. Check if the group already exists in the course. Restore the option as-is if it does.
  2. If it does not exist, check if the group record from mdl_groups was included in the backup file. If it was included, use the mapped value to supply the required groupid value for mdl_choicegroup_options.
  3. If the group still cannot be found, do not set any option for it and write nothing to mdl_choicegroup_options.

The attached patch would apply this logic and fix the issue: choicegroup.patch.txt

This fix might be considered a change to the behaviour of the activity, but the PHP error messages and the groupid=0 records in mdl_choicegroup_options make me lean towards classifying the behaviour as a bug.

ndunand commented 2 years ago

Thanks @ebithell for spotting this, working it out and sharing your fix.

I completely agree with your logic and quickly tested your patch, which I have just integrated. This will be released along with the upcoming version officially supporting Moodle 4.0.

jumabgz commented 1 year ago

Hello Nicolas,

it seems that this problem is back. I am testing with moodle 3.9.18 + mod_choicegroup 1.38 (2022092202) and after restoring a course backup with mod_choicegroup with group selection set, the restored course shows the activity without the group selection of the original course (groups are being restored correctly at course level, but as ebithell said, the selected groups for the activity are not restored).

The same is true in 1.37. Before we were using 1.33 with moodle 3.9.15 and it was fine.

I hope you can check it out.

Regards

EDIT: Sorry, I think it was already reported here: https://github.com/ndunand/moodle-mod_choicegroup/issues/168

jumabgz commented 1 year ago

Hello, I have continued testing and I see that in the restored course, even though the selected groups field, in the activity settings, is empty, the student still sees as eligible the original groups and only the original ones and they can still make the selection. If the course had more groups not included in the original activity, they are not shown eligible in the restored activity. This is fine, however, in the settings, the selected groups field becomes empty and could be a problem or be confusing for the teacher.

This behavior occurs both in choicegroup 1.38 with moodle 3.9.18 and moodle 3.11.11.

Regards

Urpokarhu1 commented 11 months ago

I would like to see this fixed