MDL-23479 scorm restore code

This commit is contained in:
Dan Marsden 2010-07-28 22:37:49 +00:00
parent 0aa78279ae
commit a2920c7e5e
3 changed files with 269 additions and 0 deletions

View File

@ -154,6 +154,7 @@ class backup_scorm_activity_structure_step extends backup_activity_structure_ste
// Define file annotations
$scorm->annotate_files('mod_scorm', 'intro', null); // This file area hasn't itemid
$scorm->annotate_files('mod_scorm', 'content', null); // This file area hasn't itemid
$scorm->annotate_files('mod_scorm', 'package', null); // This file area hasn't itemid
// Return the root element (scorm), wrapped into standard activity structure
return $this->prepare_activity_structure($scorm);

View File

@ -0,0 +1,75 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/scorm/backup/moodle2/restore_scorm_stepslib.php'); // Because it exists (must)
/**
* scorm restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_scorm_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// scorm only has one structure step
$this->add_step(new restore_scorm_activity_structure_step('scorm_structure', 'scorm.xml'));
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
static public function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('scorm', array('intro'), 'scorm');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
static public function define_decode_rules() {
$rules = array();
$rules[] = new restore_decode_rule('SCORMVIEWBYID', '/mod/scorm/view.php?id=$1', 'course_module');
$rules[] = new restore_decode_rule('SCORMINDEX', '/mod/scorm/index.php?id=$1', 'course');
return $rules;
}
}

View File

@ -0,0 +1,193 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package moodlecore
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that will be used by the restore_scorm_activity_task
*/
/**
* Structure step to restore one scorm activity
*/
class restore_scorm_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$userinfo = $this->get_setting_value('userinfo');
$paths[] = new restore_path_element('scorm', '/activity/scorm');
$paths[] = new restore_path_element('scorm_sco', '/activity/scorm/scoes/sco');
$paths[] = new restore_path_element('scorm_sco_data', '/activity/scorm/sco_datas/sco_data');
$paths[] = new restore_path_element('scorm_seq_objective', '/activity/scorm/seq_objectives/seq_objective');
$paths[] = new restore_path_element('scorm_seq_rolluprule', '/activity/scorm/seq_rolluprules/seq_rolluprule');
$paths[] = new restore_path_element('scorm_seq_rolluprulecond', '/activity/scorm/seq_rollupruleconds/seq_rolluprulecond');
$paths[] = new restore_path_element('scorm_seq_rulecond', '/activity/scorm/seq_ruleconds/seq_rulecond');
$paths[] = new restore_path_element('scorm_seq_rulecond_data', '/activity/scorm/seq_rulecond_datas/seq_rulecond_data');
$paths[] = new restore_path_element('scorm_seq_mapinfo', '/activity/scorm/seq_mapinfos/seq_mapinfo');
if ($userinfo) {
$paths[] = new restore_path_element('scorm_sco_track', '/activity/scorm/sco_tracks/sco_track');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_scorm($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
$data->timeopen = $this->apply_date_offset($data->timeopen);
$data->timeclose = $this->apply_date_offset($data->timeclose);
// insert the scorm record
$newitemid = $DB->insert_record('scorm', $data);
// inmediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
protected function process_scorm_sco($data) {
global $DB;
$data = (object)$data;
//TODO: Remove this hack - seems to be a bug in restore that passes invalid data here.
if (!empty($data->id)) {
$oldid = $data->id;
$data->scorm = $this->get_new_parentid('scorm');
$newitemid = $DB->insert_record('scorm_scoes', $data);
$this->set_mapping('scorm_scoes', $oldid, $newitemid);
}
}
protected function process_scorm_sco_data($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_scoes');
$newitemid = $DB->insert_record('scorm_scoes_data', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_seq_objective($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_scoes');
$newitemid = $DB->insert_record('scorm_seq_objective', $data);
$this->set_mapping('scorm_seq_objective', $oldid, $newitemid);
}
protected function process_scorm_seq_rolluprule($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_scoes');
$newitemid = $DB->insert_record('scorm_seq_rolluprule', $data);
$this->set_mapping('scorm_seq_rolluprule', $oldid, $newitemid);
}
protected function process_scorm_seq_rolluprulecond($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_scoes');
$data->ruleconditions = $this->get_new_parentid('scorm_seq_rolluprule');
$newitemid = $DB->insert_record('scorm_seq_rolluprulecond', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_seq_rulecond($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_scoes');
$newitemid = $DB->insert_record('scorm_seq_ruleconds', $data);
$this->set_mapping('scorm_seq_ruleconds', $oldid, $newitemid);
}
protected function process_scorm_seq_rulecond_data($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_scoes');
$data->ruleconditions = $this->get_new_parentid('scorm_seq_ruleconds');
$newitemid = $DB->insert_record('scorm_seq_rulecond', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_seq_mapinfo($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scoid = $this->get_new_parentid('scorm_scoes');
$data->objectiveid = $this->get_new_parentid('scorm_seq_objective');
$newitemid = $DB->insert_record('scorm_scoes_data', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function process_scorm_sco_track($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->scormid = $this->get_new_parentid('scorm');
$data->scoid = $this->get_new_parentid('scorm_scoes');
$data->userid = $this->get_mappingid('user', $data->userid);
$newitemid = $DB->insert_record('scorm_scoes_track', $data);
// No need to save this mapping as far as nothing depend on it
// (child paths, file areas nor links decoder)
}
protected function after_execute() {
// Add scorm related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_scorm', 'intro', null);
$this->add_related_files('mod_scorm', 'content', null);
$this->add_related_files('mod_scorm', 'package', null);
}
}