Bug when restoring preset with userdata in another site

Bug when restoring preset with userdata in another site

by Virgil Ashruf -
Number of replies: 3

I encountered an issue when trying to use a preset from one site in another where an account was present that also exists in the original source environment. I have analysed the problem and encountered a few bugs in the whole process of restoring a backup and the checks that happen. With this topic I would like to address the bug specifically related to the dataform part.

The problem is that a user in the backup created in the source site also exists in the target environment. Dataform checks this in the mod_dataform_preset_manager class on line 409:

if (!$rc->execute_precheck()) {
$precheckresults = $rc->get_precheck_results();
if (is_array($precheckresults) && !empty($precheckresults['errors'])) {
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($backuptempdir);
}
}
}

Up to this point the backup file has been extracted into a created directory in $CFG->tempdir. The execute precheck checks if the backup can be restored without conflicts. The conflict we are talking about in this topic can be identified as duplicate users. The precheck therefore fails and dataform will delete the created directory and extracted files. However, it will then still try to restore the backup which will fail because the files are no longer existing. This error message is confusing because it obfuscates the original problem: duplicate users:

Backup is missing XML file: [tempdir]/backup/tmp-1055-1476279350/files.xml

More information about this error

Debug info:
Error code: missing_moodle_backup_xml_file
Stack trace:
  • line 80 of /backup/util/plan/restore_structure_step.class.php: restore_step_exception thrown
  • line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()
  • line 177 of /backup/util/plan/base_plan.class.php: call to base_task->execute()
  • line 167 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()
  • line 335 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()
  • line 438 of /mod/dataform/classes/preset_manager.php: call to restore_controller->execute_plan()
  • line 225 of /mod/dataform/classes/preset_manager.php: call to mod_dataform_preset_manager->apply_preset()
  • line 53 of /mod/dataform/preset/index.php: call to mod_dataform_preset_manager->process_presets()

If $CFG->keeptempdirectoriesonbackup isn't empty the backup still tries to restore the dataform but fails because the user duplicate will cause an error in the restoration process.

My advise would be to either:

  1. make a call to debugging adding the precheck error message and then return false, exiting the method.
  2. throw an exception displaying the precheck error message.

Furthermore I am fantasising about anonymous presets so that no new users are created upon restore and entries are still added alongside the preset.

I currently do not have time on my hands to handle this for you; otherwise I'd be more than happy to commit this to the CONTRIB smile.

Average of ratings: -
In reply to Virgil Ashruf

Re: Bug when restoring preset with userdata in another site

by cathy taylor -

Same with me, I am facing the issue when trying to use a preset from one site in another. Please tell me how to fix this issue. Thankyou @Virgil Ashruf for the post, you saved my time.

In reply to Virgil Ashruf

Re: Bug when restoring preset with userdata in another site

by Itamar Tzadok -

Which version of the dataform are you using? I'm familiar with this issue, and as far as I can tell it has been fixed. I'll have to look into that though. smile