|
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 00027 defined('MOODLE_INTERNAL') || die(); 00028 00032 class moodle1_mod_imscp_handler extends moodle1_resource_successor_handler { 00033 00035 protected $fileman = null; 00036 00041 public function process_legacy_resource($data) { 00042 00043 $instanceid = $data['id']; 00044 $currentcminfo = $this->get_cminfo($instanceid); 00045 $moduleid = $currentcminfo['id']; 00046 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid); 00047 00048 // prepare the new imscp instance record 00049 $imscp = array(); 00050 $imscp['id'] = $data['id']; 00051 $imscp['name'] = $data['name']; 00052 $imscp['intro'] = $data['intro']; 00053 $imscp['introformat'] = $data['introformat']; 00054 $imscp['revision'] = 1; 00055 $imscp['keepold'] = 1; 00056 $imscp['structure'] = null; 00057 $imscp['timemodified'] = $data['timemodified']; 00058 00059 // prepare a fresh new file manager for this instance 00060 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_imscp'); 00061 00062 // convert course files embedded into the intro 00063 $this->fileman->filearea = 'intro'; 00064 $this->fileman->itemid = 0; 00065 $imscp['intro'] = moodle1_converter::migrate_referenced_files($imscp['intro'], $this->fileman); 00066 00067 // migrate package backup file 00068 if ($data['reference']) { 00069 $packagename = basename($data['reference']); 00070 $packagepath = $this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/'.$packagename; 00071 if (file_exists($packagepath)) { 00072 $this->fileman->filearea = 'backup'; 00073 $this->fileman->itemid = 1; 00074 $this->fileman->migrate_file('moddata/resource/'.$data['id'].'/'.$packagename); 00075 } else { 00076 $this->log('missing imscp package', backup::LOG_WARNING, 'moddata/resource/'.$data['id'].'/'.$packagename); 00077 } 00078 } 00079 00080 // migrate extracted package data 00081 $this->fileman->filearea = 'content'; 00082 $this->fileman->itemid = 1; 00083 $this->fileman->migrate_directory('moddata/resource/'.$data['id']); 00084 00085 // parse manifest 00086 $structure = $this->parse_structure($this->converter->get_tempdir_path().'/moddata/resource/'.$data['id'].'/imsmanifest.xml'); 00087 $imscp['structure'] = is_array($structure) ? serialize($structure) : null; 00088 00089 // write imscp.xml 00090 $this->open_xml_writer("activities/imscp_{$moduleid}/imscp.xml"); 00091 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 00092 'modulename' => 'imscp', 'contextid' => $contextid)); 00093 $this->write_xml('imscp', $imscp, array('/imscp/id')); 00094 $this->xmlwriter->end_tag('activity'); 00095 $this->close_xml_writer(); 00096 00097 // write inforef.xml 00098 $this->open_xml_writer("activities/imscp_{$moduleid}/inforef.xml"); 00099 $this->xmlwriter->begin_tag('inforef'); 00100 $this->xmlwriter->begin_tag('fileref'); 00101 foreach ($this->fileman->get_fileids() as $fileid) { 00102 $this->write_xml('file', array('id' => $fileid)); 00103 } 00104 $this->xmlwriter->end_tag('fileref'); 00105 $this->xmlwriter->end_tag('inforef'); 00106 $this->close_xml_writer(); 00107 } 00108 00110 00116 protected function parse_structure($manifestfilepath) { 00117 global $CFG; 00118 00119 if (!file_exists($manifestfilepath)) { 00120 $this->log('missing imscp manifest file', backup::LOG_WARNING); 00121 return null; 00122 } 00123 $manifestfilecontents = file_get_contents($manifestfilepath); 00124 if (empty($manifestfilecontents)) { 00125 $this->log('empty imscp manifest file', backup::LOG_WARNING); 00126 return null; 00127 } 00128 00129 require_once($CFG->dirroot.'/mod/imscp/locallib.php'); 00130 return imscp_parse_manifestfile($manifestfilecontents); 00131 } 00132 }