Пример #1
0
function slideshow_captions_restore_mods($old_slideshow_id, $new_slideshow_id, $info, $restore)
{
    global $CFG;
    $status = true;
    //Get the captions array
    $captions = $info['MOD']['#']['CAPTIONS']['0']['#']['CAPTION'];
    //Iterate over captions
    for ($i = 0; $i < sizeof($captions); $i++) {
        $cap_info = $captions[$i];
        //traverse_xmlize($cap_info);                                                                 //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //We'll need this later!!
        $oldid = backup_todb($cap_info['#']['ID']['0']['#']);
        $olduserid = backup_todb($cap_info['#']['USERID']['0']['#']);
        //Now, build the SLIDESHOW_MESSAGES record structure
        $caption->slideshow = $new_slideshow_id;
        $caption->image = backup_todb($cap_info['#']['IMAGE']['0']['#']);
        $caption->title = backup_todb($cap_info['#']['TITLE']['0']['#']);
        $caption->caption = backup_todb($cap_info['#']['CAPTION']['0']['#']);
        //The structure is equal to the db, so insert the slideshow_message
        $newid = insert_record("slideshow_captions", $caption);
        //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;
}
Пример #2
0
function diplome_restore_mods($mod, $restore)
{
    global $CFG;
    $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;
        //Now, build the ACCOUNTING record structure
        $diplome->course = $restore->course_id;
        $diplome->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $diplome->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $diplome->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $diplome->timecreated = time();
        $diplome->timemodified = time();
        //The structure is equal to the db, so insert the label
        $newid = insert_record("diplome", $diplome);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "diplome") . " \"" . format_string(stripslashes($diplome->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #3
0
function label_restore_mods($mod, $restore)
{
    global $CFG;
    $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 LABEL record structure
        $label->course = $restore->course_id;
        $label->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $label->content = backup_todb($info['MOD']['#']['CONTENT']['0']['#']);
        $label->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
        //The structure is equal to the db, so insert the label
        $newid = insert_record("label", $label);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "label") . " \"" . format_string(stripslashes($label->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function lightboxgallery_restore_metadata($galleryid, $info, $restore)
{
    $status = true;
    if (isset($info['MOD']['#']['IMAGEMETAS']['0']['#']['IMAGEMETA'])) {
        $imagemetas = $info['MOD']['#']['IMAGEMETAS']['0']['#']['IMAGEMETA'];
    } else {
        $imagemetas = array();
    }
    for ($i = 0; $i < sizeof($imagemetas); $i++) {
        $sub_info = $imagemetas[$i];
        $oldid = backup_todb($sub_info['#']['ID']['0']['#']);
        $record = new object();
        $record->gallery = $galleryid;
        $record->image = backup_todb($sub_info['#']['IMAGE']['0']['#']);
        $record->metatype = backup_todb($sub_info['#']['METATYPE']['0']['#']);
        $record->description = backup_todb($sub_info['#']['DESCRIPTION']['0']['#']);
        $newid = insert_record('lightboxgallery_image_meta', $record);
        if (($i + 1) % 50 == 0) {
            if (!defined('RESTORE_SILENTLY')) {
                echo '.';
                if (($i + 1) % 1000 == 0) {
                    echo '<br />';
                }
            }
            backup_flush(300);
        }
        if ($newid) {
            backup_putid($restore->backup_unique_code, 'lightboxgallery_image_meta', $oldid, $newid);
        } else {
            $status = false;
        }
    }
    return $status;
}
function tab_restore_mods($mod, $restore)
{
    global $CFG;
    $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 tab record structure
        $tab->course = $restore->course_id;
        $tab->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $tab->tab1 = backup_todb($info['MOD']['#']['TAB1']['0']['#']);
        $tab->tab2 = backup_todb($info['MOD']['#']['TAB2']['0']['#']);
        $tab->tab3 = backup_todb($info['MOD']['#']['TAB3']['0']['#']);
        $tab->tab4 = backup_todb($info['MOD']['#']['TAB4']['0']['#']);
        $tab->tab5 = backup_todb($info['MOD']['#']['TAB5']['0']['#']);
        $tab->tab6 = backup_todb($info['MOD']['#']['TAB6']['0']['#']);
        $tab->tab7 = backup_todb($info['MOD']['#']['TAB7']['0']['#']);
        $tab->tab8 = backup_todb($info['MOD']['#']['TAB8']['0']['#']);
        $tab->tab9 = backup_todb($info['MOD']['#']['TAB9']['0']['#']);
        $tab->tab0 = backup_todb($info['MOD']['#']['TAB0']['0']['#']);
        $tab->tab1content = backup_todb($info['MOD']['#']['TAB1CONTENT']['0']['#']);
        $tab->tab2content = backup_todb($info['MOD']['#']['TAB2CONTENT']['0']['#']);
        $tab->tab3content = backup_todb($info['MOD']['#']['TAB3CONTENT']['0']['#']);
        $tab->tab4content = backup_todb($info['MOD']['#']['TAB4CONTENT']['0']['#']);
        $tab->tab5content = backup_todb($info['MOD']['#']['TAB5CONTENT']['0']['#']);
        $tab->tab6content = backup_todb($info['MOD']['#']['TAB6CONTENT']['0']['#']);
        $tab->tab7content = backup_todb($info['MOD']['#']['TAB7CONTENT']['0']['#']);
        $tab->tab8content = backup_todb($info['MOD']['#']['TAB8CONTENT']['0']['#']);
        $tab->tab9content = backup_todb($info['MOD']['#']['TAB9CONTENT']['0']['#']);
        $tab->tab0content = backup_todb($info['MOD']['#']['TAB0CONTENT']['0']['#']);
        $tab->css = backup_todb($info['MOD']['#']['CSS']['0']['#']);
        $tab->menucss = backup_todb($info['MOD']['#']['MENUCSS']['0']['#']);
        $tab->displaymenu = backup_todb($info['MOD']['#']['DISPLAYMENU']['0']['#']);
        $tab->menuname = backup_todb($info['MOD']['#']['MENUNAME']['0']['#']);
        $tab->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
        //The structure is equal to the db, so insert the tab
        $newid = insert_record("tab", $tab);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "tab") . " \"" . format_string(stripslashes($tab->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #6
0
function webscheme_restore_mods($mod, $restore)
{
    global $CFG;
    $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;
        // (STOLEN FROM CHOICE) if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('Webscheme', $restore, $info['MOD']['#'], array('TIMEOPEN', 'TIMECLOSE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the WEBSCHEME record structure
        $webscheme->course = $restore->course_id;
        $webscheme->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $webscheme->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $webscheme->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $webscheme->timecreated = $info['MOD']['#']['TIMECREATED']['0']['#'];
        $webscheme->timemodified = $info['MOD']['#']['TIMEMODIFIED']['0']['#'];
        $ws_settings = $info['MOD']['#']['WS_SETTINGS']['0']['#'];
        $ws_settings = backup_todb(html_entity_decode($ws_settings));
        $webscheme->ws_settings = $ws_settings;
        $ws_events = $info['MOD']['#']['WS_EVENTS']['0']['#'];
        $ws_events = backup_todb(html_entity_decode($ws_events));
        $webscheme->ws_events = $ws_events;
        $ws_initexpr = $info['MOD']['#']['WS_INITEXPR']['0']['#'];
        $ws_initexpr = backup_todb(html_entity_decode($ws_initexpr));
        $webscheme->ws_initexpr = $ws_initexpr;
        $ws_loadurls = $info['MOD']['#']['WS_LOADURLS']['0']['#'];
        $ws_loadurls = backup_todb(html_entity_decode($ws_loadurls));
        $webscheme->ws_loadurls = $ws_loadurls;
        $ws_html = $info['MOD']['#']['WS_HTML']['0']['#'];
        $ws_html = backup_todb(html_entity_decode($ws_html));
        $webscheme->ws_html = $ws_html;
        //The structure is equal to the db, so insert the webscheme
        //  ah?  Do we need to addslashes or anything?
        $newid = insert_record("webscheme", $webscheme);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "webscheme") . " \"" . format_string($webscheme->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
}
//This function restores the podcast_items
function podcast_items_restore_mods($old_podcast_id, $new_podcast_id, $info, $restore)
{
    global $CFG;
    $status = true;
    //Get the items array
    $items = $info['MOD']['#']['ITEMS']['0']['#']['ITEM'];
    //Iterate over items
    for ($i = 0; $i < sizeof($items); $i++) {
        $items_info = $items[$i];
        //We'll need this later!!
        $oldid = backup_todb($items_info['#']['ID']['0']['#']);
        //Now, build the podcast_itemS record structure
        $item->id_podcast = $new_podcast_id;
        $item->title = backup_todb($items_info['#']['TITLE']['0']['#']);
        $item->lien = backup_todb($items_info['#']['LIEN']['0']['#']);
        $item->intro = backup_todb($items_info['#']['INTRO']['0']['#']);
        $item->pubdate = backup_todb($items_info['#']['PUBDATE']['0']['#']);
        $item->date_html = backup_todb($items_info['#']['DATE_HTML']['0']['#']);
        $item->duration = backup_todb($items_info['#']['DURATION']['0']['#']);
        $item->length = backup_todb($items_info['#']['LENGTH']['0']['#']);
        //The structure is equal to the db, so insert the podcast_item
        $newid = insert_record("podcast_structure", $item);
        //Now copy moddata associated files
        if ($newid) {
            // Check folder permissions
            if (!is_writable($CFG->dirroot . "/mod/podcast/media/") && !defined('RESTORE_SILENTLY')) {
                echo "<li style='color:red;font-size:0.9em;font-weight:bold;'>";
                echo get_string('chmod_media_1', 'podcast') . "<br />";
                echo get_string('chmod_media_2', 'podcast');
                echo "</li>";
                $status = false;
            }
            if (!is_writable($CFG->dirroot . "/mod/podcast/publication/") && !defined('RESTORE_SILENTLY')) {
                echo "<li style='color:red;font-size:0.9em;font-weight:bold;'>";
                echo get_string('chmod_publication_1', 'podcast') . "<br />";
                echo get_string('chmod_publication_2', 'podcast');
                echo "</li>";
                $status = false;
            }
            if ($status) {
                $status = podcast_restore_files($old_podcast_id, $new_podcast_id, $oldid, $newid, $restore);
            }
        }
        backup_flush(300);
        //Do some output
        if (($i + 1) % 50 == 0) {
            if (!defined('RESTORE_SILENTLY')) {
                echo ".";
                if (($i + 1) % 1000 == 0) {
                    echo "<br />";
                }
            }
            backup_flush(300);
        }
    }
Пример #8
0
function voiceauthoring_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    $userdata = restore_userdata_selected($restore, "voiceauthoring", $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //add logs
        //Now, build the voiceauthoring record structure
        $resource = get_record("voiceauthoring_resources", "fromrid", $info['MOD']['#']['RID']['0']['#'], "course", $restore->course_id);
        if (empty($resource)) {
            $resourceCopy = voicetools_api_copy_resource($info['MOD']['#']['RID']['0']['#'], null, "0");
            if ($resourceCopy === false) {
                return false;
                //error to copy the resource
            }
            $resourceId = $resourceCopy->getRid();
            voiceauthoring_createResourceFromResource($info['MOD']['#']['RID']['0']['#'], $resourceId, $restore->course_id);
        }
        if ($userdata === false) {
            $mid = $resource->mid + 1;
            $resource->mid = $resource->mid + 1;
            update_record("voiceauthoring_resources", $resource);
            $name = str_replace(backup_todb($info['MOD']['#']['MID']['0']['#']), $mid, backup_todb($info['MOD']['#']['NAME']['0']['#']));
        } else {
            $mid = backup_todb(backup_todb($info['MOD']['#']['MID']['0']['#']));
            $name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        }
        $voiceauthoring->course = backup_todb($restore->course_id);
        $voiceauthoring->rid = backup_todb($resourceId);
        $voiceauthoring->mid = $mid;
        $voiceauthoring->name = str_replace(backup_todb($info['MOD']['#']['RID']['0']['#']), $resourceId, $name);
        $voiceauthoring->activityname = backup_todb($info['MOD']['#']['ACTIVITY_NAME']['0']['#']);
        $voiceauthoring->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']);
        $voiceauthoring->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $voiceauthoring->isfirst = 1;
        //The structure is equal to the db, so insert the voiceauthoring
        $newid = insert_record("voiceauthoring", $voiceauthoring);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "voiceauthoring") . " \"" . format_string(stripslashes(stripslashes($voiceauthoring->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #9
0
function voiceemail_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    $userdata = restore_userdata_selected($restore, "voiceemail", $mod->id);
    if ($data) {
        //Now get completed xmlized object
        $info = $data->info;
        //add logs
        //Now, build the voiceemail record structure
        if ($userdata === true) {
            $copyOptions = "0";
            //top message
        } else {
            $copyOptions = "2";
            //top message
        }
        $oldResource = get_record("voiceemail_resources", "id", $info['MOD']['#']['RID']['0']['#']);
        $resourceId = $oldResource->rid;
        $resource = voicetools_api_copy_resource($resourceId, null, $copyOptions);
        if ($resource === false) {
            return false;
            //error to copy the resource
        }
        $bdId = voiceemail_createResourceFromResource($resourceId, $resource->getRid(), $restore->course_id);
        $voiceemail->course = backup_todb($restore->course_id);
        $voiceemail->rid = backup_todb($bdId);
        $voiceemail->recipients_email = backup_todb(backup_todb($info['MOD']['#']['RECIPIENTS_EMAIL']['0']['#']));
        $voiceemail->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $voiceemail->section = backup_todb($info['MOD']['#']['SECTION']['0']['#']);
        $voiceemail->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $voiceemail->isfirst = 1;
        //The structure is equal to the db, so insert the voiceemail
        $newid = insert_record("voiceemail", $voiceemail);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "voiceemail") . " \"" . format_string(stripslashes($voiceemail->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function topcoll_restore_format_data($restore, $data)
{
    global $CFG;
    $status = true;
    // Get the backup data
    if (!empty($data['FORMATDATA']['#']['LAYOUT']['0'])) {
        $layout_info = $data['FORMATDATA']['#']['LAYOUT']['0'];
        $layoutelement = backup_todb($layout_info['#']['LAYOUTELEMENT']['0']['#']);
        $layoutstructure = backup_todb($layout_info['#']['LAYOUTSTRUCTURE']['0']['#']);
        put_layout($restore->course_id, $layoutelement, $layoutstructure);
        // In $CFG->dirroot.'/course/format/topcoll/lib.php'.
    }
    return $status;
}
Пример #11
0
function textanalysis_restore_mods($mod, $restore)
{
    global $CFG, $oldidarray;
    $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
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            restore_log_date_changes('textanalysis', $restore, $info['MOD']['#'], array('TEXTANALYSISTIME'));
        }
        //Now, build the textanalysis record structure
        $textanalysis->course = $restore->course_id;
        $textanalysis->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']);
        $textanalysis->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $textanalysis->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $textanalysis->type = backup_todb($info['MOD']['#']['TYPE']['0']['#']);
        $textanalysis->time = backup_todb($info['MOD']['#']['TIME']['0']['#']);
        $user = backup_getid($restore->backup_unique_code, "user", $textanalysis->teacher);
        if ($user) {
            $textanalysis->teacher = $user->new_id;
        }
        //The structure is equal to the db, so insert the textanalysis
        $newid = insert_record("textanalysis", $textanalysis);
        //Do some output
        //if (!defined('RESTORE_SILENTLY')) {
        //    echo "<li>".get_string("modulename","textanalysis")." \"".format_string(stripslashes($textanalysis->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);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'textanalysis', $mod->id)) {
                //Restore textanalysis_messages
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #12
0
/**
 * Restore everything from the given backup.
 */
function sloodle_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //Get record from backup_ids
    $data = backup_getid($restore->backup_unique_code, $mod->modtype, $mod->id);
    if ($data) {
        // Get the XML backup data as an array
        $info = $data->info;
        // Build our SLOODLE DB record
        $sloodle = new object();
        $sloodle->course = $restore->course_id;
        $sloodle->type = backup_todb($info['MOD']['#']['SUBTYPE']['0']['#']);
        $sloodle->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $sloodle->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $sloodle->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $sloodle->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $newid = insert_record("sloodle", $sloodle);
        // Inform the user what we are restoring
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "sloodle") . " \"" . format_string(stripslashes($sloodle->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);
            // Should we restore userdata?
            $includeuserdata = restore_userdata_selected($restore, 'sloodle', $mod->id);
            // Attempt to get a SloodleModule object for this module sub-type
            $dummysession = new SloodleSession(false);
            // We need to provide this to keep the module happy!
            $moduleobj = sloodle_load_module($sloodle->type, $dummysession);
            if ($moduleobj != false) {
                // Attempt to restore this module's secondary data
                if (!$moduleobj->restore($newid, $info['MOD']['#']['SECONDARYDATA']['0']['#'], $includeuserdata)) {
                    $status = false;
                }
            } else {
                echo "<li>Failed to fully restore SLOODLE module type {$sloodle->type}. This type may not be available on your installation.</li>";
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #13
0
function wwassignment_restore_mods($mod, $restore)
{
    global $CFG;
    $status = true;
    //error_log("mod id ".$mod->id);
    //         if ($mod->id == "66666") {
    //         	$wwlinkdata  = backup_getid($restore->backup_unique_code,"wwassignment_bridge","wwassignment_bridge");
    //             error_log("wwlink data ".print_r($wwlinkdata, true ));
    //             return $status;
    //          }
    //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;
        //if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            //restore_log_date_changes('Wwassignment', $restore, $info['MOD']['#'], array('TIMEDUE', 'TIMEAVAILABLE'));
        }
        //traverse_xmlize($info);                                                                     //Debug
        //print_object ($GLOBALS['traverse_array']);                                                  //Debug
        //$GLOBALS['traverse_array']="";                                                              //Debug
        //Now, build the ASSIGNMENT record structure
        $wwassignment->course = $restore->course_id;
        $wwassignment->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $wwassignment->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
        $wwassignment->webwork_set = backup_todb($info['MOD']['#']['WEBWORK_SET']['0']['#']);
        $wwassignment->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the assignment
        $newid = insert_record("wwassignment", $wwassignment);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "wwassignment") . " \"" . format_string(stripslashes($wwassignment->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    //error_log("mod id is ".print_r($mod,true));
    return $status;
}
Пример #14
0
 function restore($old_question_id, $new_question_id, $info, $restore)
 {
     global $DB;
     $status = true;
     //Get the truefalse array
     if (array_key_exists('TRUEFALSE', $info['#'])) {
         $truefalses = $info['#']['TRUEFALSE'];
     } else {
         $truefalses = array();
     }
     //Iterate over truefalse
     for ($i = 0; $i < sizeof($truefalses); $i++) {
         $tru_info = $truefalses[$i];
         //Now, build the question_truefalse record structure
         $truefalse = new stdClass();
         $truefalse->question = $new_question_id;
         $truefalse->trueanswer = stripslashes(backup_todb($tru_info['#']['TRUEANSWER']['0']['#']));
         $truefalse->falseanswer = stripslashes(backup_todb($tru_info['#']['FALSEANSWER']['0']['#']));
         ////We have to recode the trueanswer field
         $answer = backup_getid($restore->backup_unique_code, "question_answers", $truefalse->trueanswer);
         if ($answer) {
             $truefalse->trueanswer = $answer->new_id;
         }
         ////We have to recode the falseanswer field
         $answer = backup_getid($restore->backup_unique_code, "question_answers", $truefalse->falseanswer);
         if ($answer) {
             $truefalse->falseanswer = $answer->new_id;
         }
         //The structure is equal to the db, so insert the question_truefalse
         $newid = $DB->insert_record("question_truefalse", $truefalse);
         //Do some output
         if (($i + 1) % 50 == 0) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo ".";
                 if (($i + 1) % 1000 == 0) {
                     echo "<br />";
                 }
             }
             backup_flush(300);
         }
         if (!$newid) {
             $status = false;
         }
     }
     return $status;
 }
Пример #15
0
function openmeetings_restore_mods($mod, $restore)
{
    global $CFG;
    $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
        // if necessary, write to restorelog and adjust date/time fields
        if ($restore->course_startdateoffset) {
            // restore_log_date_changes('openmeetings', $restore, $info['MOD']['#'], array('openmeetingsTIME'));
        }
        //Now, build the openmeetings record structure
        $openmeetings->course = $restore->course_id;
        $openmeetings->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $openmeetings->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $openmeetings->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $openmeetings->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        $openmeetings->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $openmeetings->teacher = backup_todb($info['MOD']['#']['TEACHER']['0']['#']);
        $newid = openmeetings_add_instance($openmeetings);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "openmeetings") . " \"" . format_string(stripslashes($openmeetings->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);
            //Now check if want to restore user data and do it.
            if (restore_userdata_selected($restore, 'openmeetings', $mod->id)) {
                //Restore nothing
                $status = false;
            }
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #16
0
function adobeconnect_pages_restore_mods($adobeconnectid, $info, $restore)
{
    global $CFG;
    $status = true;
    //Get the lesson_elements array
    $meetgroups = $info['MOD']['#']['MEETINGGROUPS']['0']['#']['MEETINGGROUP'];
    //Iterate over lesson pages (they are held in their logical order)
    $prevpageid = 0;
    for ($i = 0; $i < sizeof($meetgroups); $i++) {
        $meetgroup_info = $meetgroups[$i];
        //traverse_xmlize($ele_info);                                                          //Debug
        //print_object ($GLOBALS['traverse_array']);                                           //Debug
        //$GLOBALS['traverse_array']="";                                                       //Debug
        //Now, build the lesson_pages record structure
        $oldid = backup_todb($meetgroup_info['#']['ID']['0']['#']);
        $meeting = new stdClass();
        $meeting->instanceid = $adobeconnectid;
        $meeting->meetingscoid = backup_todb($meetgroup_info['#']['MEETINGSCOID']['0']['#']);
        $meeting->groupid = backup_todb($meetgroup_info['#']['GROUPID']['0']['#']);
        //We have to recode the groupid field
        $group = restore_group_getid($restore, $meeting->groupid);
        if ($group) {
            $meeting->groupid = $group->new_id;
        }
        //The structure is equal to the db, so insert the certificate_issue
        $newid = insert_record("adobeconnect_meeting_groups", $meeting);
        //Do some output
        if (($i + 1) % 10 == 0) {
            if (!defined('RESTORE_SILENTLY')) {
                echo ".";
                if (($i + 1) % 200 == 0) {
                    echo "<br/>";
                }
            }
            backup_flush(300);
        }
        if ($newid) {
            //We have the newid, update backup_ids (restore logs will use it!!)
            backup_putid($restore->backup_unique_code, "adobeconnect_meeting_groups", $oldid, $newid);
        } else {
            $status = false;
        }
    }
    return $status;
}
Пример #17
0
 function restore_map($old_question_id, $new_question_id, $info, $restore)
 {
     global $DB;
     $status = true;
     //Get the multianswers array
     $multianswers = $info['#']['MULTIANSWERS']['0']['#']['MULTIANSWER'];
     //Iterate over multianswers
     for ($i = 0; $i < sizeof($multianswers); $i++) {
         $mul_info = $multianswers[$i];
         //We need this later
         $oldid = backup_todb($mul_info['#']['ID']['0']['#']);
         //Now, build the question_multianswer record structure
         $multianswer->question = $new_question_id;
         $multianswer->answers = stripslashes(backup_todb($mul_info['#']['ANSWERS']['0']['#']));
         $multianswer->positionkey = backup_todb($mul_info['#']['POSITIONKEY']['0']['#']);
         $multianswer->answertype = backup_todb($mul_info['#']['ANSWERTYPE']['0']['#']);
         $multianswer->norm = backup_todb($mul_info['#']['NORM']['0']['#']);
         //If we are in this method is because the question exists in DB, so its
         //multianswer must exist too.
         //Now, we are going to look for that multianswer in DB and to create the
         //mappings in reader_backup_ids to use them later where restoring states (user level).
         //Get the multianswer from DB (by question and positionkey)
         $db_multianswer = $DB->get_record("question_multianswer", array("question" => $new_question_id, "positionkey" => $multianswer->positionkey));
         //Do some output
         if (($i + 1) % 50 == 0) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo ".";
                 if (($i + 1) % 1000 == 0) {
                     echo "<br />";
                 }
             }
             backup_flush(300);
         }
         //We have the database multianswer, so update reader_backup_ids
         if ($db_multianswer) {
             //We have the newid, update reader_backup_ids
             backup_putid($restore->backup_unique_code, "question_multianswer", $oldid, $db_multianswer->id);
         } else {
             $status = false;
         }
     }
     return $status;
 }
Пример #18
0
/**
 * restores a complete module
 * @param object $mod
 * @param object $restore
 * @uses $CFG
 */
function poodllpairwork_restore_mods($mod, $restore)
{
    global $CFG;
    $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 poodllpairwork record structure
        $poodllpairwork->course = $restore->course_id;
        $poodllpairwork->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $poodllpairwork->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $poodllpairwork->introa = backup_todb($info['MOD']['#']['INTROA']['0']['#']);
        $poodllpairwork->introb = backup_todb($info['MOD']['#']['INTROB']['0']['#']);
        $poodllpairwork->sessiontype = backup_todb($info['MOD']['#']['SESSIONTYPE']['0']['#']);
        $poodllpairwork->introformat = backup_todb($info['MOD']['#']['INTROFORMAT']['0']['#']);
        $poodllpairwork->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']);
        $poodllpairwork->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the poodllpairwork
        $newid = insert_record('poodllpairwork', $poodllpairwork);
        //Do some output
        echo '<ul><li>' . get_string('modulename', 'poodllpairwork') . " \"" . $poodllpairwork->name . "\"<br>";
        backup_flush(300);
        if ($newid) {
            //We have the newid, update backup_ids
            backup_putid($restore->backup_unique_code, $mod->modtype, $mod->id, $newid);
            //Now restore files
            $status = $status && poodllpairwork_restore_files($mod->id, $newid, $restore);
        } else {
            $status = false;
        }
        //Finalize ul
        echo '</ul>';
    } else {
        $status = false;
    }
    return $status;
}
/**
 * eBook course format restore routine
 *
 * @param object $restore Restore object
 * @param array $data This is the xmlized information underneath FORMATDATA in the backup XML file.
 **/
function ebook_restore_format_data($restore, $data)
{
    global $CFG;
    //require_once($CFG->dirroot.'/course/format/ebook/lib.php');
    $status = true;
    // Get the backup data
    if (!empty($data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE'])) {
        //$newpageids = array();
        // Get all the pages and restore them.
        $pages = $data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE'];
        for ($i = 0; $i < count($pages); $i++) {
            $pageinfo = $pages[$i];
            $page = new stdClass();
            $page->courseid = $restore->course_id;
            //$page->id = backup_todb($pageinfo['#']['ID']['0']['#']);
            //$page->courseid = backup_todb($pageinfo['#']['COURSEID']['0']['#']);
            $page->chapter = backup_todb($pageinfo['#']['CHAPTER']['0']['#']);
            $page->page = backup_todb($pageinfo['#']['PAGE']['0']['#']);
            $page->section = backup_todb($pageinfo['#']['SECTION']['0']['#']);
            $page->title = backup_todb($pageinfo['#']['TITLE']['0']['#']);
            $oldid = backup_todb($pageinfo['#']['ID']['0']['#']);
            if ($newid = insert_record('course_format_ebook', $page)) {
                //$newpageids[$oldid] = $newid;
                backup_putid($restore->backup_unique_code, 'course_format_ebook', $oldid, $newid);
            } else {
                $status = false;
                break;
            }
        }
        // Need to remap parentids
        //        foreach($newpageids as $oldid => $newid) {
        //            $parent = get_field('course_format_ebook', 'parent', 'id', $newid);
        //            if (!empty($parent)) {
        //                set_field('course_format_ebook', 'parent', $newpageids[$parent], 'id', $newid);
        //            }
        //        }
        // Need to fix sortorder for old courses - doesn't do much of anything if sortorder is already OK
        //$status = $status and page_fix_page_sortorder($restore->course_id);
        //$status = $status and page_fix_pageitem_sortorder($restore->course_id);  // Helps to repair sortorder if an item fails
    }
    return $status;
}
function groupselect_restore_mods($mod, $restore)
{
    global $CFG;
    $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 LABEL record structure
        $groupselect = new object();
        $groupselect->course = $restore->course_id;
        $groupselect->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $groupselect->intro = backup_todb($info['MOD']['#']['INTRO']['0']['#']);
        $groupselect->password = backup_todb($info['MOD']['#']['PASSWORD']['0']['#']);
        $groupselect->timeavailable = backup_todb($info['MOD']['#']['TIMEAVAILABLE']['0']['#']);
        $groupselect->timedue = backup_todb($info['MOD']['#']['TIMEDUE']['0']['#']);
        $groupselect->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the groupselect
        $newid = insert_record("groupselect", $groupselect);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "groupselect") . " \"" . format_string(stripslashes($groupselect->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
function bigbluebutton_restore_mods($mod, $restore)
{
    global $CFG;
    $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 LABEL record structure
        $bigbluebutton->course = $restore->course_id;
        $bigbluebutton->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $bigbluebutton->moderatorpass = backup_todb($info['MOD']['#']['MODERATORPASS']['0']['#']);
        $bigbluebutton->viewerpass = backup_todb($info['MOD']['#']['VIEWERPASS']['0']['#']);
        $bigbluebutton->wait = backup_todb($info['MOD']['#']['WAIT']['0']['#']);
        $bigbluebutton->meetingid = backup_todb($info['MOD']['#']['MEETINGID']['0']['#']);
        $bigbluebutton->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']);
        //The structure is equal to the db, so insert the bigbluebutton
        $newid = insert_record("bigbluebutton", $bigbluebutton);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "bigbluebutton") . " \"" . format_string(stripslashes($bigbluebutton->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #22
0
function wwassignment_restore_mods($mod, $restore)
{
    global $CFG;
    $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 QUIZ record structure
        $wwassignment = new stdClass();
        $wwassignment->course = $restore->course_id;
        $wwassignment->name = backup_todb($info['MOD']['#']['NAME']['0']['#']);
        $wwassignment->description = backup_todb($info['MOD']['#']['DESCRIPTION']['0']['#']);
        $wwassignment->webwork_set = backup_todb($info['MOD']['#']['WEBWORK_SET']['0']['#']);
        //The structure is equal to the db, so insert the quiz
        $newid = insert_record("wwassignment", $wwassignment);
        //Do some output
        if (!defined('RESTORE_SILENTLY')) {
            echo "<li>" . get_string("modulename", "wwassignment") . " \"" . format_string(stripslashes($wwassignment->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);
        } else {
            $status = false;
        }
    } else {
        $status = false;
    }
    return $status;
}
Пример #23
0
function data_comments_restore_mods($oldid, $newid, $info, $rec_info)
{
    global $CFG;
    $status = true;
    $comments = isset($rec_info['#']['COMMENTS']['0']['#']['COMMENT']) ? $rec_info['#']['COMMENTS']['0']['#']['COMMENT'] : array();
    if (empty($comments)) {
        // no comments to restore
        return true;
    }
    for ($i = 0; $i < sizeof($comments); $i++) {
        $com_info = $comments[$i];
        $comment->recordid = $newid;
        $comment->userid = backup_todb($com_info['#']['USERID']['0']['#']);
        $comment->content = backup_todb($com_info['#']['CONTENT']['0']['#']);
        $comment->created = backup_todb($com_info['#']['CREATED']['0']['#']);
        $comment->modified = backup_todb($com_info['#']['MODIFIED']['0']['#']);
        if (!insert_record("data_comments", $comment)) {
            $status = false;
        }
    }
    return $status;
}
Пример #24
0
function exercise_grades_restore_mods($new_exercise_id, $new_assessment_id, $info, $restore)
{
    global $CFG;
    $status = true;
    //Get the grades array (optional)
    if (isset($info['#']['GRADES']['0']['#']['GRADE'])) {
        $grades = $info['#']['GRADES']['0']['#']['GRADE'];
        //Iterate over grades
        for ($i = 0; $i < sizeof($grades); $i++) {
            $gra_info = $grades[$i];
            //traverse_xmlize($gra_info);                           //Debug
            //print_object ($GLOBALS['traverse_array']);            //Debug
            //$GLOBALS['traverse_array']="";                        //Debug
            //Now, build the exercise_GRADES record structure
            $grade->exerciseid = $new_exercise_id;
            $grade->assessmentid = $new_assessment_id;
            $grade->elementno = backup_todb($gra_info['#']['ELEMENTNO']['0']['#']);
            $grade->feedback = backup_todb($gra_info['#']['FEEDBACK']['0']['#']);
            $grade->grade = backup_todb($gra_info['#']['GRADE_VALUE']['0']['#']);
            //The structure is equal to the db, so insert the exercise_grade
            $newid = insert_record("exercise_grades", $grade);
            //Do some output
            if (($i + 1) % 50 == 0) {
                if (!defined('RESTORE_SILENTLY')) {
                    echo ".";
                    if (($i + 1) % 1000 == 0) {
                        echo "<br />";
                    }
                }
                backup_flush(300);
            }
            if (!$newid) {
                $status = false;
            }
        }
    }
    return $status;
}
Пример #25
0
function mail_statistics_restore_mods($courseid, $info, $restore)
{
    global $CFG;
    $status = true;
    //Get the mail_elements array
    $statistics = $info['MOD']['#']['STATISTICS']['0']['#']['STATISTIC'];
    //Iterate over mail statistics (they are held in their logical order)
    for ($i = 0; $i < sizeof($statistics); $i++) {
        $statistic_info = $statistics[$i];
        //We'll need this later!!
        $oldid = backup_todb($statistic_info['#']['ID']['0']['#']);
        //Now, build the mail_statistic record structure
        $statistic->course = $courseid;
        $statistic->userid = backup_todb($statistic_info['#']['USERID']['0']['#']);
        $statistic->received = backup_todb($statistic_info['#']['RECEIVED']['0']['#']);
        $statistic->send = backup_todb($statistic_info['#']['SEND']['0']['#']);
        $statistic->timemodified = backup_todb($statistic_info['#']['TIMEMODIFIED']['0']['#']);
        //We have to recode the userid field
        $user = backup_getid($restore->backup_unique_code, "user", $statistic->userid);
        if ($user) {
            $statistic->userid = $user->new_id;
        }
        //The structure is equal to the db, so insert the mail_statistic
        $newid = insert_record("mail_statistics", $statistic);
        //Do some output
        if (($i + 1) % 10 == 0) {
            if (!defined('RESTORE_SILENTLY')) {
                echo ".";
                if (($i + 1) % 200 == 0) {
                    echo "<br>";
                }
            }
            backup_flush(300);
        }
        if (!$newid) {
            $status = false;
        }
    }
    return $status;
}
Пример #26
0
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
    // maintain a cache of info on table columns
    static $table_columns = array();
    if (empty($table_columns[$table])) {
        global $CFG, $db;
        $table_columns[$table] = $db->MetaColumns("{$CFG->prefix}{$table}");
    }
    // get values for fields in this record
    $record = new stdClass();
    $TAGS = array_keys($xml);
    foreach ($TAGS as $TAG) {
        $value = $xml[$TAG][0]['#'];
        if (is_string($value)) {
            $tag = strtolower($TAG);
            $record->{$tag} = backup_todb($value);
        }
    }
    // update foreign keys, if any
    $ok = true;
    foreach ($foreign_keys as $key => $value) {
        if (is_numeric($value)) {
            $record->{$key} = $value;
        } else {
            $key_table = $value;
            $new_ids = array();
            if (isset($record->{$key})) {
                $old_ids = explode(',', $record->{$key});
                foreach ($old_ids as $old_id) {
                    if (empty($old_id)) {
                        // do nothing
                    } else {
                        $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 ";
                                if (isset($record->id)) {
                                    print "(old id={$record->id}) ";
                                }
                                print "was not restored</li></ul>";
                            }
                            $ok = false;
                        }
                    }
                }
            }
            $record->{$key} = implode(',', $new_ids);
        }
    }
    // set md5 keys if necessary (restoring from Moodle<1.6)
    if ($table == 'hotpot_questions' && empty($record->md5key)) {
        $record->md5key = md5($record->name);
    }
    if ($table == 'hotpot_strings' && empty($record->md5key)) {
        $record->md5key = md5($record->string);
    }
    // check all "not null" fields have been set
    foreach ($table_columns[$table] as $column) {
        if ($column->not_null) {
            $name = $column->name;
            if ($name != 'id' && empty($record->{$name})) {
                if (isset($column->default_value)) {
                    $default = $column->default_value;
                } else {
                    if (preg_match('/int|decimal|double|float|time|year/i', $column->type)) {
                        $default = 0;
                    } else {
                        $default = '';
                    }
                }
                $record->{$name} = $default;
            }
        }
    }
    // check everything is OK so far
    if ($ok) {
        // 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_records = get_records($table, $secondary_key, $record->{$secondary_key});
            if ($key_records) {
                // set new record id from already existing record
                $key_record = reset($key_records);
                $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;
}
Пример #27
0
/**
 * Page formats restore routine
 *
 * @param object $restore Restore object
 * @param array $data This is the xmlized information underneath FORMATDATA in the backup XML file.
 **/
function learning_restore_format_data($restore, $data)
{
    global $CFG;
    require_once $CFG->dirroot . '/course/format/page/lib.php';
    $status = true;
    if (isset($restore->preferences['nopages'])) {
        // request not to proceed with course format restore
        return $status;
    }
    // Get the backup data
    if (!empty($data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE'])) {
        $newpageids = array();
        // Get all the pages and restore them, restoring page items along the way.
        $pages = $data['FORMATDATA']['#']['PAGES']['0']['#']['PAGE'];
        for ($i = 0; $i < count($pages); $i++) {
            $pageinfo = $pages[$i];
            $page = new stdClass();
            $page->courseid = $restore->course_id;
            $page->nameone = backup_todb($pageinfo['#']['NAMEONE']['0']['#']);
            $page->nametwo = backup_todb($pageinfo['#']['NAMETWO']['0']['#']);
            $page->display = backup_todb($pageinfo['#']['DISPLAY']['0']['#']);
            $page->prefleftwidth = backup_todb($pageinfo['#']['PREFLEFTWIDTH']['0']['#']);
            $page->prefcenterwidth = backup_todb($pageinfo['#']['PREFCENTERWIDTH']['0']['#']);
            $page->prefrightwidth = backup_todb($pageinfo['#']['PREFRIGHTWIDTH']['0']['#']);
            $page->parent = backup_todb($pageinfo['#']['PARENT']['0']['#']);
            // will remap later when we know all ids are present
            $page->sortorder = backup_todb($pageinfo['#']['SORTORDER']['0']['#']);
            $page->template = backup_todb($pageinfo['#']['TEMPLATE']['0']['#']);
            $page->showbuttons = backup_todb($pageinfo['#']['SHOWBUTTONS']['0']['#']);
            $oldid = backup_todb($pageinfo['#']['ID']['0']['#']);
            if ($newid = insert_record('format_page', $page)) {
                $newpageids[$oldid] = $newid;
                backup_putid($restore->backup_unique_code, 'format_page', $oldid, $newid);
                // Now restore the page_items
                if (isset($pageinfo['#']['ITEMS'])) {
                    $items = $pageinfo['#']['ITEMS']['0']['#']['ITEM'];
                    for ($j = 0; $j < count($items); $j++) {
                        $iteminfo = $items[$j];
                        $item = new stdClass();
                        $item->pageid = $newid;
                        $item->cmid = backup_todb($iteminfo['#']['CMID']['0']['#']);
                        if (!empty($item->cmid)) {
                            // Try to remap the cm ID
                            $cmid = backup_getid($restore->backup_unique_code, 'course_modules', $item->cmid);
                            if ($cmid) {
                                $item->cmid = $cmid->new_id;
                            } else {
                                // Failed to remap - could be for various valid reasons - skip this item
                                continue;
                            }
                        }
                        $item->blockinstance = $iteminfo['#']['BLOCKINSTANCE']['0']['#'];
                        // we'll remap blockids when we decode contentlinks
                        $item->position = backup_todb($iteminfo['#']['POSITION']['0']['#']);
                        $item->sortorder = backup_todb($iteminfo['#']['SORTORDER']['0']['#']);
                        $item->visible = backup_todb($iteminfo['#']['VISIBLE']['0']['#']);
                        $itemoldid = backup_todb($pageinfo['#']['ID']['0']['#']);
                        if ($itemnewid = insert_record('format_page_items', $item)) {
                            backup_putid($restore->backup_unique_code, 'format_page_items', $itemoldid, $itemnewid);
                        } else {
                            $status = false;
                            break;
                        }
                    }
                }
            } else {
                $status = false;
                break;
            }
        }
        // Need to remap parentids
        foreach ($newpageids as $oldid => $newid) {
            $parent = get_field('format_page', 'parent', 'id', $newid);
            if (!empty($parent)) {
                set_field('format_page', 'parent', $newpageids[$parent], 'id', $newid);
            }
        }
        // Need to fix sortorder for old courses - doesn't do much of anything if sortorder is already OK
        $status = $status and page_fix_page_sortorder($restore->course_id);
        $status = $status and page_fix_pageitem_sortorder($restore->course_id);
        // Helps to repair sortorder if an item fails
    }
    return $status;
}
Пример #28
0
 function restore($old_question_id, $new_question_id, $info, $restore)
 {
     $status = true;
     $extraquestionfields = $this->extra_question_fields();
     if (is_array($extraquestionfields)) {
         $questionextensiontable = array_shift($extraquestionfields);
         $tagname = strtoupper($this->name());
         $recordinfo = $info['#'][$tagname][0];
         $record = new stdClass();
         $qidcolname = $this->questionid_column_name();
         $record->{$qidcolname} = $new_question_id;
         foreach ($extraquestionfields as $field) {
             $record->{$field} = backup_todb($recordinfo['#'][strtoupper($field)]['0']['#']);
         }
         if (!insert_record($questionextensiontable, $record)) {
             echo "Can't insert record in {$questionextensiontable} when restoring " . $this->name() . ' question id ' . $question;
             $status = false;
         }
     }
     //TODO restore extra data in answers
     return $status;
 }
Пример #29
0
 /**
  * Restores the data in the question
  *
  * This is used in question/restorelib.php
  */
 function restore($old_question_id, $new_question_id, $info, $restore)
 {
     $status = true;
     //Get the webworks array
     $webworks = $info['#']['WEBWORK'];
     //Iterate over webworks
     for ($i = 0; $i < sizeof($webworks); $i++) {
         $webwork_info = $webworks[$i];
         //Now, build the question_webwork record structure
         $webwork = new stdClass();
         $webwork->question = $new_question_id;
         $webwork->codecheck = backup_todb($webwork_info['#']['CODECHECK']['0']['#']);
         $webwork->code = backup_todb($webwork_info['#']['CODE']['0']['#']);
         $webwork->grading = backup_todb($webwork_info['#']['GRADING']['0']['#']);
         //The structure is equal to the db, so insert the question_shortanswer
         $newid = insert_record("question_webwork", $webwork);
         //Do some output
         if (($i + 1) % 50 == 0) {
             if (!defined('RESTORE_SILENTLY')) {
                 echo ".";
                 if (($i + 1) % 1000 == 0) {
                     echo "<br />";
                 }
             }
             backup_flush(300);
         }
         if (!$newid) {
             $status = false;
         }
     }
     return $status;
 }
 function restore_map($old_question_id, $new_question_id, $info, $restore)
 {
     $matchs = $info['#']['MATCHS']['0']['#']['MATCH'];
     foreach ($matchs as $match) {
         $match_sub_id = backup_todb($match['#']['ID']['0']['#']);
         if (!record_exists('question_match_sub', 'id', $match_sub_id)) {
             throw new SharingCart_XmlException('match sub question not found');
         }
         backup_putid($restore->backup_unique_code, 'question_match_sub', $match_sub_id, $match_sub_id);
     }
     return backup_putid($restore->backup_unique_code, 'question', $old_question_id, $new_question_id);
 }