Merge branch 'MDL-65187-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Adrian Greeve
2019-10-07 11:12:21 +08:00
3 changed files with 27 additions and 8 deletions
+2 -1
View File
@@ -88,7 +88,8 @@ class api {
$curl = new curl();
$serverurl = HUB_MOODLEORGHUBURL . "/local/hub/webservice/webservices.php";
$curloutput = @json_decode($curl->get($serverurl, $params), true);
$query = http_build_query($params, '', '&');
$curloutput = @json_decode($curl->post($serverurl, $query), true);
$info = $curl->get_info();
if ($curl->get_errno()) {
// Connection error.
+24 -6
View File
@@ -40,11 +40,11 @@ use html_writer;
*/
class registration {
/** @var Fields used in a site registration form.
/** @var array Fields used in a site registration form.
* IMPORTANT: any new fields with non-empty defaults have to be added to CONFIRM_NEW_FIELDS */
const FORM_FIELDS = ['name', 'description', 'contactname', 'contactemail', 'contactphone', 'imageurl', 'privacy', 'street',
'regioncode', 'countrycode', 'geolocation', 'contactable', 'emailalert', 'emailalertemail', 'commnews', 'commnewsemail',
'language', 'policyagreed'];
const FORM_FIELDS = ['policyagreed', 'language', 'countrycode', 'privacy',
'contactemail', 'contactable', 'emailalert', 'emailalertemail', 'commnews', 'commnewsemail',
'contactname', 'name', 'description', 'imageurl', 'contactphone', 'regioncode', 'geolocation', 'street'];
/** @var List of new FORM_FIELDS or siteinfo fields added indexed by the version when they were added.
* If site was already registered, admin will be promted to confirm new registration data manually. Until registration is manually confirmed,
@@ -350,6 +350,13 @@ class registration {
$record['timemodified'] = time();
$DB->update_record('registration_hubs', $record);
self::$registration = null;
$siteinfo = self::get_site_info();
if (strlen(http_build_query($siteinfo)) > 1800) {
// Update registration again because the initial request was too long and could have been truncated.
api::update_registration($siteinfo);
self::$registration = null;
}
}
/**
@@ -398,10 +405,21 @@ class registration {
}
$params = self::get_site_info();
$params['token'] = $hub->token;
// The most conservative limit for the redirect URL length is 2000 characters. Only pass parameters before
// we reach this limit. The next registration update will update all fields.
// We will also update registration after we receive confirmation from moodle.net.
$url = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/siteregistration.php',
['token' => $hub->token, 'url' => $params['url']]);
foreach ($params as $key => $value) {
if (strlen($url->out(false, [$key => $value])) > 2000) {
break;
}
$url->param($key, $value);
}
$SESSION->registrationredirect = $returnurl;
redirect(new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/siteregistration.php', $params));
redirect($url);
}
/**
+1 -1
View File
@@ -75,7 +75,7 @@ class site_registration_form extends \moodleform {
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
$mform->addElement('text', 'name', get_string('sitename', 'hub'),
array('class' => 'registration_textfield'));
array('class' => 'registration_textfield', 'maxlength' => 255));
$mform->setType('name', PARAM_TEXT);
$mform->addHelpButton('name', 'sitename', 'hub');