Skip to content
philcali edited this page Aug 14, 2012 · 5 revisions

Welcome to the Simple Restore wiki!

Simple restore allows simple, controlled user course restoration from customizable backup locations. Other plugins can inject their own repository without having to modify the simple restore codebase.

The purpose of this wiki is help facilitate plugin authors' understanding of the injection mechanisms.

Events

An outside plugin can add their own list of restore options to by handling two events:

  • simple_restore_backup_list: Handlers would provide restore options
  • simple_restore_selected_{name}: Handlers would load the selected option, where name is provided by the plugin

Adding to the List

The developer may want to connect some repository system, course, or user specific, and display these backups to the instructor. The simple_restore_backup_list event is given the following anonymous object:

  • $data
    • courseid: the course this request is coming from
    • restore_to: whether or not, the user selected to overwrite or import
    • shortname (if admin searched): only exists if the admin searched by course short name
    • lists: a collection of lists to display

Handlers are expected to add a list to lists. A list is an anonymous object with the following fields:

  • html: any output associated with the list (headings, tables, buttons, etc)
  • backups: any valid files associated with the user or search
  • order (optional): when the list should appear

Simple restore loads backups from the course restore file area for instructors.

Building a Table

Simple restore provides a convenience method attached to simple_restore_utils::build_table. Handlers are encouraged to use that method for building consistent tables for exposed backup files.

Making a Selection

Once a list is properly built, a selection event is fired should the user actually select the backup file. The event data is structured like so:

  • $data
    • userid: $USER->id
    • courseid: the course id of the course in question
    • fileid: the ID of the backup list
    • to_path: the temporary restore path

Handlers are expected to add a filename field to denote that the file exists and is valid, otherwise an exception will be thrown. Handlers are also expected to copy the selected file to the temporary restore location. Moodle file API's could take advantage of the copy_to_pathname($data->to_path), or external locations could simply use PHP's copy function. It is up to the plugin author to load the specific file.

General House Keeping

Moodle's core restore process can be very destructive to an existing course, if the overwrite option was taken. Simple restore allows for a plugin to do some house keeping / sanity checks once a restore is complete. One may want to restore grades, resources, enrollments, etc, depending on the university requirement. One can do so by handling the simple_restore_complete event. The event data is an associative array:

<?php
array(
  'userid' => $USER->id,
  'course_settings' => array(
    'restore_to' => $restore_to, // (1 || 0)
    'course' => $course // previous course before restore
  )
)
Clone this wiki locally