Skip to content
Browse files

uses 4-spaces (Moodle standard) instead of tabs for code indenting

  • Loading branch information...
1 parent 43b4804 commit 47edd30ca7e48d8b60fc6b17b99b1c1b59bc288d gbateson committed
Showing with 687 additions and 681 deletions.
  1. +302 −301 mod/hotpot/backuplib.php
  2. +385 −380 mod/hotpot/restorelib.php
View
603 mod/hotpot/backuplib.php
@@ -1,312 +1,313 @@
<?PHP //$Id$
- //This php script contains all the stuff to backup/restore
- //quiz mods
- //-----------------------------------------------------------
- // This is the "graphical" structure of the hotpot mod:
- //-----------------------------------------------------------
- //
- // hotpot
- // (CL, pk->id,
- // fk->course, files)
- // |
- // +--------------+---------------+
- // | |
- // hotpot_attempts hotpot_questions
- // (UL, pk->id, (UL, pk->id,
- // fk->hotpot) fk->hotpot, text)
- // | | |
- // +-------------------+----------+ |
- // | | |
- // hotpot_details hotpot_responses |
- // (UL, pk->id, (UL, pk->id, |
- // fk->attempt) fk->attempt, question, |
- // correct, wrong, ignored) |
- // | |
- // +-------+-------+
- // |
- // hotpot_strings
- // (UL, pk->id)
- //
- // 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 hotpot_backup_mods($bf, $preferences) {
- global $CFG;
+ //This php script contains all the stuff to backup/restore
+ //quiz mods
+ //-----------------------------------------------------------
+ // This is the "graphical" structure of the hotpot mod:
+ //-----------------------------------------------------------
+ //
+ // hotpot
+ // (CL, pk->id,
+ // fk->course, files)
+ // |
+ // +--------------+---------------+
+ // | |
+ // hotpot_attempts hotpot_questions
+ // (UL, pk->id, (UL, pk->id,
+ // fk->hotpot) fk->hotpot, text)
+ // | | |
+ // +-------------------+----------+ |
+ // | | |
+ // hotpot_details hotpot_responses |
+ // (UL, pk->id, (UL, pk->id, |
+ // fk->attempt) fk->attempt, question, |
+ // correct, wrong, ignored) |
+ // | |
+ // +-------+-------+
+ // |
+ // hotpot_strings
+ // (UL, pk->id)
+ //
+ // 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 hotpot_backup_mods($bf, $preferences) {
+ global $CFG;
- $status = true;
+ $status = true;
- //Iterate over hotpot table
- $hotpots = get_records ("hotpot","course",$preferences->backup_course,"id");
- if ($hotpots) {
- foreach ($hotpots as $hotpot) {
+ //Iterate over hotpot table
+ $hotpots = get_records ("hotpot","course",$preferences->backup_course,"id");
+ if ($hotpots) {
+ foreach ($hotpots as $hotpot) {
if (backup_mod_selected($preferences,'hotpot',$hotpot->id)) {
- $status = hotpot_backup_one_mod($bf,$preferences,$hotpot->id);
- }
- }
- }
- return $status;
- }
+ $status = hotpot_backup_one_mod($bf,$preferences,$hotpot->id);
+ }
+ }
+ }
+ return $status;
+ }
- function hotpot_backup_one_mod($bf, $preferences, $instance = 0) {
- // $bf : resource id for b(ackup) f(ile)
- // $preferences : object containing switches and settings for this backup
- $level = 3;
- $status = true;
- $table = 'hotpot';
- $select = "course=$preferences->backup_course AND id='$instance'";
- $records_tag = '';
- $records_tags = array();
- $record_tag = 'MOD';
- $record_tags = array('MODTYPE'=>'hotpot');
- $excluded_tags = array();
- $more_backup = '';
+ function hotpot_backup_one_mod($bf, $preferences, $instance = 0) {
+ // $bf : resource id for b(ackup) f(ile)
+ // $preferences : object containing switches and settings for this backup
+ $level = 3;
+ $status = true;
+ $table = 'hotpot';
+ $select = "course=$preferences->backup_course AND id='$instance'";
+ $records_tag = '';
+ $records_tags = array();
+ $record_tag = 'MOD';
+ $record_tags = array('MODTYPE'=>'hotpot');
+ $excluded_tags = array();
+ $more_backup = '';
if (backup_userdata_selected($preferences,'hotpot',$instance)) {
- $more_backup .= '$GLOBALS["hotpot_backup_string_ids"] = array();';
- $more_backup .= '$status = hotpot_backup_attempts($bf, $record, $level, $status);';
- $more_backup .= '$status = hotpot_backup_questions($bf, $record, $level, $status);';
- $more_backup .= '$status = hotpot_backup_strings($bf, $record, $level, $status);';
- $more_backup .= 'unset($GLOBALS["hotpot_backup_string_ids"]);'; // tidy up
- }
- return hotpot_backup_records(
- $bf, $status, $level,
- $table, $select,
- $records_tag, $records_tags,
- $record_tag, $record_tags,
- $excluded_tags, $more_backup
- );
- }
- function hotpot_backup_attempts($bf, &$parent, $level, $status) {
- // $parent is a reference to a hotpot record
- $table = 'hotpot_attempts';
- $select = "hotpot=$parent->id";
- $records_tag = 'ATTEMPT_DATA';
- $records_tags = array();
- $record_tag = 'ATTEMPT';
- $record_tags = array();
- $more_backup = '';
- $more_backup .= 'hotpot_backup_details($bf, $record, $level, $status);';
- $more_backup .= 'hotpot_backup_responses($bf, $record, $level, $status);';
- $excluded_tags = array('hotpot');
- return hotpot_backup_records(
- $bf, $status, $level,
- $table, $select,
- $records_tag, $records_tags,
- $record_tag, $record_tags,
- $excluded_tags, $more_backup
- );
- }
- function hotpot_backup_details($bf, &$parent, $level, $status) {
- // $parent is a reference to an attempt record
- $table = 'hotpot_details';
- $select = "attempt=$parent->id";
- $records_tag = '';
- $records_tags = array();
- $record_tag = '';
- $record_tags = array();
- $more_backup = '';
- $excluded_tags = array('id','attempt');
- return hotpot_backup_records(
- $bf, $status, $level,
- $table, $select,
- $records_tag, $records_tags,
- $record_tag, $record_tags,
- $excluded_tags, $more_backup
- );
- }
- function hotpot_backup_responses($bf, &$parent, $level, $status) {
- // $parent is a reference to an attempt record
- $table = 'hotpot_responses';
- $select = "attempt=$parent->id";
- $records_tag = 'RESPONSE_DATA';
- $records_tags = array();
- $record_tag = 'RESPONSE';
- $record_tags = array();
- $more_backup = 'hotpot_backup_string_ids($record, array("correct","wrong","ignored"));';
- $excluded_tags = array('id','attempt');
- return hotpot_backup_records(
- $bf, $status, $level,
- $table, $select,
- $records_tag, $records_tags,
- $record_tag, $record_tags,
- $excluded_tags, $more_backup
- );
- }
- function hotpot_backup_questions($bf, &$parent, $level, $status) {
- // $parent is a reference to an hotpot record
- $table = 'hotpot_questions';
- $select = "hotpot=$parent->id";
- $records_tag = 'QUESTION_DATA';
- $records_tags = array();
- $record_tag = 'QUESTION';
- $record_tags = array();
- $more_backup = 'hotpot_backup_string_ids($record, array("text"));';
- $excluded_tags = array('hotpot');
- return hotpot_backup_records(
- $bf, $status, $level,
- $table, $select,
- $records_tag, $records_tags,
- $record_tag, $record_tags,
- $excluded_tags, $more_backup
- );
- }
- function hotpot_backup_string_ids(&$record, $fields) {
- // as the questions and responses tables are backed up
- // this function is called to store the ids of strings.
- // The string ids are used later by "hotpot_backup_strings"
- // $GLOBALS['hotpot_backup_string_ids'] was initialized in "hotpot_backup_mods"
- // store the ids of strings used in this $record's $fields
- foreach ($fields as $field) {
- if (empty($record->$field)) {
- // do nothing
- } else {
- $value = $record->$field;
- $ids = explode(',', "$value");
- foreach ($ids as $id) {
- if (empty($id)) {
- // do nothing
- } else {
- $GLOBALS['hotpot_backup_string_ids'][$id] = true;
- }
- }
- }
- }
- }
- function hotpot_backup_strings($bf, $record, $level, $status) {
- // This functions backups the strings used
- // in the question and responses for a single hotpot activity
- // The ids of the strings were stored by "hotpot_backup_string_ids"
- // $GLOBALS['hotpot_backup_string_ids'] was initialized in "hotpot_backup_mods"
- // retrieve $ids of strings to be backed up
- $ids = array_keys($GLOBALS['hotpot_backup_string_ids']);
- if (empty($ids)) {
- // no strings to backup
- } else {
- sort($ids);
- $ids = implode(',', $ids);
- $table = 'hotpot_strings';
- $select = "id IN ($ids)";
- $records_tag = 'STRING_DATA';
- $records_tags = array();
- $record_tag = 'STRING';
- $record_tags = array();
- $more_backup = '';
- $excluded_tags = array('');
- $status = hotpot_backup_records(
- $bf, $status, $level,
- $table, $select,
- $records_tag, $records_tags,
- $record_tag, $record_tags,
- $excluded_tags, $more_backup
- );
- }
- return $status;
- }
- function hotpot_backup_records(&$bf, $status, $level, $table, $select, $records_tag, $records_tags, $record_tag, $record_tags, $excluded_tags, $more_backup) {
- // general purpose backup function
- // $bf : resource id of backup file
- // $status : current status of backup (true or false)
- // $level : current depth level in the backup XML tree
- // $table : table from which records will be selected and backed up
- // $select : SQL selection string
- // $records_tag : optional XML tag which starts a group of records (and descends a level)
- // $records_tags : optional XML tags to be inserted at the start of a group of records
- // $record_tag : optional XML tag which starts a record (and descends a level)
- // $record_tags : optional XML tags to be inserted at the start of a record
- // $excluded_tags : fields which will NOT be backed up from the records
- // $more_backup : optional PHP code to be eval(uated) for each record
- // If any of the "fwrite" statements fail,
- // no further "fwrite"s will be attempted
- // and the function returns "false".
- // Otherwise, the function returns "true".
- if ($status && ($records = get_records_select($table, $select, 'id'))) {
- // start a group of records
- if ($records_tag) {
- $status = $status && fwrite($bf, start_tag($records_tag, $level, true));
- $level++;
- foreach ($records_tags as $tag) {
- $status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
- }
- }
- foreach ($records as $record) {
- // start a single record
- if ($record_tag) {
- $status = $status && fwrite($bf, start_tag($record_tag, $level, true));
- $level++;
- foreach ($record_tags as $tag=>$value) {
- $status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
- }
- }
- // backup fields in this record
- $tags = get_object_vars($record);
- foreach ($tags as $tag=>$value) {
- if (!is_numeric($tag) && !in_array($tag, $excluded_tags)) {
- $status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
- }
- }
- // backup related records, if required
- if ($more_backup) {
- eval($more_backup);
- }
- // end a single record
- if ($record_tag) {
- $level--;
- $status = $status && fwrite($bf, end_tag($record_tag, $level, true));
- }
- }
- // end a group of records
- if ($records_tag) {
- $level--;
- $status = $status && fwrite($bf, end_tag($records_tag, $level, true));
- }
- }
- return $status;
- }
- ////Return an array of info (name, value)
- function hotpot_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 += hotpot_check_backup_mods_instances($instance,$backup_unique_code);
- }
- return $info;
- }
+ $more_backup .= '$GLOBALS["hotpot_backup_string_ids"] = array();';
+ $more_backup .= '$status = hotpot_backup_attempts($bf, $record, $level, $status);';
+ $more_backup .= '$status = hotpot_backup_questions($bf, $record, $level, $status);';
+ $more_backup .= '$status = hotpot_backup_strings($bf, $record, $level, $status);';
+ $more_backup .= 'unset($GLOBALS["hotpot_backup_string_ids"]);'; // tidy up
+ }
+ return hotpot_backup_records(
+ $bf, $status, $level,
+ $table, $select,
+ $records_tag, $records_tags,
+ $record_tag, $record_tags,
+ $excluded_tags, $more_backup
+ );
+ }
+ function hotpot_backup_attempts($bf, &$parent, $level, $status) {
+ // $parent is a reference to a hotpot record
+ $table = 'hotpot_attempts';
+ $select = "hotpot=$parent->id";
+ $records_tag = 'ATTEMPT_DATA';
+ $records_tags = array();
+ $record_tag = 'ATTEMPT';
+ $record_tags = array();
+ $more_backup = '';
+ $more_backup .= 'hotpot_backup_details($bf, $record, $level, $status);';
+ $more_backup .= 'hotpot_backup_responses($bf, $record, $level, $status);';
+ $excluded_tags = array('hotpot');
+ return hotpot_backup_records(
+ $bf, $status, $level,
+ $table, $select,
+ $records_tag, $records_tags,
+ $record_tag, $record_tags,
+ $excluded_tags, $more_backup
+ );
+ }
+ function hotpot_backup_details($bf, &$parent, $level, $status) {
+ // $parent is a reference to an attempt record
+ $table = 'hotpot_details';
+ $select = "attempt=$parent->id";
+ $records_tag = '';
+ $records_tags = array();
+ $record_tag = '';
+ $record_tags = array();
+ $more_backup = '';
+ $excluded_tags = array('id','attempt');
+ return hotpot_backup_records(
+ $bf, $status, $level,
+ $table, $select,
+ $records_tag, $records_tags,
+ $record_tag, $record_tags,
+ $excluded_tags, $more_backup
+ );
+ }
+ function hotpot_backup_responses($bf, &$parent, $level, $status) {
+ // $parent is a reference to an attempt record
+ $table = 'hotpot_responses';
+ $select = "attempt=$parent->id";
+ $records_tag = 'RESPONSE_DATA';
+ $records_tags = array();
+ $record_tag = 'RESPONSE';
+ $record_tags = array();
+ $more_backup = 'hotpot_backup_string_ids($record, array("correct","wrong","ignored"));';
+ $excluded_tags = array('id','attempt');
+ return hotpot_backup_records(
+ $bf, $status, $level,
+ $table, $select,
+ $records_tag, $records_tags,
+ $record_tag, $record_tags,
+ $excluded_tags, $more_backup
+ );
+ }
+ function hotpot_backup_questions($bf, &$parent, $level, $status) {
+ // $parent is a reference to an hotpot record
+ $table = 'hotpot_questions';
+ $select = "hotpot=$parent->id";
+ $records_tag = 'QUESTION_DATA';
+ $records_tags = array();
+ $record_tag = 'QUESTION';
+ $record_tags = array();
+ $more_backup = 'hotpot_backup_string_ids($record, array("text"));';
+ $excluded_tags = array('hotpot');
+ return hotpot_backup_records(
+ $bf, $status, $level,
+ $table, $select,
+ $records_tag, $records_tags,
+ $record_tag, $record_tags,
+ $excluded_tags, $more_backup
+ );
+ }
+ function hotpot_backup_string_ids(&$record, $fields) {
+ // as the questions and responses tables are backed up
+ // this function is called to store the ids of strings.
+ // The string ids are used later by "hotpot_backup_strings"
+ // $GLOBALS['hotpot_backup_string_ids'] was initialized in "hotpot_backup_mods"
+ // store the ids of strings used in this $record's $fields
+ foreach ($fields as $field) {
+ if (empty($record->$field)) {
+ // do nothing
+ } else {
+ $value = $record->$field;
+ $ids = explode(',', "$value");
+ foreach ($ids as $id) {
+ if (empty($id)) {
+ // do nothing
+ } else {
+ $GLOBALS['hotpot_backup_string_ids'][$id] = true;
+ }
+ }
+ }
+ }
+ }
+ function hotpot_backup_strings($bf, $record, $level, $status) {
+ // This functions backups the strings used
+ // in the question and responses for a single hotpot activity
+ // The ids of the strings were stored by "hotpot_backup_string_ids"
+ // $GLOBALS['hotpot_backup_string_ids'] was initialized in "hotpot_backup_mods"
+ // retrieve $ids of strings to be backed up
+ $ids = array_keys($GLOBALS['hotpot_backup_string_ids']);
+ if (empty($ids)) {
+ // no strings to backup
+ } else {
+ sort($ids);
+ $ids = implode(',', $ids);
+ $table = 'hotpot_strings';
+ $select = "id IN ($ids)";
+ $records_tag = 'STRING_DATA';
+ $records_tags = array();
+ $record_tag = 'STRING';
+ $record_tags = array();
+ $more_backup = '';
+ $excluded_tags = array('');
+ $status = hotpot_backup_records(
+ $bf, $status, $level,
+ $table, $select,
+ $records_tag, $records_tags,
+ $record_tag, $record_tags,
+ $excluded_tags, $more_backup
+ );
+ }
+ return $status;
+ }
+ function hotpot_backup_records(&$bf, $status, $level, $table, $select, $records_tag, $records_tags, $record_tag, $record_tags, $excluded_tags, $more_backup) {
+ // general purpose backup function
+ // $bf : resource id of backup file
+ // $status : current status of backup (true or false)
+ // $level : current depth level in the backup XML tree
+ // $table : table from which records will be selected and backed up
+ // $select : SQL selection string
+ // $records_tag : optional XML tag which starts a group of records (and descends a level)
+ // $records_tags : optional XML tags to be inserted at the start of a group of records
+ // $record_tag : optional XML tag which starts a record (and descends a level)
+ // $record_tags : optional XML tags to be inserted at the start of a record
+ // $excluded_tags : fields which will NOT be backed up from the records
+ // $more_backup : optional PHP code to be eval(uated) for each record
+ // If any of the "fwrite" statements fail,
+ // no further "fwrite"s will be attempted
+ // and the function returns "false".
+ // Otherwise, the function returns "true".
+ if ($status && ($records = get_records_select($table, $select, 'id'))) {
+ // start a group of records
+ if ($records_tag) {
+ $status = $status && fwrite($bf, start_tag($records_tag, $level, true));
+ $level++;
+ foreach ($records_tags as $tag) {
+ $status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
+ }
+ }
+ foreach ($records as $record) {
+ // start a single record
+ if ($record_tag) {
+ $status = $status && fwrite($bf, start_tag($record_tag, $level, true));
+ $level++;
+ foreach ($record_tags as $tag=>$value) {
+ $status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
+ }
+ }
+ // backup fields in this record
+ $tags = get_object_vars($record);
+ foreach ($tags as $tag=>$value) {
+ if (!is_numeric($tag) && !in_array($tag, $excluded_tags)) {
+ $status = $status && fwrite($bf, full_tag($tag, $level, false, $value));
+ }
+ }
+ // backup related records, if required
+ if ($more_backup) {
+ eval($more_backup);
+ }
+ // end a single record
+ if ($record_tag) {
+ $level--;
+ $status = $status && fwrite($bf, end_tag($record_tag, $level, true));
+ }
+ }
+ // end a group of records
+ if ($records_tag) {
+ $level--;
+ $status = $status && fwrite($bf, end_tag($records_tag, $level, true));
+ }
+ }
+ return $status;
+ }
+ ////Return an array of info (name, value)
+ function hotpot_check_backup_mods($course, $user_data=false, $backup_unique_code, $instances=null) {
+ global $CFG;
+ $info = array();
+ if (isset($instances) && is_array($instances) && count($instances)) {
+ foreach ($instances as $id => $instance) {
+ $info += hotpot_check_backup_mods_instances($instance,$backup_unique_code);
+ }
+ } else {
+ // the course data
+ $info[0][0] = get_string('modulenameplural','hotpot');
+ $info[0][1] = count_records('hotpot', 'course', $course);
- // the course data
- $info[0][0] = get_string('modulenameplural','hotpot');
- $info[0][1] = count_records('hotpot', 'course', $course);
- // the user_data, if requested
- if ($user_data) {
- global $CFG;
- $table = "{$CFG->prefix}hotpot h, {$CFG->prefix}hotpot_attempts a";
- $select = "h.course = $course AND h.id = a.hotpot";
- $info[1][0] = get_string('attempts', 'quiz');
- $info[1][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
- }
- return $info;
- }
+ // the user_data, if requested
+ if ($user_data) {
+ $table = "{$CFG->prefix}hotpot h, {$CFG->prefix}hotpot_attempts a";
+ $select = "h.course = $course AND h.id = a.hotpot";
- ////Return an array of info (name, value)
- function hotpot_check_backup_mods_instances($instance,$backup_unique_code) {
+ $info[1][0] = get_string('attempts', 'quiz');
+ $info[1][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
+ }
+ }
+ return $info;
+ }
- // the course data
- $info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
- $info[$instance->id.'0'][1] = '';
+ ////Return an array of info (name, value)
+ function hotpot_check_backup_mods_instances($instance,$backup_unique_code) {
+ global $CFG;
+ $info = array();
- // the user_data, if requested
- if (!empty($instance->userdata)) {
- global $CFG;
- $table = "{$CFG->prefix}hotpot_attempts a";
- $select = "a.hotpot = $instance->id";
-
- $info[$instance->id.'1'][0] = get_string('attempts', 'quiz');
- $info[$instance->id.'1'][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
- }
-
- return $info;
- }
+ // the course data
+ $info[$instance->id.'0'][0] = '<b>'.$instance->name.'</b>';
+ $info[$instance->id.'0'][1] = '';
+
+ // the user_data, if requested
+ if (!empty($instance->userdata)) {
+ $table = "{$CFG->prefix}hotpot_attempts a";
+ $select = "a.hotpot = $instance->id";
+
+ $info[$instance->id.'1'][0] = get_string('attempts', 'quiz');
+ $info[$instance->id.'1'][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
+ }
+ return $info;
+ }
?>
View
765 mod/hotpot/restorelib.php
@@ -1,303 +1,308 @@
<?PHP //$Id$
//This php script contains all the stuff to restore hotpot mods
- //-----------------------------------------------------------
- // This is the "graphical" structure of the hotpot mod:
- //-----------------------------------------------------------
- //
- // hotpot
- // (CL, pk->id,
- // fk->course, files)
- // |
- // +--------------+---------------+
- // | |
- // hotpot_attempts hotpot_questions
- // (UL, pk->id, (UL, pk->id,
- // fk->hotpot) fk->hotpot, text)
- // | | |
- // +-------------------+----------+ |
- // | | |
- // hotpot_details hotpot_responses |
- // (UL, pk->id, (UL, pk->id, |
- // fk->attempt) fk->attempt, question, |
- // correct, wrong, ignored) |
- // | |
- // +-------+-------+
- // |
- // hotpot_strings
- // (UL, pk->id)
- //
- // 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
- //
- //-----------------------------------------------------------
+ //-----------------------------------------------------------
+ // This is the "graphical" structure of the hotpot mod:
+ //-----------------------------------------------------------
+ //
+ // hotpot
+ // (CL, pk->id,
+ // fk->course, files)
+ // |
+ // +--------------+---------------+
+ // | |
+ // hotpot_attempts hotpot_questions
+ // (UL, pk->id, (UL, pk->id,
+ // fk->hotpot) fk->hotpot, text)
+ // | | |
+ // +-------------------+----------+ |
+ // | | |
+ // hotpot_details hotpot_responses |
+ // (UL, pk->id, (UL, pk->id, |
+ // fk->attempt) fk->attempt, question, |
+ // correct, wrong, ignored) |
+ // | |
+ // +-------+-------+
+ // |
+ // hotpot_strings
+ // (UL, pk->id)
+ //
+ // 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
+ //
+ //-----------------------------------------------------------
+
require_once ("$CFG->dirroot/mod/hotpot/lib.php");
-//This function restores a single hotpot activity
+
function hotpot_restore_mods($mod, $restore) {
- // this function is called by "restore_create_modules" (in "backup/restorelib.php")
- // which is called by "backup/restore_execute.html" (included by "backup/restore.php")
- // $mod is an object
- // id : id field in 'modtype' table
- // modtype : 'hotpot'
- // $restore is an object
- // backup_unique_code : xxxxxxxxxx
- // file : '/full/path/to/backupfile.zip'
- // mods : an array of $modinfo's (see below)
- // restoreto : 0=existing course (replace), 1=existing course (append), 2=new course
- // users : 0=all, 1=course, 2=none
- // logs : 0=no, 1=yes
- // user_files : 0=no, 1=yes
- // course_files : 0=no, 1=yes
- // course_id : id of course into which data is to be restored
- // deleting : true if 'restoreto'==0, otherwise false
- // original_wwwroot : 'http://your.server.com/moodle'
- // $modinfo is an array
- // 'modname' : array( 'restore'=> 0=no 1=yes, 'userinfo' => 0=no 1=yes)
- $status = true;
- // get course module data this hotpot activity
- $data = backup_getid($restore->backup_unique_code, 'hotpot', $mod->id);
- if ($data) {
- // $data is an object
- // backup_code => xxxxxxxxxx,
- // table_name => 'hotpot',
- // old_id => xxx,
- // new_id => NULL,
- // info => xml tree array of info backed up for this hotpot activity
- $xml = &$data->info['MOD']['#'];
- $table = 'hotpot';
- $foreign_keys = array('course' => $restore->course_id);
- $more_restore = '';
- // print a message after each hotpot is backed up
- if (!defined('RESTORE_SILENTLY')) {
- $more_restore .= 'print "<li>".get_string("modulename", "hotpot")." &quot;".$record->name."&quot;</li>";';
- }
- $more_restore .= 'backup_flush(300);';
+ //This function restores a single hotpot activity
+
+ // This function is called by "restore_create_modules" (in "backup/restorelib.php")
+ // which is called by "backup/restore_execute.html" (included by "backup/restore.php")
+ // $mod is an object
+ // id : id field in 'modtype' table
+ // modtype : 'hotpot'
+ // $restore is an object
+ // backup_unique_code : xxxxxxxxxx
+ // file : '/full/path/to/backupfile.zip'
+ // mods : an array of $modinfo's (see below)
+ // restoreto : 0=existing course (replace), 1=existing course (append), 2=new course
+ // users : 0=all, 1=course, 2=none
+ // logs : 0=no, 1=yes
+ // user_files : 0=no, 1=yes
+ // course_files : 0=no, 1=yes
+ // course_id : id of course into which data is to be restored
+ // deleting : true if 'restoreto'==0, otherwise false
+ // original_wwwroot : 'http://your.server.com/moodle'
+ // $modinfo is an array
+ // 'modname' : array( 'restore'=> 0=no 1=yes, 'userinfo' => 0=no 1=yes)
+
+ $status = true;
+
+ // get course module data this hotpot activity
+ $data = backup_getid($restore->backup_unique_code, 'hotpot', $mod->id);
+ if ($data) {
+ // $data is an object
+ // backup_code => xxxxxxxxxx,
+ // table_name => 'hotpot',
+ // old_id => xxx,
+ // new_id => NULL,
+ // info => xml tree array of info backed up for this hotpot activity
+ $xml = &$data->info['MOD']['#'];
+ $table = 'hotpot';
+ $foreign_keys = array('course' => $restore->course_id);
+ $more_restore = '';
+ // print a message after each hotpot is backed up
+ if (!defined('RESTORE_SILENTLY')) {
+ $more_restore .= 'print "<li>".get_string("modulename", "hotpot")." &quot;".$record->name."&quot;</li>";';
+ }
+ $more_restore .= 'backup_flush(300);';
if (restore_userdata_selected($restore,'hotpot',$mod->id)) {
- if (isset($xml["STRING_DATA"]) && isset($xml["QUESTION_DATA"])) {
- // HotPot v2.1+
- $more_restore .= '$status = hotpot_restore_strings($restore, $status, $xml, $record);';
- $more_restore .= '$status = hotpot_restore_questions($restore, $status, $xml, $record);';
- $more_restore .= '$status = hotpot_restore_attempts($restore, $status, $xml, $record);';
- } else {
- // HotPot v2.0.x (regenerate questions, responses and strings from attempt details)
- $more_restore .= '$status = hotpot_restore_attempts($restore, $status, $xml, $record, true);';
- }
- }
- $status = hotpot_restore_records(
- $restore, $status, $xml, $table, $foreign_keys, $more_restore
- );
- }
- return $status;
+ if (isset($xml["STRING_DATA"]) && isset($xml["QUESTION_DATA"])) {
+ // HotPot v2.1+
+ $more_restore .= '$status = hotpot_restore_strings($restore, $status, $xml, $record);';
+ $more_restore .= '$status = hotpot_restore_questions($restore, $status, $xml, $record);';
+ $more_restore .= '$status = hotpot_restore_attempts($restore, $status, $xml, $record);';
+ } else {
+ // HotPot v2.0.x (regenerate questions, responses and strings from attempt details)
+ $more_restore .= '$status = hotpot_restore_attempts($restore, $status, $xml, $record, true);';
+ }
+ }
+ $status = hotpot_restore_records(
+ $restore, $status, $xml, $table, $foreign_keys, $more_restore
+ );
+ }
+ return $status;
}
function hotpot_restore_strings(&$restore, $status, &$xml, &$record) {
- // $xml is an XML tree for a hotpot record
- // $record is the newly added hotpot record
- return hotpot_restore_records(
- $restore, $status, $xml, 'hotpot_strings', array(), '', 'STRING_DATA', 'STRING', 'string'
- );
+ // $xml is an XML tree for a hotpot record
+ // $record is the newly added hotpot record
+ return hotpot_restore_records(
+ $restore, $status, $xml, 'hotpot_strings', array(), '', 'STRING_DATA', 'STRING', 'string'
+ );
}
function hotpot_restore_questions(&$restore, $status, &$xml, &$record) {
- // $xml is an XML tree for a hotpot record
- // $record is the newly added hotpot record
- $foreignkeys = array(
- 'hotpot'=>$record->id,
- 'text'=>'hotpot_strings'
- );
- return hotpot_restore_records(
- $restore, $status, $xml, 'hotpot_questions', $foreignkeys, '', 'QUESTION_DATA', 'QUESTION'
- );
+ // $xml is an XML tree for a hotpot record
+ // $record is the newly added hotpot record
+ $foreignkeys = array(
+ 'hotpot'=>$record->id,
+ 'text'=>'hotpot_strings'
+ );
+ return hotpot_restore_records(
+ $restore, $status, $xml, 'hotpot_questions', $foreignkeys, '', 'QUESTION_DATA', 'QUESTION'
+ );
}
function hotpot_restore_attempts(&$restore, $status, &$xml, &$record, $hotpot_v20=false) {
- // $xml is an XML tree for a hotpot record
- // $record is the newly added hotpot record
- $foreignkeys = array(
- 'userid'=>'user',
- 'hotpot'=>$record->id,
- );
- $more_restore = '';
- $more_restore .= 'hotpot_restore_details($restore, $status, $xml, $record);';
- if ($hotpot_v20) {
- // HotPot v2.0.x (regenerate questions and responses from details)
- $more_restore .= '$record->details=stripslashes($record->details);';
- $more_restore .= 'hotpot_add_attempt_details($record);'; // see "hotpot/lib.php"
- } else {
- // HotPot v2.1+
- $more_restore .= '$status = hotpot_restore_responses($restore, $status, $xml, $record);';
- // save clickreportid (to be updated it later)
- $more_restore .= 'if (!empty($record->clickreportid)) {';
- $more_restore .= '$GLOBALS["hotpot_backup_clickreportids"][$record->id]=$record->clickreportid;';
- $more_restore .= '}';
- // initialize global array to store clickreportids
- $GLOBALS["hotpot_backup_clickreportids"] = array();
- }
- $status = hotpot_restore_records(
- $restore, $status, $xml, 'hotpot_attempts', $foreignkeys, $more_restore, 'ATTEMPT_DATA', 'ATTEMPT'
- );
- if ($hotpot_v20) {
- if ($status) {
- global $CFG;
- // based on code in "mod/hotpot/db/update_to_v2.php"
- execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET status=1 WHERE hotpot=$record->id AND timefinish=0 AND score IS NULL", false);
- execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET status=3 WHERE hotpot=$record->id AND timefinish>0 AND score IS NULL", false);
- execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET status=4 WHERE hotpot=$record->id AND timefinish>0 AND score IS NOT NULL", false);
- execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET clickreportid=id WHERE hotpot=$record->id AND clickreportid IS NULL", false);
- }
- } else {
- $status = hotpot_restore_clickreportids($restore, $status);
- unset($GLOBALS["hotpot_backup_clickreportids"]); // tidy up
- }
- return $status;
+ // $xml is an XML tree for a hotpot record
+ // $record is the newly added hotpot record
+ $foreignkeys = array(
+ 'userid'=>'user',
+ 'hotpot'=>$record->id,
+ );
+ $more_restore = '';
+ $more_restore .= 'hotpot_restore_details($restore, $status, $xml, $record);';
+ if ($hotpot_v20) {
+ // HotPot v2.0.x (regenerate questions and responses from details)
+ $more_restore .= '$record->details=stripslashes($record->details);';
+ $more_restore .= 'hotpot_add_attempt_details($record);'; // see "hotpot/lib.php"
+ } else {
+ // HotPot v2.1+
+ $more_restore .= '$status = hotpot_restore_responses($restore, $status, $xml, $record);';
+ // save clickreportid (to be updated it later)
+ $more_restore .= 'if (!empty($record->clickreportid)) {';
+ $more_restore .= '$GLOBALS["hotpot_backup_clickreportids"][$record->id]=$record->clickreportid;';
+ $more_restore .= '}';
+ // initialize global array to store clickreportids
+ $GLOBALS["hotpot_backup_clickreportids"] = array();
+ }
+ $status = hotpot_restore_records(
+ $restore, $status, $xml, 'hotpot_attempts', $foreignkeys, $more_restore, 'ATTEMPT_DATA', 'ATTEMPT'
+ );
+ if ($hotpot_v20) {
+ if ($status) {
+ global $CFG;
+ // based on code in "mod/hotpot/db/update_to_v2.php"
+ execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET status=1 WHERE hotpot=$record->id AND timefinish=0 AND score IS NULL", false);
+ execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET status=3 WHERE hotpot=$record->id AND timefinish>0 AND score IS NULL", false);
+ execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET status=4 WHERE hotpot=$record->id AND timefinish>0 AND score IS NOT NULL", false);
+ execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET clickreportid=id WHERE hotpot=$record->id AND clickreportid IS NULL", false);
+ }
+ } else {
+ $status = hotpot_restore_clickreportids($restore, $status);
+ unset($GLOBALS["hotpot_backup_clickreportids"]); // tidy up
+ }
+ return $status;
}
function hotpot_restore_clickreportids(&$restore, $status) {
- // update clickreport ids, if any
- global $CFG;
- foreach ($GLOBALS["hotpot_backup_clickreportids"] as $id=>$clickreportid) {
- if ($status) {
- $attempt_record = backup_getid($restore->backup_unique_code, 'hotpot_attempts', $clickreportid);
- if ($attempt_record) {
- $new_clickreportid = $attempt_record->new_id;
- $status = execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET clickreportid=$new_clickreportid WHERE id=$id", false);
- } else {
- // New clickreport id could not be found
- if (!defined('RESTORE_SILENTLY')) {
- print "<ul><li>New clickreportid could not be found: attempt id=$id, clickreportid=$clickreportid</li></ul>";
- }
- $status = false;
- }
- }
- }
- return $status;
+ // update clickreport ids, if any
+ global $CFG;
+ foreach ($GLOBALS["hotpot_backup_clickreportids"] as $id=>$clickreportid) {
+ if ($status) {
+ $attempt_record = backup_getid($restore->backup_unique_code, 'hotpot_attempts', $clickreportid);
+ if ($attempt_record) {
+ $new_clickreportid = $attempt_record->new_id;
+ $status = execute_sql("UPDATE {$CFG->prefix}hotpot_attempts SET clickreportid=$new_clickreportid WHERE id=$id", false);
+ } else {
+ // New clickreport id could not be found
+ if (!defined('RESTORE_SILENTLY')) {
+ print "<ul><li>New clickreportid could not be found: attempt id=$id, clickreportid=$clickreportid</li></ul>";
+ }
+ $status = false;
+ }
+ }
+ }
+ return $status;
}
function hotpot_restore_responses(&$restore, $status, &$xml, &$record) {
- // $xml is an XML tree for an attempt record
- // $record is the newly added attempt record
- $foreignkeys = array(
- 'attempt'=>$record->id,
- 'question'=>'hotpot_questions',
- 'correct'=>'hotpot_strings',
- 'wrong'=>'hotpot_strings',
- 'ignored'=>'hotpot_strings'
- );
- return hotpot_restore_records(
- $restore, $status, $xml, 'hotpot_responses', $foreignkeys, '', 'RESPONSE_DATA', 'RESPONSE'
- );
+ // $xml is an XML tree for an attempt record
+ // $record is the newly added attempt record
+ $foreignkeys = array(
+ 'attempt'=>$record->id,
+ 'question'=>'hotpot_questions',
+ 'correct'=>'hotpot_strings',
+ 'wrong'=>'hotpot_strings',
+ 'ignored'=>'hotpot_strings'
+ );
+ return hotpot_restore_records(
+ $restore, $status, $xml, 'hotpot_responses', $foreignkeys, '', 'RESPONSE_DATA', 'RESPONSE'
+ );
}
function hotpot_restore_details(&$restore, $status, &$xml, &$record) {
- // $xml is an XML tree for an attempt record
- // $record is the newly added attempt record
- if (empty($record->details)) {
- $status = true;
- } else {
- unset($details);
- $details->attempt = $record->id;
- $details->details = $record->details;
- if (insert_record('hotpot_details', $details)) {
- $status = true;
- } else {
- if (!defined('RESTORE_SILENTLY')) {
- print "<ul><li>Details record could not be updated: attempt=$record->attempt</li></ul>";
- }
- $status = false;
- }
- }
- return $status;
+ // $xml is an XML tree for an attempt record
+ // $record is the newly added attempt record
+ if (empty($record->details)) {
+ $status = true;
+ } else {
+ unset($details);
+ $details->attempt = $record->id;
+ $details->details = $record->details;
+ if (insert_record('hotpot_details', $details)) {
+ $status = true;
+ } else {
+ if (!defined('RESTORE_SILENTLY')) {
+ print "<ul><li>Details record could not be updated: attempt=$record->attempt</li></ul>";
+ }
+ $status = false;
+ }
+ }
+ return $status;
}
function hotpot_restore_records(&$restore, $status, &$xml, $table, $foreign_keys, $more_restore='', $records_TAG='', $record_TAG='', $secondary_key='') {
// general purpose function to restore a group of records
- // $restore : (see "hotpot_restore_mods" above)
- // $xml : an XML tree (or sub-tree)
- // $records_TAG : (optional) the name of an XML tag which starts a block of records
- // If no $records_TAG is specified, $xml is assumed to be a block of records
- // $record_TAG : (optional) the name of an XML tag which starts a single record
- // If no $record_TAG is specified, the block of records is assumed to be a single record
- // other parameters are explained in "hotpot_restore_record" below
- $i = 0;
- do {
- unset($xml_records);
- if ($records_TAG) {
- if (isset($xml[$records_TAG][$i]['#'])) {
- $xml_records = &$xml[$records_TAG][$i]['#'];
- }
- } else {
- if ($i==0) {
- $xml_records = &$xml;
- }
- }
- if (empty($xml_records)) {
- // do nothing
- } else {
- $ii = 0;
- do {
- unset($xml_record);
- if ($record_TAG) {
- if (isset($xml_records[$record_TAG][$ii]['#'])) {
- $xml_record = &$xml_records[$record_TAG][$ii]['#'];
- }
- } else {
- if ($ii==0) {
- $xml_record = &$xml_records;
- }
- }
- if (empty($xml_record)) {
- // do nothing
- } else {
- $status = hotpot_restore_record(
- $restore, $status, $xml_record, $table, $foreign_keys, $more_restore, $secondary_key
- );
- }
- $ii++;
- } while ($status && isset($xml_record));
- }
- $i++;
- } while ($status && isset($xml_records));
- return $status;
+ // $restore : (see "hotpot_restore_mods" above)
+ // $xml : an XML tree (or sub-tree)
+ // $records_TAG : (optional) the name of an XML tag which starts a block of records
+ // If no $records_TAG is specified, $xml is assumed to be a block of records
+ // $record_TAG : (optional) the name of an XML tag which starts a single record
+ // If no $record_TAG is specified, the block of records is assumed to be a single record
+ // other parameters are explained in "hotpot_restore_record" below
+ $i = 0;
+ do {
+ unset($xml_records);
+ if ($records_TAG) {
+ if (isset($xml[$records_TAG][$i]['#'])) {
+ $xml_records = &$xml[$records_TAG][$i]['#'];
+ }
+ } else {
+ if ($i==0) {
+ $xml_records = &$xml;
+ }
+ }
+ if (empty($xml_records)) {
+ // do nothing
+ } else {
+ $ii = 0;
+ do {
+ unset($xml_record);
+ if ($record_TAG) {
+ if (isset($xml_records[$record_TAG][$ii]['#'])) {
+ $xml_record = &$xml_records[$record_TAG][$ii]['#'];
+ }
+ } else {
+ if ($ii==0) {
+ $xml_record = &$xml_records;
+ }
+ }
+ if (empty($xml_record)) {
+ // do nothing
+ } else {
+ $status = hotpot_restore_record(
+ $restore, $status, $xml_record, $table, $foreign_keys, $more_restore, $secondary_key
+ );
+ }
+ $ii++;
+ } while ($status && isset($xml_record));
+ }
+ $i++;
+ } while ($status && isset($xml_records));
+ return $status;
}
function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys, $more_restore, $secondary_key) {
// general purpose function to restore a single record
- // $restore : (see "hotpot_restore_mods" above)
- // $status : current status of backup (true or false)
- // $xml : XML tree of current record
- // $table : name of Moodle database table to restore to
- // $foreign_keys : array of foreign keys, if any, specifed as $key=>$value
- // $key : the name of a field in the current $record
- // $value : if $value is numeric, then $record->$key is set to $value.
- // Otherwise $value is assumed to be a table name and $record->$key
- // is treated as a comma separated list of ids in that table
- // $more_restore : optional PHP code to be eval(uated) for each record
- // $secondary_key :
- // the name of the secondary key field, if any, in the current $record.
- // If this field is specified, then the current record will only be added
- // if the $record->$secondarykey value does not already exist in $table
- unset($record);
- $TAGS = array_keys($xml);
- foreach ($TAGS as $TAG) {
- $value = $xml[$TAG][0]['#'];
- if (is_string($value)) {
- $tag = strtolower($TAG);
- $record->$tag = backup_todb($value);
- }
- }
- $ok = true;
- foreach ($foreign_keys as $key=>$value) {
- if (is_numeric($value)) {
- $record->$key = $value;
- } else {
- if (empty($record->$key)) {
- $record->$key = NULL;
- } else {
- $key_table = $value;
- $new_ids = array();
- $old_ids = explode(',', $record->$key);
- foreach ($old_ids as $old_id) {
- $key_record = backup_getid($restore->backup_unique_code, $key_table, $old_id);
- if ($key_record) {
- $new_ids[] = $key_record->new_id;
- } else {
- // foreign key could not be updated
- if (!defined('RESTORE_SILENTLY')) {
+ // $restore : (see "hotpot_restore_mods" above)
+ // $status : current status of backup (true or false)
+ // $xml : XML tree of current record
+ // $table : name of Moodle database table to restore to
+ // $foreign_keys : array of foreign keys, if any, specifed as $key=>$value
+ // $key : the name of a field in the current $record
+ // $value : if $value is numeric, then $record->$key is set to $value.
+ // Otherwise $value is assumed to be a table name and $record->$key
+ // is treated as a comma separated list of ids in that table
+ // $more_restore : optional PHP code to be eval(uated) for each record
+ // $secondary_key :
+ // the name of the secondary key field, if any, in the current $record.
+ // If this field is specified, then the current record will only be added
+ // if the $record->$secondarykey value does not already exist in $table
+ unset($record);
+ $TAGS = array_keys($xml);
+ foreach ($TAGS as $TAG) {
+ $value = $xml[$TAG][0]['#'];
+ if (is_string($value)) {
+ $tag = strtolower($TAG);
+ $record->$tag = backup_todb($value);
+ }
+ }
+ $ok = true;
+ foreach ($foreign_keys as $key=>$value) {
+ if (is_numeric($value)) {
+ $record->$key = $value;
+ } else {
+ if (empty($record->$key)) {
+ $record->$key = NULL;
+ } else {
+ $key_table = $value;
+ $new_ids = array();
+ $old_ids = explode(',', $record->$key);
+ foreach ($old_ids as $old_id) {
+ $key_record = backup_getid($restore->backup_unique_code, $key_table, $old_id);
+ if ($key_record) {
+ $new_ids[] = $key_record->new_id;
+ } else {
+ // foreign key could not be updated
+ if (!defined('RESTORE_SILENTLY')) {
print "<ul><li><b>Warning:</b><br>Foreign key could not be updated:<br>";
print "'$key_table' record (old id=$old_id) is missing from backup data<br>";
print "'$table' record ";
@@ -307,112 +312,112 @@ function hotpot_restore_record(&$restore, $status, &$xml, $table, $foreign_keys,
print "was not restored</li></ul>";
}
$ok = false;
- }
- }
- $record->$key = implode(',', $new_ids);
- }
- }
- }
- // check everything is OK so far
- if ($ok && isset($record)) {
- // store old record id, if necessary
- if (isset($record->id)) {
- $record->old_id = $record->id;
- unset($record->id);
- }
- // if there is a secondary key field ...
- if ($secondary_key) {
- // check to see if a record with the same value already exists
- $key_record = get_record($table, $secondary_key, $record->$secondary_key);
- if ($key_record) {
- // set new record id from already existing record
- $record->id = $key_record->id;
- }
- }
- if (empty($record->id)) {
- // add the $record (and get new id)
- $record->id = insert_record ($table, $record);
- }
- // check $record was added (or found)
- if (is_numeric($record->id)) {
- // if there was an old id, save a mapping to the new id
- if (isset($record->old_id)) {
- backup_putid($restore->backup_unique_code, $table, $record->old_id, $record->id);
- }
- } else {
- // failed to add (or find) $record
- if (!defined('RESTORE_SILENTLY')) {
- print "<ul><li>Record could not be added: table=$table</li></ul>";
- }
- $status = false;
- }
- // restore related records, if required
- if ($more_restore) {
- eval($more_restore);
- }
- }
- return $status;
+ }
+ }
+ $record->$key = implode(',', $new_ids);
+ }
+ }
+ }
+ // check everything is OK so far
+ if ($ok && isset($record)) {
+ // store old record id, if necessary
+ if (isset($record->id)) {
+ $record->old_id = $record->id;
+ unset($record->id);
+ }
+ // if there is a secondary key field ...
+ if ($secondary_key) {
+ // check to see if a record with the same value already exists
+ $key_record = get_record($table, $secondary_key, $record->$secondary_key);
+ if ($key_record) {
+ // set new record id from already existing record
+ $record->id = $key_record->id;
+ }
+ }
+ if (empty($record->id)) {
+ // add the $record (and get new id)
+ $record->id = insert_record ($table, $record);
+ }
+ // check $record was added (or found)
+ if (is_numeric($record->id)) {
+ // if there was an old id, save a mapping to the new id
+ if (isset($record->old_id)) {
+ backup_putid($restore->backup_unique_code, $table, $record->old_id, $record->id);
+ }
+ } else {
+ // failed to add (or find) $record
+ if (!defined('RESTORE_SILENTLY')) {
+ print "<ul><li>Record could not be added: table=$table</li></ul>";
+ }
+ $status = false;
+ }
+ // restore related records, if required
+ if ($more_restore) {
+ eval($more_restore);
+ }
+ }
+ 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.
function hotpot_restore_logs($restore, $log) {
- // assume the worst
- $status = false;
- switch ($log->action) {
- case "add":
- case "update":
- case "view":
- if ($log->cmid) {
- //Get the new_id of the module (to recode the info field)
- $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info);
- if ($mod) {
- $log->url = "view.php?id=".$log->cmid;
- $log->info = $mod->new_id;
- $status = true;
- }
- }
- break;
- case "view all":
- $log->url = "index.php?id=".$log->course;
- $status = true;
- break;
- case "report":
- if ($log->cmid) {
- //Get the new_id of the module (to recode the info field)
- $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
- if ($mod) {
- $log->url = "report.php?id=".$log->cmid;
- $log->info = $mod->new_id;
- $status = true;
- }
- }
- break;
- case "attempt":
- case "submit":
- case "review":
- if ($log->cmid) {
- //Get the new_id of the module (to recode the info field)
- $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
- if ($mod) {
- //Extract the attempt id from the url field
- $attemptid = substr(strrchr($log->url,"="),1);
- //Get the new_id of the attempt (to recode the url field)
- $attempt = backup_getid($restore->backup_unique_code,"hotpot_attempts",$attemptid);
- if ($attempt) {
- $log->url = "review.php?id=".$log->cmid."&attempt=".$attempt->new_id;
- $log->info = $mod->new_id;
- $status = true;
- }
- }
- }
- break;
- default:
- // Oops, unknown $log->action
- if (!defined('RESTORE_SILENTLY')) {
- print "<p>action (".$log->module."-".$log->action.") unknown. Not restored</p>";
- }
- break;
- } // end switch
- return $status ? $log : false;
+ // assume the worst
+ $status = false;
+ switch ($log->action) {
+ case "add":
+ case "update":
+ case "view":
+ if ($log->cmid) {
+ //Get the new_id of the module (to recode the info field)
+ $mod = backup_getid($restore->backup_unique_code, $log->module, $log->info);
+ if ($mod) {
+ $log->url = "view.php?id=".$log->cmid;
+ $log->info = $mod->new_id;
+ $status = true;
+ }
+ }
+ break;
+ case "view all":
+ $log->url = "index.php?id=".$log->course;
+ $status = true;
+ break;
+ case "report":
+ if ($log->cmid) {
+ //Get the new_id of the module (to recode the info field)
+ $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
+ if ($mod) {
+ $log->url = "report.php?id=".$log->cmid;
+ $log->info = $mod->new_id;
+ $status = true;
+ }
+ }
+ break;
+ case "attempt":
+ case "submit":
+ case "review":
+ if ($log->cmid) {
+ //Get the new_id of the module (to recode the info field)
+ $mod = backup_getid($restore->backup_unique_code,$log->module,$log->info);
+ if ($mod) {
+ //Extract the attempt id from the url field
+ $attemptid = substr(strrchr($log->url,"="),1);
+ //Get the new_id of the attempt (to recode the url field)
+ $attempt = backup_getid($restore->backup_unique_code,"hotpot_attempts",$attemptid);
+ if ($attempt) {
+ $log->url = "review.php?id=".$log->cmid."&attempt=".$attempt->new_id;
+ $log->info = $mod->new_id;
+ $status = true;
+ }
+ }
+ }
+ break;
+ default:
+ // Oops, unknown $log->action
+ if (!defined('RESTORE_SILENTLY')) {
+ print "<p>action (".$log->module."-".$log->action.") unknown. Not restored</p>";
+ }
+ break;
+ } // end switch
+ return $status ? $log : false;
}
?>

0 comments on commit 47edd30

Please sign in to comment.
Something went wrong with that request. Please try again.