Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group Choice restore from Recycle Bin loses group settings #163

Closed
ebithell opened this issue May 3, 2022 · 5 comments
Closed

Group Choice restore from Recycle Bin loses group settings #163

ebithell opened this issue May 3, 2022 · 5 comments

Comments

@ebithell
Copy link

ebithell commented May 3, 2022

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:

  • The same general behaviour as for delete/restore of other activities i.e. all activity settings are restored
  • Group A is the selected group for the restored activity

Actual result:

  • With developer debugging and error reporting enabled, a PHP notice & warning are shown:
    Notice: Undefined property: stdClass::$option in /var/www/moodle/mod/choicegroup/mod_form.php on line 218
    Warning: Invalid argument supplied for foreach() in /var/www/moodle/mod/choicegroup/mod_form.php on line 218
  • A record for a group with groupid = 0 exists mdl_choicegroup_options
  • Selecting a group and saving the activity clears this database record and replaces it with a new and correct entry

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
Copy link
Author

ebithell commented May 3, 2022

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:

  • Delete to the Recycle Bin; restore from the Recycle Bin. Activity is restored with its pre-deletion settings.
  • Delete to the Recycle Bin followed by deleting a group from the course; restore from the Recycle Bin. The activity should not create a record in mdl_choicegroup_options for a group that does not exist and nor should the deleted group appear in the activity settings.
  • Duplicate activity: this should create a new activity with the same settings as existing. The group selection is a setting so it should be left as-is.
  • Backup the activity alone and restore into a new course. There should be no entries in mdl_choicegroup_options, because there cannot be any matching selected groups.
  • Backup the entire course and restore into a new course. New entries in mdl_choicegroup_options should be created to match the groups belonging to the new course.

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
Copy link
Owner

ndunand commented May 5, 2022

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.

@ndunand ndunand closed this as completed May 5, 2022
@jumabgz
Copy link

jumabgz commented Nov 16, 2022

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: #168

@jumabgz
Copy link

jumabgz commented Nov 17, 2022

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
Copy link

I would like to see this fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants