2

メールモジュールのバックアップ機能に取り組んでいます。私は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>
4

0 に答える 0