/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LESSON * data available */ public function process_lesson($data) { // get the course module id and context id $instanceid = $data['id']; $cminfo = $this->get_cminfo($instanceid); $this->moduleid = $cminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_lesson'); // migrate referenced local media files if (!empty($data['mediafile']) and strpos($data['mediafile'], '://') === false) { $this->fileman->filearea = 'mediafile'; $this->fileman->itemid = 0; try { $this->fileman->migrate_file('course_files/' . $data['mediafile']); } catch (moodle1_convert_exception $e) { // the file probably does not exist $this->log('error migrating lesson mediafile', backup::LOG_WARNING, 'course_files/' . $data['mediafile']); } } // start writing lesson.xml $this->open_xml_writer("activities/lesson_{$this->moduleid}/lesson.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'lesson', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('lesson', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } return $data; }
/** * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM * data available */ public function process_scorm($data) { global $CFG; // get the course module id and context id $instanceid = $data['id']; $currentcminfo = $this->get_cminfo($instanceid); $this->moduleid = $currentcminfo['id']; $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); // conditionally migrate to html format in intro if ($CFG->texteditors !== 'textarea') { $data['intro'] = text_to_html($data['intro'], false, false, true); $data['introformat'] = FORMAT_HTML; } // get a fresh new file manager for this instance $this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm'); // convert course files embedded into the intro $this->fileman->filearea = 'intro'; $this->fileman->itemid = 0; $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); // check 1.9 version where backup was created $backupinfo = $this->converter->get_stash('backup_info'); if ($backupinfo['moodle_version'] < 2007110503) { // as we have no module version data, assume $currmodule->version <= $module->version // - fix data as the source 1.9 build hadn't yet at time of backing up. $data['grademethod'] = $data['grademethod'] % 10; } // update scormtype (logic is consistent as done in scorm/db/upgrade.php) $ismanifest = preg_match('/imsmanifest\\.xml$/', $data['reference']); $iszippif = preg_match('/.(zip|pif)$/', $data['reference']); $isurl = preg_match('/^((http|https):\\/\\/|www\\.)/', $data['reference']); if ($isurl) { if ($ismanifest) { $data['scormtype'] = 'external'; } else { if ($iszippif) { $data['scormtype'] = 'localtype'; } } } // migrate scorm package file $this->fileman->filearea = 'package'; $this->fileman->itemid = 0; $this->fileman->migrate_file('course_files/' . $data['reference']); // start writing scorm.xml $this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml"); $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 'modulename' => 'scorm', 'contextid' => $contextid)); $this->xmlwriter->begin_tag('scorm', array('id' => $instanceid)); foreach ($data as $field => $value) { if ($field != 'id') { $this->xmlwriter->full_tag($field, $value); } } $this->xmlwriter->begin_tag('scoes'); return $data; }
/** * Migrates all course files referenced from the hypertext using the given filemanager * * This is typically used to convert images embedded into the intro fields. * * @param string $text hypertext containing $@FILEPHP@$ referenced * @param moodle1_file_manager $fileman file manager to use for the file migration * @return string the original $text with $@FILEPHP@$ references replaced with the new @@PLUGINFILE@@ */ public static function migrate_referenced_files($text, moodle1_file_manager $fileman) { $files = self::find_referenced_files($text); if (!empty($files)) { foreach ($files as $file) { try { $fileman->migrate_file('course_files'.$file, dirname($file)); } catch (moodle1_convert_exception $e) { // file probably does not exist $fileman->log('error migrating file', backup::LOG_WARNING, 'course_files'.$file); } } $text = self::rewrite_filephp_usage($text, $files); } return $text; }