mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 20:53:53 +01:00
MDL-23479 backup - chat revised & old code deleted (but non-existing restore logs)
This commit is contained in:
parent
c768af3dc5
commit
59c9d381ae
@ -1,528 +0,0 @@
|
||||
<?php
|
||||
//This php script contains all the stuff to backup/restore
|
||||
//scorm mods
|
||||
|
||||
//This is the "graphical" structure of the scorm mod:
|
||||
//
|
||||
// scorm
|
||||
// (CL,pk->id)-------------------------------------
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// scorm_scoes scorm_scoes_data |
|
||||
// (UL,pk->id, fk->scorm)-------(UL,pk->id, fk->scoid) |
|
||||
// | |
|
||||
// | |
|
||||
// | |
|
||||
// scorm_scoes_track |
|
||||
// (UL,k->id, fk->scormid, fk->scoid, k->element)-------------------
|
||||
//
|
||||
// Meaning: pk->primary key field of the table
|
||||
// fk->foreign key to link with parent
|
||||
// nt->nested field (recursive data)
|
||||
// CL->course level info
|
||||
// UL->user level info
|
||||
// files->table may have files)
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
function scorm_backup_mods($bf,$preferences) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Iterate over scorm table
|
||||
$scorms = $DB->get_records ('scorm', array('course'=>$preferences->backup_course),'id');
|
||||
if ($scorms) {
|
||||
foreach ($scorms as $scorm) {
|
||||
if (backup_mod_selected($preferences,'scorm',$scorm->id)) {
|
||||
$status = scorm_backup_one_mod($bf,$preferences,$scorm);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function scorm_backup_one_mod($bf,$preferences,$scorm) {
|
||||
global $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
if (is_numeric($scorm)) {
|
||||
$scorm = $DB->get_record('scorm', array('id'=>$scorm));
|
||||
}
|
||||
|
||||
//Start mod
|
||||
fwrite ($bf,start_tag('MOD',3,true));
|
||||
//Print scorm data
|
||||
fwrite ($bf,full_tag('ID',4,false,$scorm->id));
|
||||
fwrite ($bf,full_tag('MODTYPE',4,false,'scorm'));
|
||||
fwrite ($bf,full_tag('NAME',4,false,$scorm->name));
|
||||
fwrite ($bf,full_tag('REFERENCE',4,false,$scorm->reference));
|
||||
fwrite ($bf,full_tag('VERSION',4,false,$scorm->version));
|
||||
fwrite ($bf,full_tag('MAXGRADE',4,false,$scorm->maxgrade));
|
||||
fwrite ($bf,full_tag('GRADEMETHOD',4,false,$scorm->grademethod));
|
||||
fwrite ($bf,full_tag('LAUNCH',4,false,$scorm->launch));
|
||||
fwrite ($bf,full_tag('SKIPVIEW',4,false,$scorm->skipview));
|
||||
fwrite ($bf,full_tag('SUMMARY',4,false,$scorm->intro));
|
||||
fwrite ($bf,full_tag('HIDEBROWSE',4,false,$scorm->hidebrowse));
|
||||
fwrite ($bf,full_tag('HIDETOC',4,false,$scorm->hidetoc));
|
||||
fwrite ($bf,full_tag('HIDENAV',4,false,$scorm->hidenav));
|
||||
fwrite ($bf,full_tag('AUTO',4,false,$scorm->auto));
|
||||
fwrite ($bf,full_tag('POPUP',4,false,$scorm->popup));
|
||||
fwrite ($bf,full_tag('OPTIONS',4,false,$scorm->options));
|
||||
fwrite ($bf,full_tag('WIDTH',4,false,$scorm->width));
|
||||
fwrite ($bf,full_tag('HEIGHT',4,false,$scorm->height));
|
||||
fwrite ($bf,full_tag('MD5HASH',4,false,$scorm->md5hash));
|
||||
fwrite ($bf,full_tag("MAXATTEMPT",4,false,$scorm->maxattempt));
|
||||
fwrite ($bf,full_tag("UPDATEFREQ",4,false,$scorm->updatefreq));
|
||||
fwrite ($bf,full_tag('TIMEMODIFIED',4,false,$scorm->timemodified));
|
||||
$status = backup_scorm_scoes($bf,$preferences,$scorm->id);
|
||||
|
||||
//if we've selected to backup users info, then execute backup_scorm_scoes_track
|
||||
if ($status) {
|
||||
if (backup_userdata_selected($preferences,'scorm',$scorm->id)) {
|
||||
$status = backup_scorm_scoes_track($bf,$preferences,$scorm->id);
|
||||
}
|
||||
$status = backup_scorm_files_instance($bf,$preferences,$scorm->id);
|
||||
|
||||
}
|
||||
//End mod
|
||||
$status =fwrite ($bf,end_tag('MOD',3,true));
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup scorm_scoes contents (executed from scorm_backup_mods)
|
||||
function backup_scorm_scoes ($bf,$preferences,$scorm) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_scoes = $DB->get_records('scorm_scoes', array('scorm'=>$scorm),'id');
|
||||
//If there is scoes
|
||||
if ($scorm_scoes) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SCOES',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_scoes as $sco) {
|
||||
//Start sco
|
||||
$status =fwrite ($bf,start_tag('SCO',5,true));
|
||||
//Print submission contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$sco->id));
|
||||
fwrite ($bf,full_tag('MANIFEST',6,false,$sco->manifest));
|
||||
fwrite ($bf,full_tag('ORGANIZATION',6,false,$sco->organization));
|
||||
fwrite ($bf,full_tag('PARENT',6,false,$sco->parent));
|
||||
fwrite ($bf,full_tag('IDENTIFIER',6,false,$sco->identifier));
|
||||
fwrite ($bf,full_tag('LAUNCH',6,false,$sco->launch));
|
||||
fwrite ($bf,full_tag('SCORMTYPE',6,false,$sco->scormtype));
|
||||
fwrite ($bf,full_tag('TITLE',6,false,$sco->title));
|
||||
$status = backup_scorm_scoes_data($bf,$preferences,$sco->id);
|
||||
$status = backup_scorm_seq_ruleconds($bf,$preferences,$sco->id);
|
||||
$status = backup_scorm_seq_rolluprule($bf,$preferences,$sco->id);
|
||||
$status = backup_scorm_seq_objective($bf,$preferences,$sco->id);
|
||||
//End sco
|
||||
$status =fwrite ($bf,end_tag('SCO',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SCOES',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup scorm_scoes_data contents (executed from scorm_backup_scorm_scoes)
|
||||
function backup_scorm_scoes_data ($bf,$preferences,$sco) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_sco_datas = $DB->get_records('scorm_scoes_data', array('scoid'=>$sco),'id');
|
||||
//If there is data
|
||||
if ($scorm_sco_datas) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SCO_DATAS',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_sco_datas as $sco_data) {
|
||||
//Start sco track
|
||||
$status =fwrite ($bf,start_tag('SCO_DATA',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$sco_data->id));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$sco_data->scoid));
|
||||
fwrite ($bf,full_tag('NAME',6,false,$sco_data->name));
|
||||
fwrite ($bf,full_tag('VALUE',6,false,$sco_data->value));
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SCO_DATA',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SCO_DATAS',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Backup scorm_scoes_track contents (executed from scorm_backup_mods)
|
||||
function backup_scorm_scoes_track ($bf,$preferences,$scorm) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_scoes_track = $DB->get_records('scorm_scoes_track', array('scormid'=>$scorm),'id');
|
||||
//If there is track
|
||||
if ($scorm_scoes_track) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SCO_TRACKS',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_scoes_track as $sco_track) {
|
||||
//Start sco track
|
||||
$status =fwrite ($bf,start_tag('SCO_TRACK',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$sco_track->id));
|
||||
fwrite ($bf,full_tag('USERID',6,false,$sco_track->userid));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$sco_track->scoid));
|
||||
fwrite ($bf,full_tag('ELEMENT',6,false,$sco_track->element));
|
||||
fwrite ($bf,full_tag('VALUE',6,false,$sco_track->value));
|
||||
fwrite ($bf,full_tag('ATTEMPT',6,false,$sco_track->attempt));
|
||||
fwrite ($bf,full_tag('TIMEMODIFIED',6,false,$sco_track->timemodified));
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SCO_TRACK',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SCO_TRACKS',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
function backup_scorm_seq_ruleconds ($bf,$preferences,$sco) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_seq_ruleconditions = $DB->get_records('scorm_seq_ruleconds', array('scoid'=>$sco),'id');
|
||||
//If there is rulecondition
|
||||
if ($scorm_seq_ruleconditions) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SEQ_RULECONDS',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_seq_ruleconditions as $seq_rulecondition) {
|
||||
//Start sco
|
||||
$status =fwrite ($bf,start_tag('SEQ_RULECOND',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$seq_rulecondition->id));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$seq_rulecondition->scoid));
|
||||
fwrite ($bf,full_tag('CONDITIONCOMBINATION',6,false,$seq_rulecondition->conditioncombination));
|
||||
fwrite ($bf,full_tag('RULETYPE',6,false,$seq_rulecondition->ruletype));
|
||||
fwrite ($bf,full_tag('ACTION',6,false,$seq_rulecondition->action));
|
||||
|
||||
$status = backup_scorm_seq_rulecond($bf,$preferences,$seq_rulecondition->id);
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SEQ_RULECOND',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SEQ_RULECONDS',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
function backup_scorm_seq_rulecond ($bf,$preferences,$ruleconditions) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_seq_ruleconditions = $DB->get_records('scorm_seq_rulecond', array('ruleconditionsid'=>$ruleconditions),'id');
|
||||
//If there is rulecondition
|
||||
if ($scorm_seq_ruleconditions) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SEQ_RULECOND_DATAS',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_seq_ruleconditions as $seq_rulecondition) {
|
||||
//Start sco
|
||||
$status =fwrite ($bf,start_tag('SEQ_RULECOND_DATA',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$seq_rulecondition->id));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$seq_rulecondition->scoid));
|
||||
fwrite ($bf,full_tag('RULECONDITIONSID',6,false,$seq_rulecondition->ruleconditionsid));
|
||||
fwrite ($bf,full_tag('REFRENCEDOBJECTIVE',6,false,$seq_rulecondition->refrencedobjective));
|
||||
fwrite ($bf,full_tag('MEASURETHRESHOLD',6,false,$seq_rulecondition->measurethreshold));
|
||||
fwrite ($bf,full_tag('OPERATOR',6,false,$seq_rulecondition->operator));
|
||||
fwrite ($bf,full_tag('COND',6,false,$seq_rulecondition->cond));
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SEQ_RULECOND_DATA',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SEQ_RULECOND_DATAS',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function backup_scorm_seq_rolluprule ($bf,$preferences,$sco) {
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_seq_rolluprules = $DB->get_records('scorm_seq_rolluprule', array('scoid'=>$sco),'id');
|
||||
//If there is rulecondition
|
||||
if ($scorm_seq_rolluprules) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SEQ_ROLLUPRULES',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_seq_rolluprules as $seq_rolluprule) {
|
||||
//Start sco
|
||||
$status =fwrite ($bf,start_tag('SEQ_ROLLUPRULE',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$seq_rolluprule->id));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$seq_rolluprule->scoid));
|
||||
fwrite ($bf,full_tag('CHILDACTIVITYSET',6,false,$seq_rolluprule->childactivityset));
|
||||
fwrite ($bf,full_tag('MINIMUMCOUNT',6,false,$seq_rolluprule->minimumcount));
|
||||
fwrite ($bf,full_tag('MINIMUMPERCENT',6,false,$seq_rolluprule->minimumpercent));
|
||||
fwrite ($bf,full_tag('CONDITIONCOMBINATION',6,false,$seq_rolluprule->conditioncomnination));
|
||||
fwrite ($bf,full_tag('ACTION',6,false,$seq_rolluprule->action));
|
||||
$status = backup_scorm_seq_rolluprulecond($bf,$preferences,$seq_rolluprule->id);
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SEQ_ROLLUPRULE',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SEQ_ROLLUPRULES',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
function backup_scorm_seq_rolluprulecond ($bf,$preferences,$rolluprule) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_seq_rollupruleconditions = $DB->get_records('scorm_seq_rolluprulecond', array('rollupruleid'=>$rolluprule), 'id');
|
||||
//If there is rulecondition
|
||||
if ($scorm_seq_rollupruleconditions) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SEQ_ROLLUPRULECONDS',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_seq_rollupruleconditions as $seq_rolluprulecondition) {
|
||||
//Start sco
|
||||
$status =fwrite ($bf,start_tag('SEQ_ROLLUPRULECOND',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$seq_rolluprulecondition->id));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$seq_rolluprulecondition->scoid));
|
||||
fwrite ($bf,full_tag('ROLLUPRULEID',6,false,$seq_rolluprulecondition->rollupruleid));
|
||||
fwrite ($bf,full_tag('COND',6,false,$seq_rolluprulecondition->condition));
|
||||
fwrite ($bf,full_tag('OPERATOR',6,false,$seq_rolluprulecondition->operator));
|
||||
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SEQ_ROLLUPRULECOND',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SEQ_ROLLUPRULECONDS',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
function backup_scorm_seq_objective ($bf,$preferences,$sco) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_seq_objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$sco),'id');
|
||||
//If there is rulecondition
|
||||
if ($scorm_seq_objectives) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SEQ_OBJECTIVES',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_seq_objectives as $seq_objective) {
|
||||
//Start sco
|
||||
$status =fwrite ($bf,start_tag('SEQ_OBJECTIVE',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$seq_objective->id));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$seq_objective->scoid));
|
||||
fwrite ($bf,full_tag('PRIMARYOBJ',6,false,$seq_objective->primaryobj));
|
||||
fwrite ($bf,full_tag('OBJECTIVEID',6,false,$seq_objective->objectiveid));
|
||||
fwrite ($bf,full_tag('MINNORMALIZEDMEASURE',6,false,$seq_objective->minnormalizedmeasure));
|
||||
fwrite ($bf,full_tag('SATISFIEDBYMEASURE',6,false,$seq_objective->objectivemeasureweight));
|
||||
|
||||
$status = backup_scorm_seq_mapinfo($bf,$preferences,$seq_objective->id);
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SEQ_OBJECTIVE',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SEQ_OBJECTIVES',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function backup_scorm_seq_mapinfo ($bf,$preferences,$objectives) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scorm_seq_objectives = $DB->get_records('scorm_seq_mapinfo', array('objectiveid'=>$objectives),'id');
|
||||
//If there is rulecondition
|
||||
if ($scorm_seq_objectives) {
|
||||
//Write start tag
|
||||
$status =fwrite ($bf,start_tag('SEQ_MAPINFO',4,true));
|
||||
//Iterate over each sco
|
||||
foreach ($scorm_seq_objectives as $seq_objective) {
|
||||
//Start sco
|
||||
$status =fwrite ($bf,start_tag('SEQ_MAPINF',5,true));
|
||||
//Print track contents
|
||||
fwrite ($bf,full_tag('ID',6,false,$seq_objective->id));
|
||||
fwrite ($bf,full_tag('SCOID',6,false,$seq_objective->scoid));
|
||||
fwrite ($bf,full_tag('OBJECTIVEID',6,false,$seq_objective->objectiveid));
|
||||
fwrite ($bf,full_tag('TARGETOBJECTIVEID',6,false,$seq_objective->targetobjectiveid));
|
||||
fwrite ($bf,full_tag('READSATISFIEDSTATUS',6,false,$seq_objective->readsatisfiedstatus));
|
||||
fwrite ($bf,full_tag('READNORMALIZEDMEASURE',6,false,$seq_objective->readnormalizedmeasure));
|
||||
fwrite ($bf,full_tag('WRITESATISFIEDSTATUS',6,false,$seq_objective->writesatisfiedstatus));
|
||||
fwrite ($bf,full_tag('WRITENORMALIZEDMEASURE',6,false,$seq_objective->writenormalizedmeasure));
|
||||
//End sco track
|
||||
$status =fwrite ($bf,end_tag('SEQ_MAPINF',5,true));
|
||||
}
|
||||
//Write end tag
|
||||
$status =fwrite ($bf,end_tag('SEQ_MAPINFO',4,true));
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
////Return an array of info (name,value)
|
||||
function scorm_check_backup_mods($course,$user_data=false,$backup_unique_code,$instances=null) {
|
||||
if (!empty($instances) && is_array($instances) && count($instances)) {
|
||||
$info = array();
|
||||
foreach ($instances as $id => $instance) {
|
||||
$info += scorm_check_backup_mods_instances($instance,$backup_unique_code);
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
//First the course data
|
||||
$info[0][0] = get_string('modulenameplural','scorm');
|
||||
if ($ids = scorm_ids ($course)) {
|
||||
$info[0][1] = count($ids);
|
||||
} else {
|
||||
$info[0][1] = 0;
|
||||
}
|
||||
|
||||
//Now, if requested, the user_data
|
||||
if ($user_data) {
|
||||
$info[1][0] = get_string('scoes','scorm');
|
||||
if ($ids = scorm_scoes_track_ids_by_course ($course)) {
|
||||
$info[1][1] = count($ids);
|
||||
} else {
|
||||
$info[1][1] = 0;
|
||||
}
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
function scorm_check_backup_mods_instances($instance,$backup_unique_code) {
|
||||
$info[$instance->id.'0'][0] = $instance->name;
|
||||
$info[$instance->id.'0'][1] = '';
|
||||
if (!empty($instance->userdata)) {
|
||||
$info[$instance->id.'1'][0] = get_string('scoes','scorm');
|
||||
if ($ids = scorm_scoes_track_ids_by_instance ($instance->id)) {
|
||||
$info[$instance->id.'1'][1] = count($ids);
|
||||
} else {
|
||||
$info[$instance->id.'1'][1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
function backup_scorm_files_instance($bf,$preferences,$instanceid) {
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
//First we check to moddata exists and create it as necessary
|
||||
//in temp/backup/$backup_code dir
|
||||
$status = check_and_create_moddata_dir($preferences->backup_unique_code);
|
||||
$status = check_dir_exists($CFG->dataroot.'/temp/backup/'.$preferences->backup_unique_code.'/moddata/scorm/',true);
|
||||
if ($status) {
|
||||
//Only if it exists !! Thanks to Daniel Miksik.
|
||||
if (is_dir($CFG->dataroot.'/'.$preferences->backup_course.'/'.$CFG->moddata.'/scorm/'.$instanceid)) {
|
||||
$status = backup_copy_file($CFG->dataroot.'/'.$preferences->backup_course.'/'.$CFG->moddata.'/scorm/'.$instanceid,
|
||||
$CFG->dataroot.'/temp/backup/'.$preferences->backup_unique_code.'/moddata/scorm/'.$instanceid);
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
//Backup scorm package files
|
||||
function backup_scorm_files($bf,$preferences) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
//First we check to moddata exists and create it as necessary
|
||||
//in temp/backup/$backup_code dir
|
||||
$status = check_and_create_moddata_dir($preferences->backup_unique_code);
|
||||
//Now copy the scorm dir
|
||||
if ($status) {
|
||||
if (is_dir($CFG->dataroot.'/'.$preferences->backup_course.'/'.$CFG->moddata.'/scorm')) {
|
||||
$handle = opendir($CFG->dataroot.'/'.$preferences->backup_course.'/'.$CFG->moddata.'/scorm');
|
||||
while (false!==($item = readdir($handle))) {
|
||||
if ($item != '.' && $item != '..' && is_dir($CFG->dataroot.'/'.$preferences->backup_course.'/'.$CFG->moddata.'/scorm/'.$item)
|
||||
&& array_key_exists($item,$preferences->mods['scorm']->instances)
|
||||
&& !empty($preferences->mods['scorm']->instances[$item]->backup)) {
|
||||
$status = backup_copy_file($CFG->dataroot.'/'.$preferences->backup_course.'/'.$CFG->moddata.'/scorm/'.$item,
|
||||
$CFG->dataroot.'/temp/backup/'.$preferences->backup_unique_code.'/moddata/scorm/',$item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
|
||||
}
|
||||
|
||||
//Return a content encoded to support interactivities linking. Every module
|
||||
//should have its own. They are called automatically from the backup procedure.
|
||||
function scorm_encode_content_links ($content,$preferences) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$base = preg_quote($CFG->wwwroot,"/");
|
||||
|
||||
//Link to the list of scorms
|
||||
$buscar="/(".$base."\/mod\/scorm\/index.php\?id\=)([0-9]+)/";
|
||||
$result= preg_replace($buscar,'$@SCORMINDEX*$2@$',$content);
|
||||
|
||||
//Link to scorm view by moduleid
|
||||
$buscar="/(".$base."\/mod\/scorm\/view.php\?id\=)([0-9]+)/";
|
||||
$result= preg_replace($buscar,'$@SCORMVIEWBYID*$2@$',$result);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// INTERNAL FUNCTIONS. BASED IN THE MOD STRUCTURE
|
||||
|
||||
//Returns an array of scorms id
|
||||
function scorm_ids ($course) {
|
||||
global $CFG, $DB;
|
||||
|
||||
return $DB->get_records_sql ("SELECT a.id, a.course
|
||||
FROM {scorm} a
|
||||
WHERE a.course = ?", array($course));
|
||||
}
|
||||
|
||||
//Returns an array of scorm_scoes id
|
||||
function scorm_scoes_track_ids_by_course ($course) {
|
||||
global $CFG, $DB;
|
||||
|
||||
return $DB->get_records_sql ("SELECT s.id , s.scormid
|
||||
FROM {scorm_scoes_track} s, {scorm} a
|
||||
WHERE a.course = ? AND
|
||||
s.scormid = a.id", array($course));
|
||||
}
|
||||
|
||||
//Returns an array of scorm_scoes id
|
||||
function scorm_scoes_track_ids_by_instance ($instanceid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
return $DB->get_records_sql ("SELECT s.id , s.scormid
|
||||
FROM {scorm_scoes_track} s
|
||||
WHERE s.scormid = ?", array($instanceid));
|
||||
}
|
||||
|
@ -26,847 +26,6 @@
|
||||
//
|
||||
//-----------------------------------------------------------
|
||||
|
||||
//This function executes all the restore procedure about this mod
|
||||
function scorm_restore_mods($mod,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get record from backup_ids
|
||||
$data = backup_getid($restore->backup_unique_code,$mod->modtype,$mod->id);
|
||||
|
||||
if ($data) {
|
||||
//Now get completed xmlized object
|
||||
$info = $data->info;
|
||||
//traverse_xmlize($info); //Debug
|
||||
//print_object ($GLOBALS['traverse_array']); //Debug
|
||||
//$GLOBALS['traverse_array']=""; //Debug
|
||||
|
||||
//Now, build the SCORM record structure
|
||||
$scorm->course = $restore->course_id;
|
||||
$scorm->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
|
||||
$scorm->reference = backup_todb($info['MOD']['#']['REFERENCE']['0']['#']);
|
||||
$scorm->version = backup_todb($info['MOD']['#']['VERSION']['0']['#']);
|
||||
$scorm->md5hash = backup_todb($info['MOD']['#']['MD5HASH']['0']['#']);
|
||||
$scorm->maxgrade = (double)backup_todb($info['MOD']['#']['MAXGRADE']['0']['#']);
|
||||
$scorm->updatefreq = (int)backup_todb($info['MOD']['#']['UPDATEFREQ']['0']['#']);
|
||||
$scorm->maxattempt = (int)backup_todb($info['MOD']['#']['MAXATTEMPT']['0']['#']);
|
||||
$scorm->grademethod = (int)backup_todb($info['MOD']['#']['GRADEMETHOD']['0']['#']);
|
||||
$scorm->whatgrade = (int)backup_todb($info['MOD']['#']['WHATGRADE']['0']['#']);
|
||||
if ($restore->backup_version < 2005041500) {
|
||||
$scorm->datadir = substr(backup_todb($info['MOD']['#']['DATADIR']['0']['#']),1);
|
||||
} else {
|
||||
$scorm->datadir = backup_todb($info['MOD']['#']['ID']['0']['#']);
|
||||
}
|
||||
$oldlaunch = backup_todb($info['MOD']['#']['LAUNCH']['0']['#']);
|
||||
if ($restore->backup_version < 2006102600) {
|
||||
$scorm->skipview = 1;
|
||||
} else {
|
||||
$scorm->skipview = backup_todb($info['MOD']['#']['SKIPVIEW']['0']['#']);
|
||||
}
|
||||
$scorm->intro = backup_todb($info['MOD']['#']['SUMMARY']['0']['#']);
|
||||
$scorm->hidebrowse = backup_todb($info['MOD']['#']['HIDEBROWSE']['0']['#']);
|
||||
$scorm->hidetoc = backup_todb($info['MOD']['#']['HIDETOC']['0']['#']);
|
||||
$scorm->hidenav = backup_todb($info['MOD']['#']['HIDENAV']['0']['#']);
|
||||
$scorm->auto = backup_todb($info['MOD']['#']['AUTO']['0']['#']);
|
||||
if ($restore->backup_version < 2005040200) {
|
||||
$oldpopup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
|
||||
if (!empty($oldpopup)) {
|
||||
$scorm->popup = 1;
|
||||
// Parse old popup field
|
||||
$options = array();
|
||||
$oldoptions = explode(',',$scorm->popup);
|
||||
foreach ($oldoptions as $oldoption) {
|
||||
list($element,$value) = explode('=',$oldoption);
|
||||
$element = trim($element);
|
||||
$value = trim($value);
|
||||
switch ($element) {
|
||||
case 'width':
|
||||
$scorm->width = $value;
|
||||
break;
|
||||
case 'height':
|
||||
$scorm->height = $value;
|
||||
break;
|
||||
default:
|
||||
$options[] = $element.'='.$value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$scorm->options = implode($options,',');
|
||||
} else {
|
||||
$scorm->popup = 0;
|
||||
$scorm->options = '';
|
||||
$scorm->width = '100%';
|
||||
$scorm->height = 500;
|
||||
}
|
||||
} else {
|
||||
$scorm->popup = backup_todb($info['MOD']['#']['POPUP']['0']['#']);
|
||||
$scorm->width = backup_todb($info['MOD']['#']['WIDTH']['0']['#']);
|
||||
if ($scorm->width == 0) {
|
||||
$scorm->width = '100%';
|
||||
}
|
||||
$scorm->height = backup_todb($info['MOD']['#']['HEIGHT']['0']['#']);
|
||||
if ($scorm->height == 0) {
|
||||
$scorm->height = 500;
|
||||
}
|
||||
if (!empty($info['MOD']['#']['OPTIONS']['0']['#'])) {
|
||||
$scorm->options = backup_todb($info['MOD']['#']['OPTIONS']['0']['#']);
|
||||
}
|
||||
}
|
||||
$scorm->timemodified = time();
|
||||
|
||||
//The structure is equal to the db, so insert the scorm
|
||||
$newid = $DB->insert_record ("scorm",$scorm);
|
||||
//Do some output
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo "<li>".get_string("modulename","scorm")." \"".format_string($scorm->name,true)."\"</li>";
|
||||
}
|
||||
backup_flush(300);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,$mod->modtype,
|
||||
$mod->id, $newid);
|
||||
$scorm->id = $newid;
|
||||
//Now copy moddata associated files
|
||||
$status = scorm_restore_files ($scorm, $restore);
|
||||
|
||||
if ($status) {
|
||||
$status = scorm_scoes_restore_mods ($newid,$info,$restore,$mod->id);
|
||||
if ($status) {
|
||||
$launchsco = backup_getid($restore->backup_unique_code,"scorm_scoes",$oldlaunch);
|
||||
$scorm->launch = $launchsco->new_id;
|
||||
$DB->update_record('scorm',$scorm);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the scorm_scoes
|
||||
function scorm_scoes_restore_mods($scorm_id,$info,$restore,$oldmodid) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the sco array
|
||||
$scoes = $info['MOD']['#']['SCOES']['0']['#']['SCO'];
|
||||
|
||||
//Iterate over scoes
|
||||
for($i = 0; $i < sizeof($scoes); $i++) {
|
||||
$sub_info = $scoes[$i];
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
|
||||
|
||||
//Now, build the scorm_scoes record structure
|
||||
$sco->scorm = $scorm_id;
|
||||
$sco->manifest = backup_todb($sub_info['#']['MANIFEST']['0']['#']);
|
||||
$sco->organization = backup_todb($sub_info['#']['ORGANIZATION']['0']['#']);
|
||||
$sco->parent = backup_todb($sub_info['#']['PARENT']['0']['#']);
|
||||
$sco->identifier = backup_todb($sub_info['#']['IDENTIFIER']['0']['#']);
|
||||
$sco->launch = backup_todb($sub_info['#']['LAUNCH']['0']['#']);
|
||||
$sco->title = backup_todb($sub_info['#']['TITLE']['0']['#']);
|
||||
if ($restore->backup_version < 2005031300) {
|
||||
$sco->scormtype = backup_todb($sub_info['#']['TYPE']['0']['#']);
|
||||
} else {
|
||||
$sco->scormtype = backup_todb($sub_info['#']['SCORMTYPE']['0']['#']);
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the scorm_scoes
|
||||
$newid = $DB->insert_record ("scorm_scoes",$sco);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_scoes", $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
if ($status && !empty($sub_info['#']['SCO_DATAS'])) {
|
||||
$status = scorm_scoes_data_restore_mods($newid, $sub_info['#']['SCO_DATAS'], $restore);
|
||||
}
|
||||
}
|
||||
|
||||
//Now check if want to restore user data and do it.
|
||||
scorm_scoes_seq_objective_restore_mods ($newid,$info,$restore);
|
||||
scorm_scoes_seq_rolluprule_restore_mods ($newid,$info,$restore);
|
||||
scorm_scoes_seq_ruleconds_restore_mods ($newid,$info,$restore);
|
||||
if (restore_userdata_selected($restore,'scorm',$oldmodid)) {
|
||||
//Restore scorm_scoes
|
||||
if ($status) {
|
||||
if ($restore->backup_version < 2005031300) {
|
||||
$status = scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore);
|
||||
} else {
|
||||
$status = scorm_scoes_tracks_restore_mods ($scorm_id,$info,$restore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Restore scorm_scoes_data contents (executed from scorm_scoes_restore_mods)
|
||||
function scorm_scoes_data_restore_mods ($new_scoe_id, $scoes_old_datas, $restore) {
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
$scoe_old_datas = $scoes_old_datas['0']['#']['SCO_DATA'];
|
||||
|
||||
//Iterate over scoe_data
|
||||
for($i = 0; $i < sizeof($scoe_old_datas); $i++) {
|
||||
$scoe_old_data = $scoe_old_datas[$i];
|
||||
unset($scoe_new_data);
|
||||
|
||||
$scoe_new_data->scoid = $new_scoe_id;
|
||||
$scoe_new_data->name = backup_todb($scoe_old_data['#']['NAME']['0']['#']);
|
||||
$scoe_new_data->value = backup_todb($scoe_old_data['#']['VALUE']['0']['#']);
|
||||
|
||||
//The structure is equal to the db, so insert the scorm_scoes_data table
|
||||
$new_scoe_data_id = insert_record ("scorm_scoes_data",$scoe_new_data);
|
||||
|
||||
$old_scoe_data_id = backup_todb($scoe_old_data['#']['ID']['0']['#']);
|
||||
|
||||
if ($new_scoe_data_id) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_scoes_data", $old_scoe_data_id, $new_scoe_data_id);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
function scorm_scoes_seq_objective_restore_mods($sco_id,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the discussions array
|
||||
$objectives = array();
|
||||
|
||||
if (!empty($info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'])) {
|
||||
$objectives = $info['MOD']['#']['SEQ_OBJECTIVES']['0']['#']['SEQ_OBJECTIVE'];
|
||||
}
|
||||
|
||||
//Iterate over discussions
|
||||
for($i = 0; $i < sizeof($objectives); $i++) {
|
||||
$obj_info = $objectives[$i];
|
||||
//Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($obj_info['#']['ID']['0']['#']);
|
||||
//Now, build the FORUM_DISCUSSIONS record structure
|
||||
$objective->scoid = $sco_id;
|
||||
$objective->primaryobj = backup_todb($obj_info['#']['PRIMARYOBJ']['0']['#']);
|
||||
$objective->objectiveid = backup_todb($obj_info['#']['OBJECTIVEID']['0']['#']);
|
||||
$objective->satisfiedbymeasure = backup_todb($obj_info['#']['SATISFIEDBYMEASURE']['0']['#']);
|
||||
$objective->minnormalizedmeasure = backup_todb($obj_info['#']['MINNORMALIZEDMEASURE']['0']['#']);
|
||||
|
||||
//The structure is equal to the db, so insert the forum_discussions
|
||||
$newid = $DB->insert_record ("scorm_seq_objective",$objective);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_seq_objective", $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
//Now restore the scorm_seq_mapinfo for each objective
|
||||
|
||||
$status = scorm_seq_mapinfo_restore_mods ($sco_id,$newid,$obj_info,$restore);
|
||||
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function scorm_scoes_seq_rolluprule_restore_mods($sco_id,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the discussions array
|
||||
$rolluprules = array();
|
||||
|
||||
if (!empty($info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'])) {
|
||||
$rolluprules = $info['MOD']['#']['SEQ_ROLLUPRULES']['0']['#']['SEQ_ROLLUPRULE'];
|
||||
}
|
||||
|
||||
//Iterate over discussions
|
||||
for($i = 0; $i < sizeof($rolluprules); $i++) {
|
||||
$rol_info = $rolluprules[$i];
|
||||
//Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($rol_info['#']['ID']['0']['#']);
|
||||
//Now, build the FORUM_DISCUSSIONS record structure
|
||||
$rolluprule->scoid = $sco_id;
|
||||
$rolluprule->childactivityset = backup_todb($rol_info['#']['CHILDACTIVITYSET']['0']['#']);
|
||||
$rolluprule->minimumrule = backup_todb($rol_info['#']['MINIMUMCOUNT']['0']['#']);
|
||||
$rolluprule->minimumpercent = backup_todb($rol_info['#']['MINIMUMPERCENT']['0']['#']);
|
||||
$rolluprule->conditioncombination = backup_todb($rol_info['#']['CONDITIONCOMBINATION']['0']['#']);
|
||||
$rolluprule->action = backup_todb($rol_info['#']['ACTION']['0']['#']);
|
||||
|
||||
//The structure is equal to the db, so insert the forum_discussions
|
||||
$newid = $DB->insert_record ("scorm_seq_rolluprule",$rolluprule);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_seq_rolluprule", $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
//Now restore the scorm_seq_mapinfo for each objective
|
||||
|
||||
$status = scorm_seq_rolluprulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
|
||||
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
function scorm_scoes_seq_ruleconds_restore_mods($sco_id,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the discussions array
|
||||
$ruleconds = array();
|
||||
|
||||
if (!empty($info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'])) {
|
||||
$ruleconds = $info['MOD']['#']['SEQ_RULECONDS']['0']['#']['SEQ_RULECOND'];
|
||||
}
|
||||
|
||||
//Iterate over discussions
|
||||
for($i = 0; $i < sizeof($ruleconds); $i++) {
|
||||
$rul_info = $ruleconds[$i];
|
||||
//Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($rul_info['#']['ID']['0']['#']);
|
||||
|
||||
$rulecond->scoid = $sco_id;
|
||||
$rulecond->conditioncombination = backup_todb($rul_info['#']['CONDITIONCOMBINATION']['0']['#']);
|
||||
$rulecond->minimumpercent = backup_todb($rul_info['#']['RULETYPE']['0']['#']);
|
||||
$rulecond->action = backup_todb($rul_info['#']['ACTION']['0']['#']);
|
||||
|
||||
//The structure is equal to the db, so insert the forum_discussions
|
||||
$newid = $DB->insert_record ("scorm_seq_ruleconds",$rulecond);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_seq_ruleconds", $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
//Now restore the scorm_seq_mapinfo for each objective
|
||||
|
||||
$status = scorm_seq_rulecond_restore_mods ($sco_id, $newid,$obj_info,$restore);
|
||||
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
function scorm_scoes_seq_rulecond_restore_mods($sco_id,$rulecondid,$info,$restore) {
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the discussions array
|
||||
$rulecondsd = array();
|
||||
|
||||
if (!empty($info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'])) {
|
||||
$rulecondsd = $info['MOD']['#']['SEQ_RULECOND_DATAS']['0']['#']['SEQ_RULECOND_DATA'];
|
||||
}
|
||||
|
||||
|
||||
for($i = 0; $i < sizeof($rulecondsd); $i++) {
|
||||
$ruld_info = $rulecondsd[$i];
|
||||
//Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($rul_info['#']['ID']['0']['#']);
|
||||
|
||||
$rulecondd->scoid = $sco_id;
|
||||
$rulecondd->ruleconditions = $rulecondid;
|
||||
$rulecondd->refrencedobjective = backup_todb($ruld_info['#']['REFRENCEDOBJECTIVE']['0']['#']);
|
||||
$rulecondd->measurethreshold = backup_todb($ruld_info['#']['MEASURETHRESHOLD']['0']['#']);
|
||||
$rulecondd->operator = backup_todb($ruld_info['#']['OPERATOR']['0']['#']);
|
||||
$rulecondd->cond = backup_todb($ruld_info['#']['COND']['0']['#']);
|
||||
|
||||
//The structure is equal to the db, so insert the forum_discussions
|
||||
$newid = $DB->insert_record ("scorm_seq_rulecond",$rulecondd);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_seq_rulecond", $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
//Now restore the scorm_seq_mapinfo for each objective
|
||||
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
function scorm_scoes_seq_rolluprulecond_restore_mods($sco_id,$rolluprule,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the discussions array
|
||||
$rollupruleconds = array();
|
||||
|
||||
if (!empty($info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'])) {
|
||||
$rollupruleconds = $info['MOD']['#']['SEQ_ROLLUPRULECONDS']['0']['#']['SEQ_ROLLUPRULECOND'];
|
||||
}
|
||||
|
||||
|
||||
for($i = 0; $i < sizeof($rollupruleconds); $i++) {
|
||||
$rulc_info = $rollupruleconds[$i];
|
||||
//Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($rulc_info['#']['ID']['0']['#']);
|
||||
|
||||
$rolluprulecond->scoid = $sco_id;
|
||||
$rolluprulecond->ruleconditions = $rolluprule;
|
||||
$rolluprulecond->cond = backup_todb($rulc_info['#']['COND']['0']['#']);
|
||||
$rolluprulecond->operator = backup_todb($rulc_info['#']['OPERATOR']['0']['#']);
|
||||
|
||||
|
||||
//The structure is equal to the db, so insert the forum_discussions
|
||||
$newid = $DB->insert_record ("scorm_seq_rolluprulecond",$rolluprulecond);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_seq_rolluprulecond", $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
//Now restore the scorm_seq_mapinfo for each objective
|
||||
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
function scorm_scoes_seq_mapinfo_restore_mods($sco_id,$objectiveid,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
|
||||
//Get the discussions array
|
||||
$mapinfos = array();
|
||||
|
||||
if (!empty($info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'])) {
|
||||
$mapinfos = $info['MOD']['#']['SEQ_MAPINFO']['0']['#']['SEQ_MAPINF'];
|
||||
}
|
||||
|
||||
|
||||
for($i = 0; $i < sizeof($mapinfos); $i++) {
|
||||
$map_info = $mapinfos[$i];
|
||||
//Debug
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($map_info['#']['ID']['0']['#']);
|
||||
|
||||
$mapinfo->scoid = $sco_id;
|
||||
$mapinfo->objectiveid = $ojectiveid;
|
||||
$mapinfo->targetobjectiveid = backup_todb($map_info['#']['TARGETOBJECTIVEID']['0']['#']);
|
||||
$mapinfo->readsatisfiedstatus = backup_todb($map_info['#']['READSATISFIEDSTATUS']['0']['#']);
|
||||
$mapinfo->readnormalizedmeasure = backup_todb($map_info['#']['READNORMALIZEDMEASURE']['0']['#']);
|
||||
$mapinfo->writesatisfiedstatus = backup_todb($map_info['#']['WRITESATISFIEDSTATUS']['0']['#']);
|
||||
$mapinfo->writenormalizedmeasure = backup_todb($map_info['#']['WRITENORMALIZEDMEASURE']['0']['#']);
|
||||
|
||||
|
||||
//The structure is equal to the db, so insert the forum_discussions
|
||||
$newid = $DB->insert_record ("scorm_seq_mapinfo",$mapinfo);
|
||||
|
||||
if ($newid) {
|
||||
//We have the newid, update backup_ids
|
||||
backup_putid($restore->backup_unique_code,"scorm_seq_mapinfo", $oldid, $newid);
|
||||
} else {
|
||||
$status = false;
|
||||
}
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the scorm_scoes_track
|
||||
function scorm_scoes_tracks_restore_mods($scorm_id,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
$scotracks = NULL;
|
||||
|
||||
//Get the sco array
|
||||
if (!empty($info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK']))
|
||||
$scotracks = $info['MOD']['#']['SCO_TRACKS']['0']['#']['SCO_TRACK'];
|
||||
|
||||
//Iterate over sco_users
|
||||
for($i = 0; $i < sizeof($scotracks); $i++) {
|
||||
$sub_info = $scotracks[$i];
|
||||
unset($scotrack);
|
||||
|
||||
//Now, build the scorm_scoes_track record structure
|
||||
$scotrack->scormid = $scorm_id;
|
||||
$scotrack->userid = backup_todb($sub_info['#']['USERID']['0']['#']);
|
||||
$scotrack->scoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
|
||||
$scotrack->element = backup_todb($sub_info['#']['ELEMENT']['0']['#']);
|
||||
$scotrack->attempt = backup_todb($sub_info['#']['ATTEMPT']['0']['#']);
|
||||
$scotrack->value = backup_todb($sub_info['#']['VALUE']['0']['#']);
|
||||
|
||||
//We have to recode the userid field
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$scotrack->userid);
|
||||
if (!empty($user)) {
|
||||
$scotrack->userid = $user->new_id;
|
||||
}
|
||||
|
||||
//We have to recode the scoid field
|
||||
$sco = backup_getid($restore->backup_unique_code,"scorm_scoes",$scotrack->scoid);
|
||||
if ($sco != NULL) {
|
||||
$scotrack->scoid = $sco->new_id;
|
||||
}
|
||||
|
||||
$scotrack->timemodified = time();
|
||||
//The structure is equal to the db, so insert the scorm_scoes_track
|
||||
$newid = $DB->insert_record ("scorm_scoes_track",$scotrack);
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function restores the scorm_scoes_track from Moodle 1.4
|
||||
function scorm_scoes_tracks_restore_mods_pre15 ($scorm_id,$info,$restore) {
|
||||
global $CFG, $DB;
|
||||
|
||||
$status = true;
|
||||
$scousers = NULL;
|
||||
|
||||
//Get the sco array
|
||||
if (!empty($info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'])) {
|
||||
$scousers = $info['MOD']['#']['SCO_USERS']['0']['#']['SCO_USER'];
|
||||
}
|
||||
|
||||
$oldelements = array ('CMI_CORE_LESSON_LOCATION',
|
||||
'CMI_CORE_LESSON_STATUS',
|
||||
'CMI_CORE_EXIT',
|
||||
'CMI_CORE_TOTAL_TIME',
|
||||
'CMI_CORE_SCORE_RAW',
|
||||
'CMI_SUSPEND_DATA');
|
||||
$newelements = array ('cmi.core.lesson_location',
|
||||
'cmi.core.lesson_status',
|
||||
'cmi.core.exit',
|
||||
'cmi.core.total_time',
|
||||
'cmi.core.score.raw',
|
||||
'cmi.suspend_data');
|
||||
|
||||
//Iterate over sco_users
|
||||
for ($i = 0; $i < sizeof($scousers); $i++) {
|
||||
$sub_info = $scousers[$i];
|
||||
unset($scotrack);
|
||||
|
||||
//We'll need this later!!
|
||||
$oldid = backup_todb($sub_info['#']['ID']['0']['#']);
|
||||
$oldscoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
|
||||
$olduserid = backup_todb($sub_info['#']['USERID']['0']['#']);
|
||||
|
||||
//Now, build the scorm_scoes_track record structure
|
||||
$scotrack->scormid = $scorm_id;
|
||||
$scotrack->userid = backup_todb($sub_info['#']['USERID']['0']['#']);
|
||||
$scotrack->scoid = backup_todb($sub_info['#']['SCOID']['0']['#']);
|
||||
$pos = 0;
|
||||
foreach ($oldelements as $oldelement) {
|
||||
$elementvalue = backup_todb($sub_info['#'][$oldelement]['0']['#']);
|
||||
if (!empty($elementvalue)) {
|
||||
$scotrack->element = $newelements[$pos];
|
||||
$scotrack->value = backup_todb($sub_info['#'][strtoupper($oldelement)]['0']['#']);
|
||||
|
||||
//We have to recode the userid field
|
||||
$user = backup_getid($restore->backup_unique_code,"user",$scotrack->userid);
|
||||
if (!empty($user)) {
|
||||
$scotrack->userid = $user->new_id;
|
||||
}
|
||||
|
||||
//We have to recode the scoid field
|
||||
$sco = backup_getid($restore->backup_unique_code,"scorm_scoes",$scotrack->scoid);
|
||||
if (!empty($sco)) {
|
||||
$scotrack->scoid = $sco->new_id;
|
||||
}
|
||||
|
||||
//The structure is equal to the db, so insert the scorm_scoes_track
|
||||
$newid = $DB->insert_record ("scorm_scoes_track",$scotrack);
|
||||
}
|
||||
$pos++;
|
||||
}
|
||||
|
||||
//Do some output
|
||||
if (($i+1) % 50 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 1000 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function copies the scorm related info from backup temp dir to course moddata folder,
|
||||
//creating it if needed
|
||||
function scorm_restore_files ($package, $restore) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$status = true;
|
||||
$todo = false;
|
||||
$moddata_path = "";
|
||||
$scorm_path = "";
|
||||
$temp_path = "";
|
||||
|
||||
//First, we check to "course_id" exists and create is as necessary
|
||||
//in CFG->dataroot
|
||||
$dest_dir = $CFG->dataroot."/".$restore->course_id;
|
||||
$status = check_dir_exists($dest_dir,true);
|
||||
|
||||
//First, locate course's moddata directory
|
||||
$moddata_path = $CFG->dataroot."/".$restore->course_id."/".$CFG->moddata;
|
||||
|
||||
//Check it exists and create it
|
||||
$status = check_dir_exists($moddata_path,true);
|
||||
|
||||
//Now, locate scorm directory
|
||||
if ($status) {
|
||||
$scorm_path = $moddata_path."/scorm";
|
||||
//Check it exists and create it
|
||||
$status = check_dir_exists($scorm_path,true);
|
||||
}
|
||||
|
||||
//Now locate the temp dir we are restoring from
|
||||
if ($status) {
|
||||
$temp_path = $CFG->dataroot."/temp/backup/".$restore->backup_unique_code.
|
||||
"/moddata/scorm/".$package->datadir;
|
||||
//Check it exists
|
||||
if (is_dir($temp_path)) {
|
||||
$todo = true;
|
||||
}
|
||||
}
|
||||
|
||||
//If todo, we create the neccesary dirs in course moddata/scorm
|
||||
if ($status and $todo) {
|
||||
//Make scorm package directory path
|
||||
$this_scorm_path = $scorm_path."/".$package->id;
|
||||
$status = backup_copy_file($temp_path, $this_scorm_path);
|
||||
}
|
||||
|
||||
return $status;
|
||||
}
|
||||
|
||||
//Return a content decoded to support interactivities linking. Every module
|
||||
//should have its own. They are called automatically from
|
||||
//scorm_decode_content_links_caller() function in each module
|
||||
//in the restore process
|
||||
function scorm_decode_content_links ($content,$restore) {
|
||||
|
||||
global $CFG;
|
||||
|
||||
$result = $content;
|
||||
|
||||
//Link to the list of scorms
|
||||
|
||||
$searchstring='/\$@(SCORMINDEX)\*([0-9]+)@\$/';
|
||||
//We look for it
|
||||
preg_match_all($searchstring,$content,$foundset);
|
||||
//If found, then we are going to look for its new id (in backup tables)
|
||||
if ($foundset[0]) {
|
||||
//print_object($foundset); //Debug
|
||||
//Iterate over foundset[2]. They are the old_ids
|
||||
foreach($foundset[2] as $old_id) {
|
||||
//We get the needed variables here (course id)
|
||||
$rec = backup_getid($restore->backup_unique_code,"course",$old_id);
|
||||
//Personalize the searchstring
|
||||
$searchstring='/\$@(SCORMINDEX)\*('.$old_id.')@\$/';
|
||||
//If it is a link to this course, update the link to its new location
|
||||
if($rec->new_id) {
|
||||
//Now replace it
|
||||
$result= preg_replace($searchstring,$CFG->wwwroot.'/mod/scorm/index.php?id='.$rec->new_id,$result);
|
||||
} else {
|
||||
//It's a foreign link so leave it as original
|
||||
$result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/scorm/index.php?id='.$old_id,$result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Link to scorm view by moduleid
|
||||
|
||||
$searchstring='/\$@(SCORMVIEWBYID)\*([0-9]+)@\$/';
|
||||
//We look for it
|
||||
preg_match_all($searchstring,$result,$foundset);
|
||||
//If found, then we are going to look for its new id (in backup tables)
|
||||
if ($foundset[0]) {
|
||||
//print_object($foundset); //Debug
|
||||
//Iterate over foundset[2]. They are the old_ids
|
||||
foreach($foundset[2] as $old_id) {
|
||||
//We get the needed variables here (course_modules id)
|
||||
$rec = backup_getid($restore->backup_unique_code,"course_modules",$old_id);
|
||||
//Personalize the searchstring
|
||||
$searchstring='/\$@(SCORMVIEWBYID)\*('.$old_id.')@\$/';
|
||||
//If it is a link to this course, update the link to its new location
|
||||
if($rec->new_id) {
|
||||
//Now replace it
|
||||
$result= preg_replace($searchstring,$CFG->wwwroot.'/mod/scorm/view.php?id='.$rec->new_id,$result);
|
||||
} else {
|
||||
//It's a foreign link so leave it as original
|
||||
$result= preg_replace($searchstring,$restore->original_wwwroot.'/mod/scorm/view.php?id='.$old_id,$result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
//This function makes all the necessary calls to xxxx_decode_content_links()
|
||||
//function in each module, passing them the desired contents to be decoded
|
||||
//from backup format to destination site/course in order to mantain inter-activities
|
||||
//working in the backup/restore process. It's called from restore_decode_content_links()
|
||||
//function in restore process
|
||||
function scorm_decode_content_links_caller($restore) {
|
||||
global $CFG;
|
||||
$status = true;
|
||||
|
||||
if ($scorms = $DB->get_records('scorm', array('course'=>$restore->course_id), '', "id,intro")) {
|
||||
|
||||
$i = 0; //Counter to send some output to the browser to avoid timeouts
|
||||
foreach ($scorms as $scorm) {
|
||||
//Increment counter
|
||||
$i++;
|
||||
$content = $scorm->intro;
|
||||
$result = restore_decode_content_links_worker($content,$restore);
|
||||
|
||||
if ($result != $content) {
|
||||
//Update record
|
||||
$scorm->intro = $result;
|
||||
$status = $DB->update_record("scorm",$scorm);
|
||||
if (debugging()) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo '<br /><hr />'.s($content).'<br />changed to<br />'.s($result).'<hr /><br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
//Do some output
|
||||
if (($i+1) % 5 == 0) {
|
||||
if (!defined('RESTORE_SILENTLY')) {
|
||||
echo ".";
|
||||
if (($i+1) % 100 == 0) {
|
||||
echo "<br />";
|
||||
}
|
||||
}
|
||||
backup_flush(300);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
//This function returns a log record with all the necessay transformations
|
||||
//done. It's used by restore_log_module() to restore modules log.
|
||||
|
Loading…
x
Reference in New Issue
Block a user