Skip to content

Commit

Permalink
MDL-59495 course: publish courses on moodle.net only
Browse files Browse the repository at this point in the history
Remove support for alternative hubs
  • Loading branch information
marinaglancy committed Sep 27, 2017
1 parent ef467ff commit 8df792e
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 437 deletions.
22 changes: 4 additions & 18 deletions course/publish/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,12 @@
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');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot . '/course/publish/lib.php');
require_once($CFG->libdir . '/filelib.php');


//retrieve initial page parameters
$id = required_param('id', PARAM_INT);
$hubcourseid = required_param('hubcourseid', PARAM_INT);
$huburl = required_param('huburl', PARAM_URL);
$hubname = optional_param('hubname', '', PARAM_TEXT);

//some permissions and parameters checking
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
Expand All @@ -67,7 +63,7 @@
backup::INTERACTIVE_YES, backup::MODE_HUB, $USER->id);
}
$backup = new backup_ui($bc,
array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => $huburl, 'hubname' => $hubname));
array('id' => $id, 'hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL, 'hubname' => 'Moodle.net'));
$backup->process();
if ($backup->get_stage() == backup_ui::STAGE_FINAL) {
$backup->execute();
Expand All @@ -78,7 +74,7 @@
if ($backup->get_stage() !== backup_ui::STAGE_COMPLETE) {
$renderer = $PAGE->get_renderer('core', 'backup');
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', !empty($hubname)?$hubname:$huburl), 3, 'main');
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
if ($backup->enforce_changed_dependencies()) {
debugging('Your settings have been altered due to unmet dependencies', DEBUG_DEVELOPER);
}
Expand All @@ -93,10 +89,6 @@
$backupfile = $backupfile['backup_destination'];
//END backup processing

//retrieve the token to call the hub
$registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl);

//display the sending file page
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('sendingcourse', 'hub'), 3, 'main');
Expand All @@ -108,19 +100,13 @@
flush();

//send backup file to the hub
$curl = new curl();
$params = array();
$params['filetype'] = HUB_BACKUP_FILE_TYPE;
$params['courseid'] = $hubcourseid;
$params['file'] = $backupfile;
$params['token'] = $registeredhub->token;
$curl->post($huburl . "/local/hub/webservice/upload.php", $params);
\core\hub\publication::upload_course_backup($hubcourseid, $backupfile);

//delete the temp backup file from user_tohub aera
$backupfile->delete();
$bc->destroy();

//Output sending success
echo $renderer->sentbackupinfo($id, $huburl, $hubname);
echo $renderer->sentbackupinfo($id, HUB_MOODLEORGHUBURL, 'Moodle.net');

echo $OUTPUT->footer();
2 changes: 1 addition & 1 deletion course/publish/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
defined('MOODLE_INTERNAL') || die();

debugging('Support for alternative hubs has been removed from Moodle in 3.4. For communication with moodle.net ' .
'see lib/classes/moodlenet/ .', DEBUG_DEVELOPER);
'see lib/classes/hub/ .', DEBUG_DEVELOPER);
49 changes: 1 addition & 48 deletions course/publish/hubselector.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,5 @@

require('../../config.php');

require_once($CFG->dirroot.'/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot.'/course/publish/forms.php');

$id = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_login($course);

$PAGE->set_url('/course/publish/hubselector.php', array('id' => $course->id));
$PAGE->set_pagelayout('incourse');
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($course->fullname);

$registrationmanager = new registration_manager();
$registeredhubs = $registrationmanager->get_registered_on_hubs();
if (empty($registeredhubs)) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
echo $OUTPUT->box(get_string('notregisteredonhub', 'hub'));
echo $OUTPUT->footer();
die();
}


$share = optional_param('share', false, PARAM_BOOL);
$advertise = optional_param('advertise', false, PARAM_BOOL);
$hubselectorform = new hub_publish_selector_form('',
array('id' => $id, 'share' => $share, 'advertise' => $advertise));
$fromform = $hubselectorform->get_data();

//// Redirect to the registration form if an URL has been chosen ////
$huburl = optional_param('huburl', false, PARAM_URL);

//redirect
if (!empty($huburl) and confirm_sesskey()) {
$hubname = optional_param(clean_param($huburl, PARAM_ALPHANUMEXT), '', PARAM_TEXT);
$params = array('sesskey' => sesskey(), 'id' => $id,
'huburl' => $huburl, 'hubname' => $hubname, 'share' => $share, 'advertise' => $advertise);
redirect(new moodle_url($CFG->wwwroot."/course/publish/metadata.php",
$params));
}


//// OUTPUT ////


echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
$hubselectorform->display();
echo $OUTPUT->footer();
redirect(new moodle_url('/course/publish/index.php', ['id' => $id]));
179 changes: 47 additions & 132 deletions course/publish/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,155 +27,70 @@
*/

require('../../config.php');
require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php');
require_once($CFG->dirroot . '/course/publish/lib.php');

$id = required_param('id', PARAM_INT);
$hubname = optional_param('hubname', 0, PARAM_TEXT);
$huburl = optional_param('huburl', 0, PARAM_URL);
$courseid = required_param('id', PARAM_INT); // Course id.
$publicationid = optional_param('publicationid', 0, PARAM_INT); // Id of course publication to unpublish.

$course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
require_login($courseid);
$shortname = format_string($COURSE->shortname);

require_login($course);
$context = context_course::instance($course->id);
$shortname = format_string($course->shortname, true, array('context' => $context));

$PAGE->set_url('/course/publish/index.php', array('id' => $course->id));
$PAGE->set_url('/course/publish/index.php', array('id' => $courseid));
$PAGE->set_pagelayout('incourse');
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($course->fullname);
$PAGE->set_title(get_string('publish') . ': ' . $COURSE->fullname);
$PAGE->set_heading($COURSE->fullname);

require_capability('moodle/course:publish', context_course::instance($courseid));

//check that the PHP xmlrpc extension is enabled
if (!extension_loaded('xmlrpc')) {
$notificationerror = $OUTPUT->doc_link('admin/environment/php_extension/xmlrpc', '');
$notificationerror .= get_string('xmlrpcdisabledpublish', 'hub');
// If the site is not registered display an error page.
if (!\core\hub\registration::is_registered()) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $OUTPUT->notification($notificationerror);
echo $OUTPUT->heading(get_string('publishcourseon', 'hub', 'Moodle.net'), 3, 'main');
echo $OUTPUT->box(get_string('notregisteredonhub', 'hub'));
if (has_capability('moodle/site:config', context_system::instance())) {
echo $OUTPUT->single_button(new moodle_url('/admin/registration/index.php'), get_string('register', 'admin'));
}
echo $OUTPUT->footer();
die();
}

if (has_capability('moodle/course:publish', context_course::instance($id))) {

$publicationmanager = new course_publish_manager();
$confirmmessage = '';

//update the courses status
$updatestatusid = optional_param('updatestatusid', false, PARAM_INT);
if (!empty($updatestatusid) and confirm_sesskey()) {
//get the communication token from the publication
$hub = $publicationmanager->get_registeredhub_by_publication($updatestatusid);
if (empty($hub)) {
$confirmmessage = $OUTPUT->notification(get_string('nocheckstatusfromunreghub', 'hub'));
} else {
//get all site courses registered on this hub
$function = 'hub_get_courses';
$params = array('search' => '', 'downloadable' => 1,
'enrollable' => 1, 'options' => array( 'allsitecourses' => 1));
$serverurl = $hub->huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $hub->token);
$result = $xmlrpcclient->call($function, $params);
$sitecourses = $result['courses'];

//update status for all these course
foreach ($sitecourses as $sitecourse) {
//get the publication from the hub course id
$publication = $publicationmanager->get_publication($sitecourse['id'], $hub->huburl);
if (!empty($publication)) {
$publication->status = $sitecourse['privacy'];
$publication->timechecked = time();
$publicationmanager->update_publication($publication);
} else {
$msgparams = new stdClass();
$msgparams->id = $sitecourse['id'];
$msgparams->hubname = html_writer::tag('a', $hub->hubname, array('href' => $hub->huburl));
$confirmmessage .= $OUTPUT->notification(
get_string('detectednotexistingpublication', 'hub', $msgparams));
}
}
}
// When hub listing status is requested update statuses of all published courses.
$updatestatusid = optional_param('updatestatusid', false, PARAM_INT);
if (!empty($updatestatusid) && confirm_sesskey()) {
if (core\hub\publication::get_publication($updatestatusid, $courseid)) {
core\hub\publication::request_status_update();
redirect($PAGE->url);
}
}

//if the site os registered on no hub display an error page
$registrationmanager = new registration_manager();
$registeredhubs = $registrationmanager->get_registered_on_hubs();
if (empty($registeredhubs)) {
$renderer = $PAGE->get_renderer('core', 'publish');

// Unpublish course.
if ($publication = \core\hub\publication::get_publication($publicationid, $courseid)) {
$confirm = optional_param('confirm', 0, PARAM_BOOL);
if ($confirm && confirm_sesskey()) {
\core\hub\publication::unpublish($publication);
} else {
// Display confirmation page for unpublishing.
$publication = \core\hub\publication::get_publication($publicationid, $courseid, MUST_EXIST);
$publication->courseshortname = format_string($COURSE->shortname);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('publishon', 'hub'), 3, 'main');
echo $OUTPUT->box(get_string('notregisteredonhub', 'hub'));
echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->confirmunpublishing($publication);
echo $OUTPUT->footer();
die();
}
}

$renderer = $PAGE->get_renderer('core', 'publish');

/// UNPUBLISH
$cancel = optional_param('cancel', 0, PARAM_BOOL);
if (!empty($cancel) and confirm_sesskey()) {
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$hubcourseid = optional_param('hubcourseid', 0, PARAM_INT);
$publicationid = optional_param('publicationid', 0, PARAM_INT);
$timepublished = optional_param('timepublished', 0, PARAM_INT);
$publication = new stdClass();
$publication->courseshortname = $course->shortname;
$publication->courseid = $course->id;
$publication->hubname = $hubname;
$publication->huburl = $huburl;
$publication->hubcourseid = $hubcourseid;
$publication->timepublished = $timepublished;
if (empty($publication->hubname)) {
$publication->hubname = $huburl;
}
$publication->id = $publicationid;
if($confirm) {
//unpublish the publication by web service
$registeredhub = $registrationmanager->get_registeredhub($huburl);
$function = 'hub_unregister_courses';
$params = array('courseids' => array( $publication->hubcourseid));
$serverurl = $huburl."/local/hub/webservice/webservices.php";
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
$xmlrpcclient = new webservice_xmlrpc_client($serverurl, $registeredhub->token);
$result = $xmlrpcclient->call($function, $params);

//delete the publication from the database
$publicationmanager->delete_publication($publicationid);

//display confirmation message
$confirmmessage = $OUTPUT->notification(get_string('courseunpublished', 'hub', $publication), 'notifysuccess');

} else {
//display confirmation page for unpublishing

echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('unpublishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->confirmunpublishing($publication);
echo $OUTPUT->footer();
die();
}
}

//check if a course was published
if (optional_param('published', 0, PARAM_TEXT)) {
$confirmmessage = $OUTPUT->notification(get_string('coursepublished', 'hub',
empty($hubname)?$huburl:$hubname), 'notifysuccess');
}


/// OUTPUT
echo $OUTPUT->header();
echo $confirmmessage;

echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->publicationselector($course->id);

$publications = $publicationmanager->get_course_publications($course->id);
if (!empty($publications)) {
echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main');
echo $renderer->registeredonhublisting($course->id, $publications);
}
// List current publications and "Publish" buttons.
echo $OUTPUT->header();

echo $OUTPUT->footer();
echo $OUTPUT->heading(get_string('publishcourse', 'hub', $shortname), 3, 'main');
echo $renderer->publicationselector($courseid);

$publications = \core\hub\publication::get_course_publications($courseid);
if (!empty($publications)) {
echo $OUTPUT->heading(get_string('publishedon', 'hub'), 3, 'main');
echo $renderer->registeredonhublisting($courseid, $publications);
}

echo $OUTPUT->footer();
Loading

0 comments on commit 8df792e

Please sign in to comment.