Restore of local plugin tables with child items

Restore of local plugin tables with child items

by Enrique Castro -
Number of replies: 1
Picture of Core developers Picture of Particularly helpful Moodlers

Hi,

I've been cleaning some customizations embedding them in a local plugin. This plugin defines tables to store additional details to core 'course', 'groups' and 'grade_categories' tables as needed by my University administrative systems. 

I've managed to get the backup of these data working. I have defined backup/restore classes using the course hook. All additional data is relevant at course level.

class backup_local_ulpgccore_plugin extends backup_local_plugin {
protected function define_course_plugin_structure() {

In this way I can get the backup performed and data stored in the .mbz file in the course/course.xml part. 

<course id="3" contextid="1336">
  <shortname>T00</shortname>
  ...
  <plugin_local_ulpgccore_course>
    <term>2</term>
    <credits>6.00</credits>
    <department>242</department>
    <ctype>ob</ctype>
    <groups>
      <group>
        <groupid>6</groupid>
        <faculty>251</faculty>
        <itemid>66</itemid>
      </group>
      <group>
        <groupid>7</groupid>
        <faculty>324</faculty>
        <itemid>77</itemid>
      </group>
    </groups>
    <grade_categories>
      <grade_category>
        <categoryid>3</categoryid>
        <lockedit>1</lockedit>
      </grade_category>
      <grade_category>
        <categoryid>4</categoryid>
        <lockedit>1</lockedit>
      </grade_category>
    </grade_categories>
  </plugin_local_ulpgccore_course>

I've defined the companion restore class to revover these data, but it is working only in part. The first data is recovered but child parts, group and grade_category, are not restored.

The restore class contain the structure

    protected function define_course_plugin_structure() {
        $paths = array();
        $elename = 'plugin_local_ulpgccore_course'; // This defines the postfix of 'process_*' below.
        $elepath = $this->get_pathfor('/');
        $paths[] = new restore_path_element($elename, $elepath);
        $paths[] = new restore_path_element('plugin_local_ulpgccore_grade_category', $elepath.'/grade_categories/grade_category');
        if($groupinfo = $this->get_setting_value('groups')) {
            $paths[] = new restore_path_element('plugin_local_ulpgccore_group', $elepath.'/groups/group');
        }
        return $paths; // And we return the interesting paths.
    }
public function process_plugin_local_ulpgccore_course($data)
public function process_plugin_local_ulpgccore_grade_category($data)
public function process_plugin_local_ulpgccore_group($data)

The process_ ... method are required, if name changed the restore task aborts with a message indicating that a required method is missing.

However, when present those child methods the restore procedure proceed to completion but methods for child items are never executed. Only 'process_plugin_local_ulpgccore_course' gets executed and data is restored, the other two methods never get executed, and those data under 'groups' or 'grade_category' are not restored.

So, I'm missing something but I cannot figure. Any help is welcome!

Average of ratings: -
In reply to Enrique Castro

Re: Restore of local plugin tables with child items

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

When backup/restore code works, it is really great. When it does not work, it can be really, really hard to work out what is going on.

One technique is to find some other code in another plugin that works, and then compare what they did with what you did. So, looking at https://github.com/moodle/moodle/blob/master/mod/forum/backup/moodle2/restore_forum_stepslib.php#L34

Well, that is an activity module, that ends with 

return $this->prepare_activity_structure($paths);

But, you are working on a local plugin, which I guess is different.

Sorry, I can't see anything obviously wrong.