3 ///////////////////////////////////////////////////////////////////////////
5 // This file is part of Moodle - http://moodle.org/ //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
8 // Moodle is free software: you can redistribute it and/or modify //
9 // it under the terms of the GNU General Public License as published by //
10 // the Free Software Foundation, either version 3 of the License, or //
11 // (at your option) any later version. //
13 // Moodle is distributed in the hope that it will be useful, //
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
16 // GNU General Public License for more details. //
18 // You should have received a copy of the GNU General Public License //
19 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
21 ///////////////////////////////////////////////////////////////////////////
24 * This page display the publication backup form
28 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
30 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
33 define('NO_OUTPUT_BUFFERING', true);
35 require_once('../../config.php');
36 require_once($CFG->dirroot
. '/backup/util/includes/backup_includes.php');
37 require_once($CFG->dirroot
. '/backup/moodle2/backup_plan_builder.class.php');
38 require_once($CFG->libdir
. '/filelib.php');
41 //retrieve initial page parameters
42 $id = required_param('id', PARAM_INT
);
43 $hubcourseid = required_param('hubcourseid', PARAM_INT
);
45 //some permissions and parameters checking
46 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST
);
47 require_login($course);
48 if (!has_capability('moodle/course:publish', context_course
::instance($id))
49 or !confirm_sesskey()) {
50 throw new moodle_exception('nopermission');
54 $PAGE->set_url('/course/publish/backup.php');
55 $PAGE->set_pagelayout('incourse');
56 $PAGE->set_title(get_string('course') . ': ' . $course->fullname
);
57 $PAGE->set_heading($course->fullname
);
59 //BEGIN backup processing
60 $backupid = optional_param('backup', false, PARAM_ALPHANUM
);
61 if (!($bc = backup_ui
::load_controller($backupid))) {
62 $bc = new backup_controller(backup
::TYPE_1COURSE
, $id, backup
::FORMAT_MOODLE
,
63 backup
::INTERACTIVE_YES
, backup
::MODE_HUB
, $USER->id
);
65 $backup = new backup_ui($bc,
66 array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL
, 'hubname' => 'Moodle.net'));
68 if ($backup->get_stage() == backup_ui
::STAGE_FINAL
) {
71 $backup->save_controller();
74 if ($backup->get_stage() !== backup_ui
::STAGE_COMPLETE
) {
75 $renderer = $PAGE->get_renderer('core', 'backup');
76 echo $OUTPUT->header();
77 echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
78 if ($backup->enforce_changed_dependencies()) {
79 debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER
);
81 echo $renderer->progress_bar($backup->get_progress_bar());
82 echo $backup->display($renderer);
83 echo $OUTPUT->footer();
87 //$backupfile = $backup->get_stage_results();
88 $backupfile = $bc->get_results();
89 $backupfile = $backupfile['backup_destination'];
90 //END backup processing
92 //display the sending file page
93 echo $OUTPUT->header();
94 echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
95 $renderer = $PAGE->get_renderer('core', 'course');
96 echo $renderer->sendingbackupinfo($backupfile);
102 //send backup file to the hub
103 \core\hub\publication
::upload_course_backup($hubcourseid, $backupfile);
105 //delete the temp backup file from user_tohub aera
106 $backupfile->delete();
109 //Output sending success
110 echo $renderer->sentbackupinfo($id, HUB_MOODLEORGHUBURL
, 'Moodle.net');
112 echo $OUTPUT->footer();