Merge branch 'wip-MDL-35056-stable23' of git://github.com/phalacee/moodle into MOODLE...
[moodle.git] / course / publish / backup.php
CommitLineData
770f7e24 1<?php
2
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///////////////////////////////////////////////////////////////////////////
22
23/*
24 * @package course
25 * @subpackage publish
26 * @author Jerome Mouneyrac <jerome@mouneyrac.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL
28 * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
29 *
30 * This page display the publication backup form
31 */
32
33require_once('../../config.php');
34require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
35require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
a8e174cc 36require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
37require_once($CFG->dirroot . '/course/publish/lib.php');
38require_once($CFG->libdir . '/filelib.php');
770f7e24 39
40
41//retrieve initial page parameters
0d731457 42$id = required_param('id', PARAM_INT);
43$hubcourseid = required_param('hubcourseid', PARAM_INT);
44$huburl = required_param('huburl', PARAM_URL);
770f7e24 45$hubname = optional_param('hubname', '', PARAM_TEXT);
46
47//some permissions and parameters checking
48$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
49require_login($course);
50if (!has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE, $id))
51 or !confirm_sesskey()) {
52 throw new moodle_exception('nopermission');
53}
770f7e24 54
55//page settings
56$PAGE->set_url('/course/publish/backup.php');
57$PAGE->set_pagelayout('course');
58$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
59$PAGE->set_heading($course->fullname);
60
61//BEGIN backup processing
62$backupid = optional_param('backup', false, PARAM_ALPHANUM);
63if (!($bc = backup_ui::load_controller($backupid))) {
64 $bc = new backup_controller(backup::TYPE_1COURSE, $id, backup::FORMAT_MOODLE,
65 backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id);
66}
67$backup = new backup_ui($bc,
68 array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => $huburl, 'hubname' => $hubname));
69$backup->process();
70if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
71 $backup->execute();
72} else {
73 $backup->save_controller();
74}
75
76if ($backup->get_stage() !== backup_ui::STAGE_COMPLETE) {
77 $renderer = $PAGE->get_renderer('core', 'backup');
78 echo $OUTPUT->header();
79 echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname)?$hubname:$huburl), 3, 'main');
80 if ($backup->enforce_changed_dependencies()) {
d4f5439d 81 debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
770f7e24 82 }
83 echo $renderer->progress_bar($backup->get_progress_bar());
b0fc1218 84 echo $backup->display($renderer);
770f7e24 85 echo $OUTPUT->footer();
86 die();
87}
88
89//$backupfile = $backup->get_stage_results();
90$backupfile = $bc->get_results();
91$backupfile = $backupfile['backup_destination'];
92//END backup processing
93
94//retrieve the token to call the hub
95$registrationmanager = new registration_manager();
96$registeredhub = $registrationmanager->get_registeredhub($huburl);
97
60cc2f78 98//display the sending file page
99echo $OUTPUT->header();
100echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
101$renderer = $PAGE->get_renderer('core', 'publish');
102echo $renderer->sendingbackupinfo($backupfile);
c78e1133
JM
103if (ob_get_level()) {
104 ob_flush();
105}
60cc2f78 106flush();
107
770f7e24 108//send backup file to the hub
109$curl = new curl();
110$params = array();
111$params['filetype'] = HUB_BACKUP_FILE_TYPE;
112$params['courseid'] = $hubcourseid;
113$params['file'] = $backupfile;
114$params['token'] = $registeredhub->token;
115$curl->post($huburl . "/local/hub/webservice/upload.php", $params);
116
117//delete the temp backup file from user_tohub aera
118$backupfile->delete();
0c92f113 119$bc->destroy();
770f7e24 120
60cc2f78 121//Output sending success
122echo $renderer->sentbackupinfo($id, $huburl, $hubname);
123
124echo $OUTPUT->footer();