|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00028 defined('MOODLE_INTERNAL') || die(); 00029 00033 class moodle1_mod_wiki_handler extends moodle1_mod_handler { 00034 00036 protected $initialcontent; 00037 00039 protected $initialcontentfilename; 00040 00042 protected $needinitpage = false; 00043 00045 protected $databuf = array(); 00046 00048 protected $fileman = null; 00049 00051 protected $moduleid = null; 00052 00066 public function get_paths() { 00067 return array( 00068 new convert_path( 00069 'wiki', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI', 00070 array( 00071 'newfields' => array( 00072 'introformat' => '0', 00073 'defaultformat' => 'html', //1.9 migrations default to html 00074 'forceformat' => '1', 00075 'editbegin' => '0', 00076 'editend' => '0', 00077 'timecreated' => time(), //2.x time of creation since theres no 1.9 time of creation 00078 ), 00079 'renamefields' => array( 00080 'summary' => 'intro', 00081 'format' => 'introformat', 00082 'firstpagetitle' => 'pagename', 00083 'wtype' => 'wikimode' 00084 ), 00085 'dropfields' => array( 00086 'pagename', 'scaleid', 'ewikiprinttitle', 'htmlmode', 'ewikiacceptbinary', 'disablecamelcase', 00087 'setpageflags', 'strippages', 'removepages', 'revertchanges' 00088 ) 00089 ) 00090 ), 00091 new convert_path( 00092 'wiki_entries', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES', 00093 array( 00094 'newfields' => array( 00095 'synonyms' => '0', 00096 'links' => 'collaborative', 00097 ), 00098 'dropfields' => array( 00099 'pagename' ,'timemodified' 00100 ) 00101 ) 00102 ), 00103 new convert_path( 00104 'wiki_entry', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES/ENTRY' 00105 ), 00106 new convert_path( 00107 'wiki_pages', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES/ENTRY/PAGES' 00108 ), 00109 new convert_path( 00110 'wiki_entry_page', '/MOODLE_BACKUP/COURSE/MODULES/MOD/WIKI/ENTRIES/ENTRY/PAGES/PAGE', 00111 array( 00112 'newfields' => array( 00113 'cachedcontent' => '**reparse needed**', 00114 'timerendered' => '0', 00115 'readonly' => '0', 00116 'tags' => '' 00117 ), 00118 'renamefields' => array( 00119 'pagename' => 'title', 00120 'created' => 'timecreated', 00121 'lastmodified' => 'timemodified', 00122 'hits' => 'pageviews' 00123 ), 00124 'dropfields' => array( 00125 'version', 'flags', 'author', 'refs', //refs will be reparsed during rendering 00126 'meta' 00127 ) 00128 ) 00129 ) 00130 ); 00131 } 00132 00137 public function process_wiki($data) { 00138 if (!empty($data['initialcontent'])) { 00139 //convert file in <INITIALCONTENT>filename</INITIALCONTENT> into a subwiki page if no entry created. 00140 $temppath = $this->converter->get_tempdir_path(); 00141 $this->initialcontent = file_get_contents($temppath.'/course_files/'.$data['initialcontent']); 00142 $this->initialcontentfilename = $data['initialcontent']; 00143 $this->needinitpage = true; 00144 } 00145 unset($data['initialcontent']); 00146 if ($data['wikimode'] !== 'group') { 00147 $data['wikimode'] = 'individual'; 00148 //@todo need to create extra subwikis due to individual wikimode? 00149 //this would then need to reference the users in the course that is being restored.(some parent class API needed) 00150 } else { 00151 $data['wikimode'] = 'collaborative'; 00152 } 00153 00154 if (empty($data['name'])) { 00155 $data['name'] = 'Wiki'; 00156 } 00157 // get the course module id and context id 00158 $instanceid = $data['id']; 00159 $cminfo = $this->get_cminfo($instanceid); 00160 $this->moduleid = $cminfo['id']; 00161 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 00162 00163 // get a fresh new file manager for this instance 00164 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_wiki'); 00165 00166 // convert course files embedded into the intro 00167 $this->fileman->filearea = 'intro'; 00168 $this->fileman->itemid = 0; 00169 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 00170 00171 // we now have all information needed to start writing into the file 00172 $this->open_xml_writer("activities/wiki_{$this->moduleid}/wiki.xml"); 00173 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 00174 'modulename' => 'wiki', 'contextid' => $contextid)); 00175 $this->xmlwriter->begin_tag('wiki', array('id' => $instanceid)); 00176 00177 foreach ($data as $field => $value) { 00178 if ($field <> 'id') { 00179 $this->xmlwriter->full_tag($field, $value); 00180 } 00181 } 00182 00183 return $data; 00184 } 00185 00186 public function on_wiki_entries_start() { 00187 $this->xmlwriter->begin_tag('subwikis'); 00188 $this->needinitpage = false; //backup has entries, so the initial_content file has been stored as a page in 1.9. 00189 } 00190 00191 public function on_wiki_entries_end() { 00192 $this->xmlwriter->end_tag('subwikis'); 00193 } 00194 00195 public function process_wiki_entry($data) { 00196 $this->xmlwriter->begin_tag('subwiki', array('id' => $data['id'])); 00197 unset($data['id']); 00198 00199 unset($data['pagename']); 00200 unset($data['timemodified']); 00201 00202 foreach ($data as $field => $value) { 00203 $this->xmlwriter->full_tag($field, $value); 00204 } 00205 } 00206 00207 public function on_wiki_entry_end() { 00208 $this->xmlwriter->end_tag('subwiki'); 00209 } 00210 00211 public function on_wiki_pages_start() { 00212 $this->xmlwriter->begin_tag('pages'); 00213 } 00214 00215 public function on_wiki_pages_end() { 00216 $this->xmlwriter->end_tag('pages'); 00217 } 00218 00219 public function process_wiki_entry_page($data) { 00220 // assimilate data to create later in extra virtual path page/versions/version/ 00221 $this->databuf['id'] = $this->converter->get_nextid(); 00222 $this->databuf['content'] = $data['content']; 00223 unset($data['content']); 00224 $this->databuf['contentformat'] = 'html'; 00225 $this->databuf['version'] = 0; 00226 $this->databuf['timecreated'] = $data['timecreated']; //do not unset, is reused 00227 $this->databuf['userid'] = $data['userid']; //do not unset, is reused 00228 00229 // process page data (user data and also the one that is from <initialcontent> 00230 $this->xmlwriter->begin_tag('page', array('id' => $data['id'])); 00231 unset($data['id']); // we already write it as attribute, do not repeat it as child element 00232 foreach ($data as $field => $value) { 00233 $this->xmlwriter->full_tag($field, $value); 00234 } 00235 00236 // process page content as a version. 00237 $this->xmlwriter->begin_tag('versions'); 00238 $this->write_xml('version', $this->databuf, array('/version/id')); //version id from get_nextid() 00239 $this->xmlwriter->end_tag('versions'); 00240 } 00241 public function on_wiki_entry_page_end() { 00242 $this->xmlwriter->end_tag('page'); 00243 } 00244 00248 public function on_wiki_end() { 00249 global $USER; 00250 00251 //check if the initial content needs to be created (and if a page is already there for it) 00252 if ($this->initialcontentfilename && $this->needinitpage) { 00253 //contruct (synthetic - not for cooking) a full path for creating entries/entry/pages/page 00254 $data_entry = array( 00255 'id' => $this->converter->get_nextid(), //creating the first entry 00256 'groupid' => 0, 00257 'userid' => 0, 00258 'synonyms' => '', 00259 'links' => '' 00260 ); 00261 $data_page = array( 00262 'id' => $this->converter->get_nextid(), //just creating the first page in the wiki 00263 'title' => $this->initialcontentfilename, 00264 'content' => $this->initialcontent, 00265 'userid' => $USER->id, 00266 'timecreated' => time(), 00267 'timemodified' => 0, 00268 'pageviews' => 0, 00269 'cachedcontent' => '**reparse needed**', 00270 'timerendered' => 0, 00271 'readonly' => 0, 00272 'tags' => '' 00273 ); 00274 //create xml with constructed page data (from initial_content file). 00275 $this->on_wiki_entries_start(); 00276 $this->process_wiki_entry($data_entry); 00277 $this->on_wiki_pages_start(); 00278 $this->process_wiki_entry_page($data_page); 00279 $this->on_wiki_entry_page_end(); 00280 $this->on_wiki_pages_end(); 00281 $this->on_wiki_entry_end(); 00282 $this->on_wiki_entries_end(); 00283 } 00284 00285 //close wiki.xml 00286 $this->xmlwriter->end_tag('wiki'); 00287 $this->xmlwriter->end_tag('activity'); 00288 $this->close_xml_writer(); 00289 00290 // write inforef.xml 00291 $this->open_xml_writer("activities/wiki_{$this->moduleid}/inforef.xml"); 00292 $this->xmlwriter->begin_tag('inforef'); 00293 $this->xmlwriter->begin_tag('fileref'); 00294 foreach ($this->fileman->get_fileids() as $fileid) { 00295 $this->write_xml('file', array('id' => $fileid)); 00296 } 00297 $this->xmlwriter->end_tag('fileref'); 00298 $this->xmlwriter->end_tag('inforef'); 00299 $this->close_xml_writer(); 00300 } 00301 }