forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backup MDL-22142 This is the user interface for backups, several mino…
…r/cosmetic issues still to be ironed out. See the tracker for details
- Loading branch information
Sam Hemelryk
committed
May 1, 2010
1 parent
9057a84
commit 1904e9b
Showing
20 changed files
with
2,177 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,80 @@ | ||
<?php | ||
//This script is used to configure and execute the backup proccess. | ||
|
||
//Define some globals for all the script | ||
|
||
require_once ("../config.php"); | ||
require_once ("lib.php"); | ||
require_once ("backuplib.php"); | ||
require_once ("$CFG->libdir/adminlib.php"); | ||
|
||
$id = optional_param('id', 0, PARAM_INT); // course id | ||
$to = optional_param('to', 0, PARAM_INT); // id of course to import into afterwards. | ||
$cancel = optional_param('cancel', '', PARAM_RAW); | ||
$launch = optional_param('launch', '', PARAM_ACTION); | ||
|
||
$url = new moodle_url('/backup/backup.php'); | ||
if ($id !== 0) { | ||
$url->param('id', $id); | ||
} | ||
if ($to !== 0) { | ||
$url->param('to', $to); | ||
} | ||
if ($launch !== '') { | ||
$url->param('launch', $launch); | ||
} | ||
$PAGE->set_url($url); | ||
|
||
$loginurl = get_login_url(); | ||
|
||
if (!empty($id)) { | ||
require_login($id); | ||
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $id))) { | ||
print_error('cannotuseadminadminorteacher', 'error', $loginurl); | ||
} | ||
} else { | ||
require_login(); | ||
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) { | ||
print_error('cannotuseadmin', 'error', $loginurl); | ||
} | ||
} | ||
|
||
if (!empty($to)) { | ||
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $to))) { | ||
print_error('cannotuseadminadminorteacher', 'error', $loginurl); | ||
} | ||
} | ||
|
||
//Check site | ||
$site = get_site(); | ||
|
||
//Check necessary functions exists. Thanks to [email protected] | ||
backup_required_functions(); | ||
|
||
//Get strings | ||
if (empty($to)) { | ||
$strcoursebackup = get_string("coursebackup"); | ||
} | ||
else { | ||
$strcoursebackup = get_string('importdata'); | ||
} | ||
$stradministration = get_string("administration"); | ||
|
||
//If cancel has been selected, go back to course main page (bug 2817) | ||
if ($cancel) { | ||
if ($id) { | ||
$redirecto = $CFG->wwwroot . '/course/view.php?id=' . $id; //Course page | ||
} else { | ||
$redirecto = $CFG->wwwroot.'/'; | ||
} | ||
redirect ($redirecto, get_string('backupcancelled')); //Site page | ||
exit; | ||
} | ||
|
||
//If no course has been selected, show a list of available courses | ||
$PAGE->set_title("$site->shortname: $strcoursebackup"); | ||
$PAGE->set_heading($site->fullname); | ||
if (!$id) { | ||
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php')); | ||
$PAGE->navbar->add($strcoursebackup); | ||
echo $OUTPUT->header(); | ||
if ($courses = get_courses('all','c.shortname','c.id,c.shortname,c.fullname')) { | ||
echo $OUTPUT->heading(get_string("choosecourse")); | ||
echo $OUTPUT->box_start(); | ||
foreach ($courses as $course) { | ||
echo '<a href="backup.php?id='.$course->id.'">'.format_string($course->fullname).' ('.format_string($course->shortname).')</a><br />'."\n"; | ||
} | ||
echo $OUTPUT->box_end(); | ||
} else { | ||
echo $OUTPUT->heading(get_string("nocoursesyet")); | ||
echo $OUTPUT->continue_button("$CFG->wwwroot/$CFG->admin/index.php"); | ||
} | ||
echo $OUTPUT->footer(); | ||
exit; | ||
} | ||
|
||
//Get and check course | ||
if (! $course = $DB->get_record("course", array("id"=>$id))) { | ||
print_error('unknowncourseidnumber','error'); | ||
} | ||
|
||
//Print header | ||
if (has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_SYSTEM))) { | ||
$PAGE->navbar->add($stradministration, new moodle_url('/admin/index.php')); | ||
$PAGE->navbar->add($strcoursebackup, new moodle_url('/backup/backup.php')); | ||
$PAGE->navbar->add("$course->fullname ($course->shortname)"); | ||
echo $OUTPUT->header(); | ||
} else { | ||
$PAGE->navbar->add($course->fullname, new moodle_url('/course/view.php', array('id'=>$course->id))); | ||
$PAGE->navbar->add($strcoursebackup); | ||
echo $OUTPUT->header(); | ||
} | ||
|
||
//Print form | ||
echo $OUTPUT->heading(format_string("$strcoursebackup: $course->fullname ($course->shortname)")); | ||
echo $OUTPUT->box_start(); | ||
|
||
//Adjust some php variables to the execution of this script | ||
@ini_set("max_execution_time","3000"); | ||
raise_memory_limit("192M"); | ||
|
||
//Call the form, depending the step we are | ||
if (!$launch or !data_submitted() or !confirm_sesskey()) { | ||
// if we're at the start, clear the cache of prefs | ||
if (isset($SESSION->backupprefs[$course->id])) { | ||
unset($SESSION->backupprefs[$course->id]); | ||
} | ||
include_once("backup_form.html"); | ||
} else if ($launch == "check") { | ||
include_once("backup_check.html"); | ||
} else if ($launch == "execute") { | ||
include_once("backup_execute.html"); | ||
} | ||
echo $OUTPUT->box_end(); | ||
|
||
//Print footer | ||
echo $OUTPUT->footer(); | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
require_once('../config.php'); | ||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php'); | ||
require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php'); | ||
|
||
|
||
$courseid = required_param('id', PARAM_INT); | ||
$sectionid = optional_param('section', null, PARAM_INT); | ||
$cmid = optional_param('cm', null, PARAM_INT); | ||
|
||
$url = new moodle_url('/backup/backup.php', array('id'=>$courseid)); | ||
if ($sectionid !== null) { | ||
$url->param('section', $sectionid); | ||
} | ||
if ($cmid !== null) { | ||
$url->param('cm', $cmid); | ||
} | ||
$PAGE->set_url($url); | ||
|
||
$id = $courseid; | ||
$cm = null; | ||
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST); | ||
$type = backup::TYPE_1COURSE; | ||
if (!is_null($sectionid)) { | ||
$section = $DB->get_record('course_sections', array('course'=>$course->id, 'section'=>$sectionid)); | ||
$type = backup::TYPE_1SECTION; | ||
$id = $sectionid; | ||
} | ||
if (!is_null($cmid)) { | ||
$cm = get_coursemodule_from_id(null, $cmid, $course->id, $sectionid, MUST_EXIST); | ||
$type = backup::TYPE_1ACTIVITY; | ||
$id = $cmid; | ||
} | ||
require_login($course, false, $cm); | ||
|
||
if (!has_capability('moodle/backup:backupcourse', get_context_instance(CONTEXT_COURSE, $course->id))) { | ||
print_error('cannotuseadminadminorteacher', 'error'); | ||
} | ||
|
||
if (!($bc = backup_ui::load_controller())) { | ||
$bc = new backup_controller($type, $id, backup::FORMAT_MOODLE, | ||
backup::INTERACTIVE_YES, backup::MODE_GENERAL, $USER->id); | ||
} | ||
$backup = new backup_ui($bc); | ||
$backup->process(); | ||
if ($backup->get_stage() == backup_ui::STAGE_FINAL) { | ||
$backup->execute(); | ||
} else { | ||
$backup->save_controller(); | ||
} | ||
|
||
$PAGE->set_title(get_string('backup')); | ||
$PAGE->set_heading(get_string('backup')); | ||
$PAGE->navbar->add($backup->get_stage_name()); | ||
$PAGE->set_pagelayout('admin'); | ||
|
||
$renderer = $PAGE->get_renderer('core','backup'); | ||
echo $OUTPUT->header(); | ||
if ($backup->enforce_changed_dependencies()) { | ||
echo $renderer->dependency_notification(get_string('dependenciesenforced','backup')); | ||
} | ||
echo $renderer->progress_bar($backup->get_progress_bar()); | ||
echo $backup->display(); | ||
echo $OUTPUT->footer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.