Beispiel #1
0
 // went really wrong in backup, throw error. Note that backup::MODE_IMPORT
 // backups don't store resulting files ever
 $tempdestination = $CFG->tempdir . '/backup/' . $backupid;
 if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
     print_error('unknownbackupexporterror');
     // shouldn't happen ever
 }
 // Prepare the restore controller. We don't need a UI here as we will just use what
 // ever the restore has (the user has just chosen).
 $rc = new restore_controller($backupid, $course->id, backup::INTERACTIVE_YES, backup::MODE_IMPORT, $USER->id, $restoretarget);
 // Convert the backup if required.... it should NEVER happed
 if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
     $rc->convert();
 }
 // Mark the UI finished.
 $rc->finish_ui();
 // Execute prechecks
 $warnings = false;
 if (!$rc->execute_precheck()) {
     $precheckresults = $rc->get_precheck_results();
     if (is_array($precheckresults)) {
         if (!empty($precheckresults['errors'])) {
             // If errors are found, terminate the import.
             fulldelete($tempdestination);
             echo $OUTPUT->header();
             echo $renderer->precheck_notices($precheckresults);
             echo $OUTPUT->continue_button(new moodle_url('/course/view.php', array('id' => $course->id)));
             echo $OUTPUT->footer();
             die;
         }
         if (!empty($precheckresults['warnings'])) {
Beispiel #2
0
function restore_to_course($courseid, $backupid, $restoretarget, $admin) {
    global $CFG; 

    // Check whether the backup directory still exists. If missing, something
    // went really wrong in backup, throw error. Note that backup::MODE_IMPORT
    // backups don't store resulting files ever
    $tempdestination = $CFG->tempdir . '/backup/' . $backupid;
    if (!file_exists($tempdestination) || !is_dir($tempdestination)) {
        print_error('unknownbackupexporterror'); // shouldn't happen ever
    }
 
    $rc = new restore_controller($backupid, $courseid, backup::INTERACTIVE_YES, 
                                backup::MODE_IMPORT,$admin->id,$restoretarget);
 
    // Convert the backup if required.... it should NEVER happed
    if ($rc->get_status() == backup::STATUS_REQUIRE_CONV) {
        $rc->convert();
    }
    // Mark the UI finished.
    $rc->finish_ui();
    // Execute prechecks
    $rc->execute_precheck();
    
    //if ($restoretarget == backup::TARGET_CURRENT_DELETING || $restoretarget == backup::TARGET_EXISTING_DELETING) {
    //    restore_dbops::delete_course_content($courseid);
    //}
    // Execute the restore.
    $rc->execute_plan();
    $rc->destroy();
    unset($rc);
    
    // Delete the temp directory now
    fulldelete($tempdestination);
}