Backing up Context ID

Backing up Context ID

by Morgan Harris -
Number of replies: 1

I'm developing a /local plugin that adds functionality to certain contexts. One of my database tables has records that are associated with a context ID.

I'm just now starting the backup and restore code, and I've suddenly realised – how do I do this? What's the best way to encode a context in a course backup?

I don't really know anything about backup and restore, let along backup and restore for local plugins, let alone backup and restore of associated contexts. Any help would be great.

Average of ratings: -
In reply to Morgan Harris

Re: Backing up Context ID

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

When you restore from backup, all the values that need mapping from the backup version to the restored version (e.g. userids, courseid, course module ids, context ids, etc.) are stored by calling $this->set_mapping() (within the relevant restore_xx_step) and can then be retrieved by calling $this->get_mapping(), within your restore step.

e.g. look here: https://github.com/moodle/moodle/blob/master/mod/assign/backup/moodle2/restore_assign_stepslib.php#L152 for an example of mapping the backed-up userid onto a restored userid. You can do exactly the same for the contextid (I'd guess the identifier would be 'context', in this case).