Backup independent tables in new module

Backup independent tables in new module

by Josh Bush -
Number of replies: 0
I have a module that uses an independent table, much like the questions table(s) in the quiz module.  I create a number of items in the main table (A), which access the data from the other table (B).  However, some records in B are not linked to A, an important part of the functionality.

I have recently become better acquainted with the abysmally documented backup/restore code.  The assumption made is that all data that an individual instance of a module activity belongs to that instance.  In my case, there is a link between the data, but there is no ownership.  I am currently "cheating", though I didn't know it until just recently.  I store all records from both tables under the same <MODTYPE>, using a field called <SUBMOD> to differentiate between the two tables during the restore process.  This works just fine as long as all the <ID> references are different.  If even one of B's <ID> is the same as A's, the restore function fails in my restore code; this is because the $info value returned is empty.

 I looked up how the quiz module handles this, and I saw the inserted reference to quiz_backup_question_categories in the backup_execute.html file.  This, however, would require the installer to edit the Moodle code everytime they upgrade to a new version.  I would like to avoid this.  Any suggestions?

I have some options available, such as mangling the table B <ID> fields in some allowed fashion to ensure there is no match to A <ID> fields.  I also have the problem of restoring past backups with this problem embedded.  Any help is appreciated.
Average of ratings: -