1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * Provides support for the conversion of moodle1 backup to the moodle2 format 20 * 21 * @package mod_forum 22 * @copyright 2011 Mark Nielsen <mark@moodlerooms.com> 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 /** 29 * Forum conversion handler 30 */ 31 class moodle1_mod_forum_handler extends moodle1_mod_handler { 32 33 /** @var moodle1_file_manager */ 34 protected $fileman = null; 35 36 /** @var int cmid */ 37 protected $moduleid = null; 38 39 /** 40 * Declare the paths in moodle.xml we are able to convert 41 * 42 * The method returns list of {@link convert_path} instances. 43 * For each path returned, the corresponding conversion method must be 44 * defined. 45 * 46 * Note that the paths /MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM do not 47 * actually exist in the file. The last element with the module name was 48 * appended by the moodle1_converter class. 49 * 50 * @return array of {@link convert_path} instances 51 */ 52 public function get_paths() { 53 return array( 54 new convert_path('forum', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM', 55 array( 56 'renamefields' => array( 57 'format' => 'messageformat', 58 ), 59 'newfields' => array( 60 'completiondiscussions' => 0, 61 'completionreplies' => 0, 62 'completionpost' => 0, 63 'maxattachments' => 1, 64 'introformat' => 0, 65 ), 66 ) 67 ), 68 ); 69 } 70 71 /** 72 * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/FORUM data 73 */ 74 public function process_forum($data) { 75 global $CFG; 76 77 // get the course module id and context id 78 $instanceid = $data['id']; 79 $cminfo = $this->get_cminfo($instanceid); 80 $this->moduleid = $cminfo['id']; 81 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 82 83 // get a fresh new file manager for this instance 84 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_forum'); 85 86 // convert course files embedded into the intro 87 $this->fileman->filearea = 'intro'; 88 $this->fileman->itemid = 0; 89 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 90 91 // Convert the introformat if necessary. 92 if ($CFG->texteditors !== 'textarea') { 93 $data['intro'] = text_to_html($data['intro'], false, false, true); 94 $data['introformat'] = FORMAT_HTML; 95 } 96 97 // start writing forum.xml 98 $this->open_xml_writer("activities/forum_{$this->moduleid}/forum.xml"); 99 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 100 'modulename' => 'forum', 'contextid' => $contextid)); 101 $this->xmlwriter->begin_tag('forum', array('id' => $instanceid)); 102 103 foreach ($data as $field => $value) { 104 if ($field <> 'id') { 105 $this->xmlwriter->full_tag($field, $value); 106 } 107 } 108 109 $this->xmlwriter->begin_tag('discussions'); 110 111 return $data; 112 } 113 114 /** 115 * This is executed when we reach the closing </MOD> tag of our 'forum' path 116 */ 117 public function on_forum_end() { 118 // finish writing forum.xml 119 $this->xmlwriter->end_tag('discussions'); 120 $this->xmlwriter->end_tag('forum'); 121 $this->xmlwriter->end_tag('activity'); 122 $this->close_xml_writer(); 123 124 // write inforef.xml 125 $this->open_xml_writer("activities/forum_{$this->moduleid}/inforef.xml"); 126 $this->xmlwriter->begin_tag('inforef'); 127 $this->xmlwriter->begin_tag('fileref'); 128 foreach ($this->fileman->get_fileids() as $fileid) { 129 $this->write_xml('file', array('id' => $fileid)); 130 } 131 $this->xmlwriter->end_tag('fileref'); 132 $this->xmlwriter->end_tag('inforef'); 133 $this->close_xml_writer(); 134 } 135 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body