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 ///////////////////////////////////////////////////////////////////////////
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
30 * This page display the publication backup form
33 require_once('../../config.php');
34 require_once($CFG->dirroot
. '/backup/util/includes/backup_includes.php');
35 require_once($CFG->dirroot
. '/backup/moodle2/backup_plan_builder.class.php');
36 require_once($CFG->dirroot
. '/' . $CFG->admin
. '/registration/lib.php');
37 require_once($CFG->dirroot
. '/course/publish/lib.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
);
44 $huburl = required_param('huburl', PARAM_URL
);
45 $hubname = optional_param('hubname', '', PARAM_TEXT
);
47 //some permissions and parameters checking
48 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST
);
49 require_login($course);
50 if (!has_capability('moodle/course:publish', get_context_instance(CONTEXT_COURSE
, $id))
51 or !confirm_sesskey()) {
52 throw new moodle_exception('nopermission');
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
);
61 //BEGIN backup processing
62 $backupid = optional_param('backup', false, PARAM_ALPHANUM
);
63 if (!($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
);
67 $backup = new backup_ui($bc,
68 array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => $huburl, 'hubname' => $hubname));
70 if ($backup->get_stage() == backup_ui
::STAGE_FINAL
) {
73 $backup->save_controller();
76 if ($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()) {
81 echo $renderer->dependency_notification(get_string('dependenciesenforced', 'backup'));
83 echo $renderer->progress_bar($backup->get_progress_bar());
84 echo $backup->display();
85 echo $OUTPUT->footer();
89 //$backupfile = $backup->get_stage_results();
90 $backupfile = $bc->get_results();
91 $backupfile = $backupfile['backup_destination'];
92 //END backup processing
94 //retrieve the token to call the hub
95 $registrationmanager = new registration_manager();
96 $registeredhub = $registrationmanager->get_registeredhub($huburl);
98 //display the sending file page
99 echo $OUTPUT->header();
100 echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
101 $renderer = $PAGE->get_renderer('core', 'publish');
102 echo $renderer->sendingbackupinfo($backupfile);
103 if (ob_get_level()) {
108 //send backup file to the hub
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);
117 //delete the temp backup file from user_tohub aera
118 $backupfile->delete();
121 //Output sending success
122 echo $renderer->sentbackupinfo($id, $huburl, $hubname);
124 echo $OUTPUT->footer();