diff --git a/admin/registration/confirmregistration.php b/admin/registration/confirmregistration.php index 7c9d422184b..ff99680ac8b 100644 --- a/admin/registration/confirmregistration.php +++ b/admin/registration/confirmregistration.php @@ -46,7 +46,7 @@ $error = optional_param('error', '', PARAM_ALPHANUM); admin_externalpage_setup('registrationmoodleorg'); if ($url !== HUB_MOODLEORGHUBURL) { - // Allow other plugins to confirm registration on hubs other than moodle.net . Plugins implementing this + // Allow other plugins to confirm registration on custom hubs. Plugins implementing this // callback need to redirect or exit. See https://docs.moodle.org/en/Hub_registration . $callbacks = get_plugins_with_function('hub_registration'); foreach ($callbacks as $plugintype => $plugins) { diff --git a/admin/registration/forms.php b/admin/registration/forms.php index 6fe95536333..af05a7a34fe 100644 --- a/admin/registration/forms.php +++ b/admin/registration/forms.php @@ -32,5 +32,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/hub/ .', DEBUG_DEVELOPER); +debugging('Support for alternative hubs has been removed from Moodle in 3.4.', DEBUG_DEVELOPER); diff --git a/admin/registration/index.php b/admin/registration/index.php index 62f251a4b44..2b1a01f8b36 100644 --- a/admin/registration/index.php +++ b/admin/registration/index.php @@ -22,7 +22,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com * - * This page displays the site registration form for Moodle.net. + * This page displays the site registration form. * It handles redirection to the hub to continue the registration workflow process. * It also handles update operation by web service. */ @@ -48,7 +48,7 @@ if ($unregistration && \core\hub\registration::is_registered()) { } echo $OUTPUT->header(); - echo $OUTPUT->heading(get_string('unregisterfrom', 'hub', 'Moodle.net'), 3, 'main'); + echo $OUTPUT->heading(get_string('registerwithmoodleorgremove', 'core_hub'), 3, 'main'); $siteunregistrationform->display(); echo $OUTPUT->footer(); exit; @@ -82,7 +82,7 @@ if ($fromform = $siteregistrationform->get_data()) { echo $OUTPUT->header(); -// Current status of registration on Moodle.net. +// Current status of registration. $notificationtype = \core\output\notification::NOTIFY_ERROR; if (\core\hub\registration::is_registered()) { @@ -104,11 +104,11 @@ if (\core\hub\registration::is_registered()) { // Heading. if (\core\hub\registration::is_registered()) { - echo $OUTPUT->heading(get_string('updatesite', 'hub', 'Moodle.net')); + echo $OUTPUT->heading(get_string('registerwithmoodleorgupdate', 'core_hub')); } else if ($isinitialregistration) { - echo $OUTPUT->heading(get_string('completeregistration', 'hub')); + echo $OUTPUT->heading(get_string('registerwithmoodleorgcomplete', 'core_hub')); } else { - echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'admin')); + echo $OUTPUT->heading(get_string('registerwithmoodleorg', 'core_hub')); } $renderer = $PAGE->get_renderer('core', 'admin'); diff --git a/admin/registration/renewregistration.php b/admin/registration/renewregistration.php index 84e727be323..bc05da60ffe 100644 --- a/admin/registration/renewregistration.php +++ b/admin/registration/renewregistration.php @@ -40,7 +40,7 @@ $token = optional_param('token', '', PARAM_TEXT); admin_externalpage_setup('registrationmoodleorg'); if ($url !== HUB_MOODLEORGHUBURL) { - // Allow other plugins to renew registration on hubs other than moodle.net . Plugins implementing this + // Allow other plugins to renew registration on custom hubs. Plugins implementing this // callback need to redirect or exit. See https://docs.moodle.org/en/Hub_registration . $callbacks = get_plugins_with_function('hub_registration'); foreach ($callbacks as $plugintype => $plugins) { @@ -56,7 +56,7 @@ if ($url !== HUB_MOODLEORGHUBURL) { echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('renewregistration', 'hub'), 3, 'main'); -$hublink = html_writer::tag('a', 'Moodle.net', array('href' => HUB_MOODLEORGHUBURL)); +$hublink = html_writer::tag('a', HUB_MOODLEORGHUBURL, array('href' => HUB_MOODLEORGHUBURL)); $deletedregmsg = get_string('previousregistrationdeleted', 'hub', $hublink); diff --git a/admin/renderer.php b/admin/renderer.php index 773ba4d3c1b..5abd08eaebb 100644 --- a/admin/renderer.php +++ b/admin/renderer.php @@ -2112,6 +2112,27 @@ class core_admin_renderer extends plugin_renderer_base { * @return string */ public function moodleorg_registration_message() { - return format_text(get_string('registermoodlenet', 'admin'), FORMAT_HTML, ['noclean' => true]); + + $out = format_text(get_string('registerwithmoodleorginfo', 'core_hub'), FORMAT_MARKDOWN); + + $out .= html_writer::link( + new moodle_url('/admin/settings.php', ['section' => 'moodleservices']), + $this->output->pix_icon('i/info', '').' '.get_string('registerwithmoodleorginfoapp', 'core_hub'), + ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href'] + ); + + $out .= html_writer::link( + HUB_MOODLEORGHUBURL, + $this->output->pix_icon('i/stats', '').' '.get_string('registerwithmoodleorginfostats', 'core_hub'), + ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href'] + ); + + $out .= html_writer::link( + HUB_MOODLEORGHUBURL.'/sites', + $this->output->pix_icon('i/location', '').' '.get_string('registerwithmoodleorginfosites', 'core_hub'), + ['class' => 'btn btn-link', 'role' => 'opener', 'target' => '_href'] + ); + + return $this->output->box($out); } } diff --git a/admin/tool/lp/classes/output/manage_competency_frameworks_page.php b/admin/tool/lp/classes/output/manage_competency_frameworks_page.php index 7a2181b586d..07a6dad7687 100644 --- a/admin/tool/lp/classes/output/manage_competency_frameworks_page.php +++ b/admin/tool/lp/classes/output/manage_competency_frameworks_page.php @@ -75,7 +75,7 @@ class manage_competency_frameworks_page implements renderable, templatable { ); $this->navigation[] = $addpage; $competenciesrepository = new single_button( - new moodle_url('https://moodle.net/competencies'), + new moodle_url('https://archive.moodle.net/competencies'), get_string('competencyframeworksrepository', 'tool_lp'), 'get' ); diff --git a/admin/tool/usertours/classes/manager.php b/admin/tool/usertours/classes/manager.php index f29f481aae3..c7e5b3e533f 100644 --- a/admin/tool/usertours/classes/manager.php +++ b/admin/tool/usertours/classes/manager.php @@ -257,7 +257,7 @@ class manager { 'title' => get_string('importtour', 'tool_usertours'), ], (object) [ - 'link' => new \moodle_url('https://moodle.net/tours'), + 'link' => new \moodle_url('https://archive.moodle.net/tours'), 'linkproperties' => [ 'target' => '_blank', ], diff --git a/lang/en/hub.php b/lang/en/hub.php index f0c71f8b00f..d1ab5d37c2f 100644 --- a/lang/en/hub.php +++ b/lang/en/hub.php @@ -82,7 +82,7 @@ $string['errorbadimageheightwidth'] = 'The image should have a maximum size of { $string['errorcourseinfo'] = 'An error occurred when retrieving course metadata from {$a}. Please try again to retrieve the course metadata by reloading this page later. Otherwise you can decide to continue the registration process with the following default metadata. '; $string['errorcoursepublish'] = 'An error occurred during the course publication ({$a}). Please try again later.'; $string['errorcoursewronglypublished'] = 'A publication error has been returned by Moodle.net. Please try again later.'; -$string['errorotherhubsnotsupported'] = 'This page can no longer be used for registration with sites other than Moodle.net'; +$string['errorotherhubsnotsupported'] = 'This page can no longer be used for registration with custom sites directories.'; $string['errorregistration'] = 'An error occurred during registration, please try again later. ({$a})'; $string['errorunpublishcourses'] = 'Due to an unexpected error, the courses could not be deleted from Moodle.net. Try again later (recommended) or contact Moodle.net administrator.'; $string['errorws'] = '{$a}'; @@ -119,7 +119,7 @@ $string['notregisteredonhub'] = 'Your administrator needs to register this site $string['operation'] = 'Actions'; $string['participantnumberaverage'] = 'Average number of participants ({$a})'; $string['policyagreed'] = 'Privacy notice and data processing agreement'; -$string['policyagreeddesc'] = 'I agree to the Privacy notice and data processing agreement for Moodle.net'; +$string['policyagreeddesc'] = 'I agree to the Privacy notice and data processing agreement'; $string['postaladdress'] = 'Postal address'; $string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.'; $string['postsnumber'] = 'Number of posts ({$a})'; @@ -140,6 +140,19 @@ $string['registrationinfo'] = 'Registration information'; $string['registereduserdevices'] = 'Number of users with registered mobile devices ({$a})'; $string['registeredactiveuserdevices'] = 'Number of active users with registered mobile devices which are receiving notifications ({$a})'; $string['registersite'] = 'Register with {$a}'; +$string['registerwithmoodleorg'] = 'Register your site'; +$string['registerwithmoodleorgupdate'] = 'Update your site registration'; +$string['registerwithmoodleorgcomplete'] = 'Complete your site registration'; +$string['registerwithmoodleorginfo'] = 'We\'d love to stay in touch and provide you with important things for your Moodle site! By registering: + +* You can subscribe to receive notifications of new Moodle releases, security alerts and other important news. +* You can access and activate mobile push notifications from your Moodle site through our free Moodle app. +* You are contributing to our Moodle statistics of the worldwide community, which help us improve Moodle and our community sites. +* If you wish, your site can be included in the list of registered Moodle sites in your country.'; +$string['registerwithmoodleorginfoapp'] = 'About the Moodle app'; +$string['registerwithmoodleorginfostats'] = 'Moodle statistics'; +$string['registerwithmoodleorginfosites'] = 'Other sites in my country'; +$string['registerwithmoodleorgremove'] = 'Unregistering your site'; $string['registrationconfirmed'] = 'Site registration confirmed'; $string['registrationconfirmedon'] = 'Thank you for registering your site. Registration information will be kept up to date by the \'Site registration\' scheduled task.'; $string['removefromhub'] = 'Remove from Moodle.net'; @@ -215,10 +228,11 @@ $string['unregisterfrom'] = 'Unregister from {$a}'; $string['unregistrationerror'] = 'An error occurred when the site tried to unregister from Moodle.net: {$a}'; $string['update'] = 'Update'; $string['updatesite'] = 'Update registration on {$a}'; +$string['updatesiteregistration'] = 'Update registration'; $string['updatestatus'] = 'Check it now.'; $string['usedifferentemail'] = 'Use different email'; -$string['unregisterexplained'] = 'If the site with URL {$a} is registered on Moodle.net its registration will be removed.'; -$string['urlalreadyregistered'] = 'Your site seems to be already registered on Moodle.net, which means something has gone wrong. Please contact the Moodle.net administrator to reset your registration so you can try again.'; +$string['unregisterexplained'] = 'If the site with URL {$a} is registered, then its registration will be removed.'; +$string['urlalreadyregistered'] = 'Your site seems to be already registered, which means something has gone wrong. Please contact the Moodle.net administrator to reset your registration so you can try again.'; $string['usersnumber'] = 'Number of users ({$a})'; $string['wrongtoken'] = 'The registration failed for some unknown reason (network?). Please try again.'; diff --git a/lib/classes/hub/api.php b/lib/classes/hub/api.php index 81711f1f6a7..40a0f9ec130 100644 --- a/lib/classes/hub/api.php +++ b/lib/classes/hub/api.php @@ -33,7 +33,7 @@ use coding_exception; use moodle_url; /** - * Methods to communicate with moodle.net web services + * Provides methods to communicate with the hub (sites directory) web services. * * @package core * @copyright 2017 Marina Glancy @@ -51,11 +51,11 @@ class api { const HUB_BACKUP_FILE_TYPE = 'backup'; /** - * Calls moodle.net WS + * Calls a remote function exposed via web services on the hub. * * @param string $function name of WS function * @param array $data parameters of WS function - * @param bool $allowpublic allow request without moodle.net registration + * @param bool $allowpublic allow request without registration on the hub * @return mixed depends on the function * @throws moodle_exception */ @@ -71,7 +71,7 @@ class api { } /** - * Performs REST request to moodle.net (using GET method) + * Performs a REST request to the hub site (using the GET method). * * @param string $token * @param string $function @@ -95,7 +95,7 @@ class api { // Connection error. throw new moodle_exception('errorconnect', 'hub', '', $curl->error); } else if (isset($curloutput['exception'])) { - // Exception occurred on moodle.net . + // Exception occurred on the remote side. self::process_curl_exception($token, $curloutput); } else if ($info['http_code'] != 200) { throw new moodle_exception('errorconnect', 'hub', '', $info['http_code']); @@ -105,7 +105,7 @@ class api { } /** - * Analyses exception received from moodle.net + * Analyses exception received from the hub server. * * @param string $token token used for CURL request * @param array $curloutput output from CURL request @@ -128,7 +128,7 @@ class api { } /** - * Update site registration on moodle.net + * Update site registration on the hub. * * @param array $siteinfo * @throws moodle_exception @@ -139,20 +139,20 @@ class api { } /** - * Returns information about moodle.net + * Returns information about the hub. * * Example of the return array: * { * "courses": 384, - * "description": "Moodle.net connects you with free content and courses shared by Moodle ...", - * "downloadablecourses": 190, - * "enrollablecourses": 194, + * "description": "Official Moodle sites directory.", + * "downloadablecourses": 0, + * "enrollablecourses": 0, * "hublogo": 1, * "language": "en", - * "name": "Moodle.net", + * "name": "moodle", * "sites": 274175, - * "url": "https://moodle.net", - * "imgurl": "https://moodle.net/local/hub/webservice/download.php?filetype=hubscreenshot" + * "url": "https://stats.moodle.org", + * "imgurl": "https://stats.moodle.org/local/hub/webservice/download.php?filetype=hubscreenshot" * } * * @return array @@ -358,7 +358,7 @@ class api { * * @param array|\stdClass $courseinfo * @return int id of the published course on the hub - * @throws moodle_exception if communication to moodle.net failed or course could not be published + * @throws moodle_exception if the communication with the hub failed or the course could not be published */ public static function register_course($courseinfo) { $params = array('courses' => array($courseinfo)); @@ -372,7 +372,7 @@ class api { /** * Uploads a screenshot for the published course * - * @param int $hubcourseid id of the published course on moodle.net, it must be published from this site + * @param int $hubcourseid id of the published course on the hub, it must be published from this site * @param \stored_file $file * @param int $screenshotnumber ordinal number of the screenshot */ @@ -391,7 +391,7 @@ class api { /** * Downloads course backup * - * @param int $hubcourseid id of the course on moodle.net + * @param int $hubcourseid id of the course on the hub * @param string $path local path (in tempdir) to save the downloaded backup to. */ public static function download_course_backup($hubcourseid, $path) { @@ -415,7 +415,7 @@ class api { /** * Uploads a course backup * - * @param int $hubcourseid id of the published course on moodle.net, it must be published from this site + * @param int $hubcourseid id of the published course on the hub, it must be published from this site * @param \stored_file $backupfile */ public static function upload_course_backup($hubcourseid, \stored_file $backupfile) { diff --git a/lib/classes/hub/registration.php b/lib/classes/hub/registration.php index cead3bb7544..cd716ef0084 100644 --- a/lib/classes/hub/registration.php +++ b/lib/classes/hub/registration.php @@ -32,7 +32,7 @@ use stdClass; use html_writer; /** - * Methods to use when publishing and searching courses on moodle.net + * Methods to use when registering the site at the moodle sites directory. * * @package core * @copyright 2017 Marina Glancy @@ -147,7 +147,7 @@ class registration { } /** - * Calculates and prepares site information to send to moodle.net as part of registration or update + * Calculates and prepares site information to send to the sites directory as a part of registration. * * @param array $defaults default values for inputs in the registration form (if site was never registered before) * @return array site info @@ -158,9 +158,8 @@ class registration { require_once($CFG->dirroot . "/course/lib.php"); $siteinfo = array(); - $cleanhuburl = clean_param(HUB_MOODLEORGHUBURL, PARAM_ALPHANUMEXT); foreach (self::FORM_FIELDS as $field) { - $siteinfo[$field] = get_config('hub', 'site_'.$field.'_' . $cleanhuburl); + $siteinfo[$field] = get_config('hub', 'site_'.$field); if ($siteinfo[$field] === false) { $siteinfo[$field] = array_key_exists($field, $defaults) ? $defaults[$field] : null; } @@ -210,7 +209,7 @@ class registration { } /** - * Human-readable summary of data that will be sent to moodle.net + * Human-readable summary of data that will be sent to the sites directory. * * @param array $siteinfo result of get_site_info() * @return string @@ -264,13 +263,12 @@ class registration { * @param stdClass $formdata data from {@link site_registration_form} */ public static function save_site_info($formdata) { - $cleanhuburl = clean_param(HUB_MOODLEORGHUBURL, PARAM_ALPHANUMEXT); foreach (self::FORM_FIELDS as $field) { - set_config('site_' . $field . '_' . $cleanhuburl, $formdata->$field, 'hub'); + set_config('site_' . $field, $formdata->$field, 'hub'); } - // Even if the the connection with moodle.net fails, admin has manually submitted the form which means they don't need + // Even if the connection with the sites directory fails, admin has manually submitted the form which means they don't need // to be redirected to the site registration page any more. - set_config('site_regupdateversion_' . $cleanhuburl, max(array_keys(self::CONFIRM_NEW_FIELDS)), 'hub'); + set_config('site_regupdateversion', max(array_keys(self::CONFIRM_NEW_FIELDS)), 'hub'); } /** @@ -329,7 +327,7 @@ class registration { } /** - * Confirms registration by moodle.net + * Confirms registration by the sites directory. * * @param string $token * @param string $newtoken @@ -375,8 +373,8 @@ class registration { * Registers a site * * This method will make sure that unconfirmed registration record is created and then redirect to - * registration script on https://moodle.net - * Moodle.net will check that the site is accessible, register it and redirect back + * registration script on the sites directory. + * The sites directory will check that the site is accessible, register it and redirect back * to /admin/registration/confirmregistration.php * * @param string $returnurl @@ -397,7 +395,7 @@ class registration { $hub->token = get_site_identifier(); $hub->secret = $hub->token; $hub->huburl = HUB_MOODLEORGHUBURL; - $hub->hubname = 'Moodle.net'; + $hub->hubname = 'moodle'; $hub->confirmed = 0; $hub->timemodified = time(); $hub->id = $DB->insert_record('registration_hubs', $hub); @@ -487,20 +485,20 @@ class registration { } /** - * Returns information about moodle.net + * Returns information about the sites directory. * * Example of the return array: * { * "courses": 384, - * "description": "Moodle.net connects you with free content and courses shared by Moodle ...", - * "downloadablecourses": 190, - * "enrollablecourses": 194, + * "description": "Official moodle sites directory", + * "downloadablecourses": 0, + * "enrollablecourses": 0, * "hublogo": 1, * "language": "en", - * "name": "Moodle.net", + * "name": "moodle", * "sites": 274175, - * "url": "https://moodle.net", - * "imgurl": moodle_url : "https://moodle.net/local/hub/webservice/download.php?filetype=hubscreenshot" + * "url": "https://stats.moodle.org", + * "imgurl": "https://stats.moodle.org/local/hub/webservice/download.php?filetype=hubscreenshot" * } * * @return array|null @@ -509,8 +507,8 @@ class registration { try { return api::get_hub_info(); } catch (moodle_exception $e) { - // Ignore error, we only need it for displaying information about moodle.net, if this request - // fails, it's not a big deal. + // Ignore error, we only need it for displaying information about the sites directory. + // If this request fails, it's not a big deal. return null; } } @@ -555,8 +553,7 @@ class registration { return $fieldsneedconfirm; } - $cleanhuburl = clean_param(HUB_MOODLEORGHUBURL, PARAM_ALPHANUMEXT); - $lastupdated = (int)get_config('hub', 'site_regupdateversion_' . $cleanhuburl); + $lastupdated = (int)get_config('hub', 'site_regupdateversion'); foreach (self::CONFIRM_NEW_FIELDS as $version => $fields) { if ($version > $lastupdated) { $fieldsneedconfirm = array_merge($fieldsneedconfirm, $fields); diff --git a/lib/classes/hub/site_registration_form.php b/lib/classes/hub/site_registration_form.php index 0369aa3958d..f58f9ef9560 100644 --- a/lib/classes/hub/site_registration_form.php +++ b/lib/classes/hub/site_registration_form.php @@ -32,7 +32,7 @@ global $CFG; require_once($CFG->libdir . '/formslib.php'); /** - * The site registration form. Information will be sent to moodle.net + * The site registration form. Information will be sent to the sites directory. * * @author Jerome Mouneyrac * @package core @@ -161,16 +161,16 @@ class site_registration_form extends \moodleform { $mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $siteinfo['url']); $mform->addHelpButton('urlstring', 'siteurl', 'hub'); - // Display statistic that are going to be retrieve by moodle.net. + // Display statistic that are going to be retrieve by the sites directory. $mform->addElement('static', 'siteinfosummary', get_string('sendfollowinginfo', 'hub'), registration::get_stats_summary($siteinfo)); // Check if it's a first registration or update. if (registration::is_registered()) { - $buttonlabel = get_string('updatesite', 'hub', 'Moodle.net'); + $buttonlabel = get_string('updatesiteregistration', 'core_hub'); $mform->addElement('hidden', 'update', true); $mform->setType('update', PARAM_BOOL); } else { - $buttonlabel = get_string('registersite', 'hub', 'Moodle.net'); + $buttonlabel = get_string('register', 'core_admin'); } $this->add_action_buttons(false, $buttonlabel); diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index a903d3dc813..54af7a5da2a 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3428,5 +3428,23 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2019052002.01); } + if ($oldversion < 2019052002.07) { + // Rename the official moodle sites directory the site is registered with. + $DB->execute("UPDATE {registration_hubs} + SET hubname = ?, huburl = ? + WHERE huburl = ?", ['moodle', 'https://stats.moodle.org', 'https://moodle.net']); + + // Convert the hub site specific settings to the new naming format without the hub URL in the name. + $hubconfig = get_config('hub'); + + if (!empty($hubconfig)) { + foreach (upgrade_convert_hub_config_site_param_names($hubconfig, 'https://moodle.net') as $name => $value) { + set_config($name, $value, 'hub'); + } + } + + upgrade_main_savepoint(true, 2019052002.07); + } + return true; } diff --git a/lib/db/upgradelib.php b/lib/db/upgradelib.php index e7e162fb78a..f7eefbb919c 100644 --- a/lib/db/upgradelib.php +++ b/lib/db/upgradelib.php @@ -350,10 +350,10 @@ function upgrade_course_letter_boundary($courseid = null) { } $lettercolumnsql = ''; if ($usergradelettercolumnsetting) { - // the system default is to show a column with letters (and the course uses the defaults). + // The system default is to show a column with letters (and the course uses the defaults). $lettercolumnsql = '(gss.value is NULL OR ' . $DB->sql_compare_text('gss.value') . ' <> \'0\')'; } else { - // the course displays a column with letters. + // The course displays a column with letters. $lettercolumnsql = $DB->sql_compare_text('gss.value') . ' = \'1\''; } @@ -566,3 +566,47 @@ function upgrade_delete_orphaned_file_records() { $DB->delete_records_list('files_reference', 'id', $deletedfileids); } + +/** + * Convert the site settings for the 'hub' component in the config_plugins table. + * + * @param stdClass $hubconfig Settings loaded for the 'hub' component. + * @param string $huburl The URL of the hub to use as the valid one in case of conflict. + * @return stdClass List of new settings to be applied (including null values to be unset). + */ +function upgrade_convert_hub_config_site_param_names(stdClass $hubconfig, string $huburl): stdClass { + + $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT); + $converted = []; + + foreach ($hubconfig as $oldname => $value) { + if (preg_match('/^site_([a-z]+)([A-Za-z0-9_-]*)/', $oldname, $matches)) { + $newname = 'site_'.$matches[1]; + + if ($oldname === $newname) { + // There is an existing value with the new naming convention already. + $converted[$newname] = $value; + + } else if (!array_key_exists($newname, $converted)) { + // Add the value under a new name and mark the original to be unset. + $converted[$newname] = $value; + $converted[$oldname] = null; + + } else if ($matches[2] === '_'.$cleanhuburl) { + // The new name already exists, overwrite only if coming from the valid hub. + $converted[$newname] = $value; + $converted[$oldname] = null; + + } else { + // Just unset the old value. + $converted[$oldname] = null; + } + + } else { + // Not a hub-specific site setting, just keep it. + $converted[$oldname] = $value; + } + } + + return (object) $converted; +} diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 334ff65d4b8..97ef382cfc1 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -491,11 +491,10 @@ define('HOMEPAGE_USER', 2); */ define('HUB_HUBDIRECTORYURL', "https://hubdirectory.moodle.org"); - /** - * Moodle.net url (should be moodle.net) + * URL of the Moodle sites registration portal. */ -define('HUB_MOODLEORGHUBURL', "https://moodle.net"); +defined('HUB_MOODLEORGHUBURL') || define('HUB_MOODLEORGHUBURL', 'https://stats.moodle.org'); define('HUB_OLDMOODLEORGHUBURL', "http://hub.moodle.org"); /** diff --git a/lib/tests/upgradelib_test.php b/lib/tests/upgradelib_test.php index 61c29af3b0e..61b3c1ffb02 100644 --- a/lib/tests/upgradelib_test.php +++ b/lib/tests/upgradelib_test.php @@ -1005,4 +1005,52 @@ class core_upgradelib_testcase extends advanced_testcase { $file = reset($files); $this->assertEquals($file, $newstoredfile[1]); } + + /** + * Test the functionality of the {@link upgrade_convert_hub_config_site_param_names()} function. + */ + public function test_upgrade_convert_hub_config_site_param_names() { + + $config = (object) [ + // This is how site settings related to registration at https://moodle.net are stored. + 'site_name_httpsmoodlenet' => 'Foo Site', + 'site_language_httpsmoodlenet' => 'en', + 'site_emailalert_httpsmoodlenet' => 1, + // These are unexpected relics of a value as registered at the old http://hub.moodle.org site. + 'site_name_httphubmoodleorg' => 'Bar Site', + 'site_description_httphubmoodleorg' => 'Old description', + // This is the target value we are converting to - here it already somehow exists. + 'site_emailalert' => 0, + // This is a setting not related to particular hub. + 'custom' => 'Do not touch this', + // A setting defined for multiple alternative hubs. + 'site_foo_httpfirsthuborg' => 'First', + 'site_foo_httpanotherhubcom' => 'Another', + 'site_foo_httpyetanotherhubcom' => 'Yet another', + // A setting defined for multiple alternative hubs and one referential one. + 'site_bar_httpfirsthuborg' => 'First', + 'site_bar_httpanotherhubcom' => 'Another', + 'site_bar_httpsmoodlenet' => 'One hub to rule them all!', + 'site_bar_httpyetanotherhubcom' => 'Yet another', + ]; + + $converted = upgrade_convert_hub_config_site_param_names($config, 'https://moodle.net'); + + // Values defined for the moodle.net take precedence over the ones defined for other hubs. + $this->assertSame($converted->site_name, 'Foo Site'); + $this->assertSame($converted->site_bar, 'One hub to rule them all!'); + $this->assertNull($converted->site_name_httpsmoodlenet); + $this->assertNull($converted->site_bar_httpfirsthuborg); + $this->assertNull($converted->site_bar_httpanotherhubcom); + $this->assertNull($converted->site_bar_httpyetanotherhubcom); + // Values defined for alternative hubs only do not have any guaranteed value. Just for convenience, we use the first one. + $this->assertSame($converted->site_foo, 'First'); + $this->assertNull($converted->site_foo_httpfirsthuborg); + $this->assertNull($converted->site_foo_httpanotherhubcom); + $this->assertNull($converted->site_foo_httpyetanotherhubcom); + // Values that are already defined with the new name format are kept. + $this->assertSame($converted->site_emailalert, 0); + // Eventual custom values not following the expected hub-specific naming format, are kept. + $this->assertSame($converted->custom, 'Do not touch this'); + } } diff --git a/theme/boost/lang/en/theme_boost.php b/theme/boost/lang/en/theme_boost.php index 1867cb3f4cd..1133f7bf996 100644 --- a/theme/boost/lang/en/theme_boost.php +++ b/theme/boost/lang/en/theme_boost.php @@ -40,7 +40,7 @@ $string['generalsettings'] = 'General settings'; $string['nobootswatch'] = 'None'; $string['pluginname'] = 'Boost'; $string['presetfiles'] = 'Additional theme preset files'; -$string['presetfiles_desc'] = 'Preset files can be used to dramatically alter the appearance of the theme. See Boost presets for information on creating and sharing your own preset files, and see the Presets repository for presets that others have shared.'; +$string['presetfiles_desc'] = 'Preset files can be used to dramatically alter the appearance of the theme. See Boost presets for information on creating and sharing your own preset files, and see the Presets repository for presets that others have shared.'; $string['preset'] = 'Theme preset'; $string['preset_desc'] = 'Pick a preset to broadly change the look of the theme.'; $string['privacy:metadata'] = 'The Boost theme does not store any personal data about any user.'; diff --git a/theme/classic/lang/en/theme_classic.php b/theme/classic/lang/en/theme_classic.php index 9dfd1d06261..e6f2da470cb 100644 --- a/theme/classic/lang/en/theme_classic.php +++ b/theme/classic/lang/en/theme_classic.php @@ -32,7 +32,7 @@ $string['navbardark'] = 'Use a dark style navbar'; $string['navbardarkdesc'] = 'Swaps text and background colours for the navbar at the top of the page between dark and light.'; $string['pluginname'] = 'Classic'; $string['presetfiles'] = 'Additional theme preset files'; -$string['presetfiles_desc'] = 'Preset files can be used to dramatically alter the appearance of the theme. See Boost presets for information on creating and sharing your own preset files, and see the Presets repository for presets that others have shared.'; +$string['presetfiles_desc'] = 'Preset files can be used to dramatically alter the appearance of the theme. See Boost presets for information on creating and sharing your own preset files, and see the Presets repository for presets that others have shared.'; $string['preset'] = 'Theme preset'; $string['preset_desc'] = 'Pick a preset to broadly change the look of the theme.'; $string['region-side-post'] = 'Right';