Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]
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_page 22 * @copyright 2011 Andrew Davis <andrew@moodle.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 * Page conversion handler. This resource handler is called by moodle1_mod_resource_handler 30 */ 31 class moodle1_mod_page_handler extends moodle1_resource_successor_handler { 32 33 /** @var moodle1_file_manager instance */ 34 protected $fileman = null; 35 36 /** 37 * Converts /MOODLE_BACKUP/COURSE/MODULES/MOD/RESOURCE data 38 * Called by moodle1_mod_resource_handler::process_resource() 39 */ 40 public function process_legacy_resource(array $data, array $raw = null) { 41 42 // get the course module id and context id 43 $instanceid = $data['id']; 44 $cminfo = $this->get_cminfo($instanceid, 'resource'); 45 $moduleid = $cminfo['id']; 46 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid); 47 48 // convert the legacy data onto the new page record 49 $page = array(); 50 $page['id'] = $data['id']; 51 $page['name'] = $data['name']; 52 $page['intro'] = $data['intro']; 53 $page['introformat'] = $data['introformat']; 54 $page['content'] = $data['alltext']; 55 56 if ($data['type'] === 'html') { 57 // legacy Resource of the type Web page 58 $page['contentformat'] = FORMAT_HTML; 59 60 } else { 61 // legacy Resource of the type Plain text page 62 $page['contentformat'] = (int)$data['reference']; 63 64 if ($page['contentformat'] < 0 or $page['contentformat'] > 4) { 65 $page['contentformat'] = FORMAT_MOODLE; 66 } 67 } 68 69 $page['legacyfiles'] = RESOURCELIB_LEGACYFILES_ACTIVE; 70 $page['legacyfileslast'] = null; 71 $page['revision'] = 1; 72 $page['timemodified'] = $data['timemodified']; 73 74 // populate display and displayoptions fields 75 $options = array('printintro' => 0); 76 if ($data['popup']) { 77 $page['display'] = RESOURCELIB_DISPLAY_POPUP; 78 $rawoptions = explode(',', $data['popup']); 79 foreach ($rawoptions as $rawoption) { 80 list($name, $value) = explode('=', trim($rawoption), 2); 81 if ($value > 0 and ($name == 'width' or $name == 'height')) { 82 $options['popup'.$name] = $value; 83 continue; 84 } 85 } 86 } else { 87 $page['display'] = RESOURCELIB_DISPLAY_OPEN; 88 } 89 $page['displayoptions'] = serialize($options); 90 91 // get a fresh new file manager for this instance 92 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_page'); 93 94 // convert course files embedded into the intro 95 $this->fileman->filearea = 'intro'; 96 $this->fileman->itemid = 0; 97 $page['intro'] = moodle1_converter::migrate_referenced_files($page['intro'], $this->fileman); 98 99 // convert course files embedded into the content 100 $this->fileman->filearea = 'content'; 101 $this->fileman->itemid = 0; 102 $page['content'] = moodle1_converter::migrate_referenced_files($page['content'], $this->fileman); 103 104 // write page.xml 105 $this->open_xml_writer("activities/page_{$moduleid}/page.xml"); 106 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 107 'modulename' => 'page', 'contextid' => $contextid)); 108 $this->write_xml('page', $page, array('/page/id')); 109 $this->xmlwriter->end_tag('activity'); 110 $this->close_xml_writer(); 111 112 // write inforef.xml for migrated resource file. 113 $this->open_xml_writer("activities/page_{$moduleid}/inforef.xml"); 114 $this->xmlwriter->begin_tag('inforef'); 115 $this->xmlwriter->begin_tag('fileref'); 116 foreach ($this->fileman->get_fileids() as $fileid) { 117 $this->write_xml('file', array('id' => $fileid)); 118 } 119 $this->xmlwriter->end_tag('fileref'); 120 $this->xmlwriter->end_tag('inforef'); 121 $this->close_xml_writer(); 122 } 123 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body