From 94a8d2e2e289b18b162fe026809dec8aa8f2b75d Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 11 Jul 2017 13:48:25 +0800 Subject: [PATCH] MDL-53492 registration: use https://moodle.net as hub url --- admin/registration/forms.php | 2 +- blocks/community/forms.php | 7 +++++++ lib/db/upgrade.php | 29 +++++++++++++++++++++++++++++ lib/moodlelib.php | 7 ++++--- version.php | 2 +- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/admin/registration/forms.php b/admin/registration/forms.php index af26d35aff6..40ea925367d 100644 --- a/admin/registration/forms.php +++ b/admin/registration/forms.php @@ -128,7 +128,7 @@ class hub_selector_form extends moodleform { //remove moodle.org from the hub list foreach ($hubs as $key => $hub) { - if ($hub['url'] == HUB_MOODLEORGHUBURL) { + if ($hub['url'] == HUB_MOODLEORGHUBURL || $hub['url'] == HUB_OLDMOODLEORGHUBURL) { unset($hubs[$key]); } } diff --git a/blocks/community/forms.php b/blocks/community/forms.php index c5159119fdb..a61b2732cde 100644 --- a/blocks/community/forms.php +++ b/blocks/community/forms.php @@ -109,6 +109,13 @@ class community_hub_search_form extends moodleform { $mform->addElement('static', 'errorhub', '', $error); } + // Hubdirectory returns old URL for the moodle.net hub, substitute it. + foreach ($hubs as $key => $hub) { + if ($hub['url'] === HUB_OLDMOODLEORGHUBURL) { + $hubs[$key]['url'] = HUB_MOODLEORGHUBURL; + } + } + //display list of registered on hub $registrationmanager = new registration_manager(); $registeredhubs = $registrationmanager->get_registered_on_hubs(); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 6e7dbf6e671..fb389dc1f5f 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2875,5 +2875,34 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2017051500.06); } + if ($oldversion < 2017051501.04) { + + // If the site was previously registered with http://hub.moodle.org change the registration to + // point to https://moodle.net - this is the correct hub address using https protocol. + $oldhuburl = "http://hub.moodle.org"; + $newhuburl = "https://moodle.net"; + $cleanoldhuburl = preg_replace('/[^A-Za-z0-9_-]/i', '', $oldhuburl); + $cleannewhuburl = preg_replace('/[^A-Za-z0-9_-]/i', '', $newhuburl); + + // Update existing registration. + $DB->execute("UPDATE {registration_hubs} SET hubname = ?, huburl = ? WHERE huburl = ?", + ['Moodle.net', $newhuburl, $oldhuburl]); + + // Update settings of existing registration. + $sqlnamelike = $DB->sql_like('name', '?'); + $entries = $DB->get_records_sql("SELECT * FROM {config_plugins} where plugin=? and " . $sqlnamelike, + ['hub', '%' . $DB->sql_like_escape('_' . $cleanoldhuburl)]); + foreach ($entries as $entry) { + $newname = substr($entry->name, 0, -strlen($cleanoldhuburl)) . $cleannewhuburl; + $DB->update_record('config_plugins', ['id' => $entry->id, 'name' => $newname]); + } + + // Update published courses. + $DB->execute('UPDATE {course_published} SET huburl = ? WHERE huburl = ?', [$newhuburl, $oldhuburl]); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2017051501.04); + } + return true; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 96d13f4048c..9e5ede0ded3 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -488,13 +488,14 @@ define('HOMEPAGE_USER', 2); /** * Hub directory url (should be moodle.org) */ -define('HUB_HUBDIRECTORYURL', "http://hubdirectory.moodle.org"); +define('HUB_HUBDIRECTORYURL', "https://hubdirectory.moodle.org"); /** - * Moodle.org url (should be moodle.org) + * Moodle.net url (should be moodle.net) */ -define('HUB_MOODLEORGHUBURL', "http://hub.moodle.org"); +define('HUB_MOODLEORGHUBURL', "https://moodle.net"); +define('HUB_OLDMOODLEORGHUBURL', "http://hub.moodle.org"); /** * Moodle mobile app service name diff --git a/version.php b/version.php index 710eb9679ea..57b5fe02255 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2017051501.03; // 20170515 = branching date YYYYMMDD - do not modify! +$version = 2017051501.04; // 20170515 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes.