Merge branch 'MDL-57900_master' of git://github.com/dmonllao/moodle
[moodle.git] / course / publish / backup.php
blob5194773ab843596d508231c342a7a5445f83c144
1 <?php
3 ///////////////////////////////////////////////////////////////////////////
4 // //
5 // This file is part of Moodle - http://moodle.org/ //
6 // Moodle - Modular Object-Oriented Dynamic Learning Environment //
7 // //
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. //
12 // //
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. //
17 // //
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/>. //
20 // //
21 ///////////////////////////////////////////////////////////////////////////
23 /**
24 * This page display the publication backup form
26 * @package course
27 * @subpackage publish
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);
49 $context = context_course::instance($courseid);
50 if (empty($CFG->enablecoursepublishing) || !has_capability('moodle/course:publish', $context) || !confirm_sesskey()) {
51 throw new moodle_exception('nopermission');
54 //page settings
55 $PAGE->set_url('/course/publish/backup.php');
56 $PAGE->set_pagelayout('incourse');
57 $PAGE->set_title(get_string('course') . ': ' . $course->fullname);
58 $PAGE->set_heading($course->fullname);
60 //BEGIN backup processing
61 $backupid = optional_param('backup', false, PARAM_ALPHANUM);
62 if (!($bc = backup_ui::load_controller($backupid))) {
63 $bc = new backup_controller(backup::TYPE_1COURSE, $id, backup::FORMAT_MOODLE,
64 backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id);
66 $backup = new backup_ui($bc,
67 array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.net'));
68 $backup->process();
69 if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
70 $backup->execute();
71 } else {
72 $backup->save_controller();
75 if ($backup->get_stage() !== backup_ui::STAGE_COMPLETE) {
76 $renderer = $PAGE->get_renderer('core', 'backup');
77 echo $OUTPUT->header();
78 echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
79 if ($backup->enforce_changed_dependencies()) {
80 debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
82 echo $renderer->progress_bar($backup->get_progress_bar());
83 echo $backup->display($renderer);
84 echo $OUTPUT->footer();
85 die();
88 //$backupfile = $backup->get_stage_results();
89 $backupfile = $bc->get_results();
90 $backupfile = $backupfile['backup_destination'];
91 //END backup processing
93 //display the sending file page
94 echo $OUTPUT->header();
95 echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
96 $renderer = $PAGE->get_renderer('core', 'course');
97 echo $renderer->sendingbackupinfo($backupfile);
98 if (ob_get_level()) {
99 ob_flush();
101 flush();
103 //send backup file to the hub
104 \core\hub\publication::upload_course_backup($hubcourseid, $backupfile);
106 //delete the temp backup file from user_tohub aera
107 $backupfile->delete();
108 $bc->destroy();
110 //Output sending success
111 echo $renderer->sentbackupinfo($id, HUB_MOODLEORGHUBURL, 'Moodle.net');
113 echo $OUTPUT->footer();