MOODLE 2备份不存储表

时间:2013-01-22 20:25:47

标签: php moodle

我一直致力于邮件模块的备份功能。我按照MOODLE备份2.0开发指南。但是,除了模块活动表'mail'之外,备份不会保存任何表。这是我的实施:

  class backup_mail_activity_structure_step extends backup_activity_structure_step {

    protected function define_structure() {

        // To know if we are including userinfo
        $userinfo = $this->get_setting_value('userinfo');

        // Define each element separated
        $mail = new backup_nested_element('mail', array('id'), array(
          'course', 'name', 'intro', 'introformat', 'timecreated', 'timemodified'));

        $folders = new backup_nested_element('folders');
        $folder = new backup_nested_element('folder', array('id'), array(
          'mailid', 'userid', 'name', 'type', 'timemodified'));

        $messages = new backup_nested_element('messages');
        $message = new backup_nested_element('message', array('id'), array(
          'mailid', 'userid', 'fromid', 'folderid', 'subject', 'content',
          'file', 'isread', 'replied', 'forwarded', 'deleted', 'timecreated',
          'timemodified'));

        $groups = new backup_nested_element('groups');
        $group = new backup_nested_element('group', array('id'), array(
          'mailid', 'name', 'timemodified'));

        $members = new backup_nested_element('members');
        $member = new backup_nested_element('member', array('id'), array(
          'groupid', 'userid', 'timemodified'));

        $recipients = new backup_nested_element('recipients');
        $recipient = new backup_nested_element('recipient', array('id'), array(
          'messageid', 'toid', 'timemodified'));

        // Build the tree
        $mail->add_child($folders);
        $folders->add_child($folder);
        $folder->add_child($messages);
        $messages->add_child($message);
        $message->add_child($recipients);
        $recipients->add_child($recipient);

        $mail->add_child($groups);
        $groups->add_child($group);
        $group->add_child($members);
        $members->add_child($member);

        // Define sources
        //$mail->set_source_table('mail', array('id' => backup::VAR_ACTIVITYID));
        $mail->set_source_table('mail', array('id' => backup::VAR_ACTIVITYID));
        /*
        $folder->set_source_sql('
          SELECT *
          FROM {mail_folder}
          WHERE mailid = ?',
          array(backup::VAR_PARENTID));
         */
        if ($userinfo) {
          $folder->set_source_table('mail_folder', array('mailid' => backup::VAR_ACTIVITYID));
          $message->set_source_table('mail_messages', array('mailid'=>backup::VAR_ACTIVITYID));
          $recipient->set_source_table('mail_to_messages', array('messageid'=>backup::VAR_PARENTID));
          $group->set_source_table('mail_groups', array('mailid'=>backup::VAR_ACTIVITYID));
          $member->set_source_table('mail_members', array('groupid'=>backup::VAR_PARENTID));
        }
        /*
        print("ray_test:\n");
        print_object($groups);
         */

        // Define id annotations
        $folder->annotate_ids('user', 'userid');
        $message->annotate_ids('user', 'userid');
        $member->annotate_ids('user', 'userid');
        $recipient->annotate_ids('user', 'toid');

        // Define file annotations
        $mail->annotate_files('mod_mail', 'intro', null);

        // Return the root element (mail), wrapped into standard activity structure
        return $this->prepare_activity_structure($mail);

    }
}

这是生成的xml文件:

 <?xml version="1.0" encoding="UTF-8"?>
    <activity id="3" moduleid="87" modulename="mail" contextid="196">
    <mail id="3">
    <course>12</course>
    <name>Course Email</name>
    <intro></intro>
    <introformat>1</introformat>
    <timecreated>1351542231</timecreated>
    <timemodified>0</timemodified>
    <folders>
    </folders>
    <groups>
    </groups>
  </mail>
</activity>

0 个答案:

没有答案