Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Backup API

From MoodleDocs
Revision as of 02:32, 24 January 2012 by David Mudrak (talk | contribs) (The scaffold of the page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Moodle 2.0

The Backup API provides a way to include your plugin's in the course backup. See Restore API for the part that takes care of restoring data.

Overview

This page provides just a quick reference to the backup machinery in Moodle 2.0 and higher. There is a detailed documentation available at Backup 2.0 page - see especially the tutorial for plugin authors at Backup 2.0 for developers page.

Moodle creates backups of courses or their parts by executing so called backup plan. The backup plan consists of a set of backup tasks and finally each backup task consists of one or more backup steps. You as the developer of a plugin will have to implement one backup task that deals with your plugin data. Most plugins have their backup tasks consisting of a single backup step - the one that creates the XML file with data from your plugin's tables. Some activities may need two or more steps to finish their backup task though (for example the backup task of the Quiz module consists of three steps as it needs to write not just the Quiz setting itself but also the questions used by that particular quiz).

There are subtle differences in how the backup code is organised in various supported plugin types (activity modules, blocks, themes, course reports).

API for activity modules

Files

The files that implement the backup support in your activity module must be located in the subdirectory backup/moodle2/ in your plugin's folder. So, if you are developing the activity module called foobar then the backup files will be located in mod/foobar/backup/moodle2/ folder.

The following two files are supposed to exist in that location (replace foobar with the name of your module):

backup_foobar_activity_task.class.php
Provides the activity task class
backup_foobar_stepslib.php
Provides all the backup steps classes

If your module declares its own backup setting (apart from the ones common for all activity modules provided by the core), you will also want to create the backup_foobar_settingslib.php file to provide the setting classes. However most modules do not need this feature.

Classes

API for blocks

API for themes

See Backup 2.0 theme data

API for reports

See Backup 2.0 course report data