Skip to content

Commit 2c9bb9c

Browse files
committed
registration MDL-22662 display explicit error message when ws communication fail when trying to retrieve hub listing from hub directory
1 parent 7399bce commit 2c9bb9c

File tree

2 files changed

+85
-77
lines changed

2 files changed

+85
-77
lines changed

admin/registration/forms.php

+84-77
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
///////////////////////////////////////////////////////////////////////////
34
// //
45
// This file is part of Moodle - http://moodle.org/ //
@@ -27,11 +28,11 @@
2728
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
2829
*
2930
* The forms needed by registration pages.
30-
*/
31+
*/
3132

3233

33-
require_once($CFG->dirroot.'/lib/formslib.php');
34-
require_once($CFG->dirroot.'/admin/registration/lib.php');
34+
require_once($CFG->dirroot . '/lib/formslib.php');
35+
require_once($CFG->dirroot . '/admin/registration/lib.php');
3536

3637
/**
3738
* This form display a hub selector.
@@ -41,17 +42,23 @@
4142
class hub_selector_form extends moodleform {
4243

4344
public function definition() {
44-
global $CFG;
45-
$mform =& $this->_form;
45+
global $CFG, $OUTPUT;
46+
$mform = & $this->_form;
4647
$mform->addElement('header', 'site', get_string('selecthub', 'hub'));
4748

4849
//retrieve the hub list on the hub directory by web service
4950
$function = 'hubdirectory_get_hubs';
5051
$params = array();
51-
$serverurl = HUB_HUBDIRECTORYURL."/local/hubdirectory/webservice/webservices.php";
52-
require_once($CFG->dirroot."/webservice/xmlrpc/lib.php");
52+
$serverurl = HUB_HUBDIRECTORYURL . "/local/hubdirectory/webservice/webservices.php";
53+
require_once($CFG->dirroot . "/webservice/xmlrpc/lib.php");
5354
$xmlrpcclient = new webservice_xmlrpc_client();
54-
$hubs = $xmlrpcclient->call($serverurl, 'publichubdirectory', $function, $params);
55+
try {
56+
$hubs = $xmlrpcclient->call($serverurl, 'publichubdirectory', $function, $params);
57+
} catch (Exception $e) {
58+
$error = $OUTPUT->notification(get_string('errorhublisting', 'hub', $e->getMessage()));
59+
$mform->addElement('static', 'errorhub', '', $error);
60+
$hubs = array();
61+
}
5562

5663
//remove moodle.org from the hub list
5764
foreach ($hubs as $key => $hub) {
@@ -64,23 +71,25 @@ public function definition() {
6471
$options = array();
6572
foreach ($hubs as $hub) {
6673
//to not display a name longer than 100 character (too big)
67-
if (strlen($hub['name'])>100) {
68-
$hubname = substr($hub['name'],0, 100);
69-
$hubname = $hubname."...";
74+
if (strlen($hub['name']) > 100) {
75+
$hubname = substr($hub['name'], 0, 100);
76+
$hubname = $hubname . "...";
7077
} else {
7178
$hubname = $hub['name'];
7279
}
7380
$options[$hub['url']] = $hubname;
7481
$mform->addElement('hidden', clean_param($hub['url'], PARAM_ALPHANUMEXT), $hubname);
7582
}
76-
$mform->addElement('select', 'publichub', get_string('publichub','hub'),
77-
$options, array("size" => 15));
83+
if (!empty($hubs)) {
84+
$mform->addElement('select', 'publichub', get_string('publichub', 'hub'),
85+
$options, array("size" => 15));
86+
}
7887

79-
$mform->addElement('static','or' , '', get_string('orenterprivatehub', 'hub'));
88+
$mform->addElement('static', 'or', '', get_string('orenterprivatehub', 'hub'));
8089

8190
//Private hub
82-
$mform->addElement('text','unlistedurl' , get_string('privatehuburl', 'hub'));
83-
$mform->addElement('text','password' , get_string('password'));
91+
$mform->addElement('text', 'unlistedurl', get_string('privatehuburl', 'hub'));
92+
$mform->addElement('text', 'password', get_string('password'));
8493

8594
$this->add_action_buttons(false, get_string('selecthub', 'hub'));
8695
}
@@ -106,7 +115,6 @@ function validation($data, $files) {
106115

107116
}
108117

109-
110118
/**
111119
* The site registration form. Information will be sent to a given hub.
112120
*/
@@ -116,7 +124,7 @@ public function definition() {
116124
global $CFG, $DB;
117125

118126
$strrequired = get_string('required');
119-
$mform =& $this->_form;
127+
$mform = & $this->_form;
120128
$huburl = $this->_customdata['huburl'];
121129
$hubname = $this->_customdata['hubname'];
122130
$password = $this->_customdata['password'];
@@ -125,44 +133,44 @@ public function definition() {
125133

126134
//retrieve config for this hub and set default if they don't exist
127135
$cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT);
128-
$sitename = get_config('hub', 'site_name_'.$cleanhuburl);
136+
$sitename = get_config('hub', 'site_name_' . $cleanhuburl);
129137
if ($sitename === false) {
130138
$sitename = $site->fullname;
131139
}
132-
$sitedescription = get_config('hub', 'site_description_'.$cleanhuburl);
140+
$sitedescription = get_config('hub', 'site_description_' . $cleanhuburl);
133141
if ($sitedescription === false) {
134142
$sitedescription = $site->summary;
135143
}
136-
$contactname = get_config('hub', 'site_contactname_'.$cleanhuburl);
144+
$contactname = get_config('hub', 'site_contactname_' . $cleanhuburl);
137145
if ($contactname === false) {
138146
$contactname = fullname($admin, true);
139147
}
140-
$contactemail = get_config('hub', 'site_contactemail_'.$cleanhuburl);
148+
$contactemail = get_config('hub', 'site_contactemail_' . $cleanhuburl);
141149
if ($contactemail === false) {
142150
$contactemail = $admin->email;
143151
}
144-
$contactphone = get_config('hub', 'site_contactphone_'.$cleanhuburl);
152+
$contactphone = get_config('hub', 'site_contactphone_' . $cleanhuburl);
145153
if ($contactphone === false) {
146154
$contactphone = $admin->phone1;
147155
}
148-
$imageurl = get_config('hub', 'site_imageurl_'.$cleanhuburl);
149-
$privacy = get_config('hub', 'site_privacy_'.$cleanhuburl);
150-
$address = get_config('hub', 'site_address_'.$cleanhuburl);
151-
$region = get_config('hub', 'site_region_'.$cleanhuburl);
152-
$country = get_config('hub', 'site_country_'.$cleanhuburl);
156+
$imageurl = get_config('hub', 'site_imageurl_' . $cleanhuburl);
157+
$privacy = get_config('hub', 'site_privacy_' . $cleanhuburl);
158+
$address = get_config('hub', 'site_address_' . $cleanhuburl);
159+
$region = get_config('hub', 'site_region_' . $cleanhuburl);
160+
$country = get_config('hub', 'site_country_' . $cleanhuburl);
153161
if ($country === false) {
154-
$country = $admin->country;
162+
$country = $admin->country;
155163
}
156-
$geolocation = get_config('hub', 'site_geolocation_'.$cleanhuburl);
157-
$contactable = get_config('hub', 'site_contactable_'.$cleanhuburl);
158-
$emailalert = get_config('hub', 'site_emailalert_'.$cleanhuburl);
159-
$coursesnumber = get_config('hub', 'site_coursesnumber_'.$cleanhuburl);
160-
$usersnumber = get_config('hub', 'site_usersnumber_'.$cleanhuburl);
161-
$roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_'.$cleanhuburl);
162-
$postsnumber = get_config('hub', 'site_postsnumber_'.$cleanhuburl);
163-
$questionsnumber = get_config('hub', 'site_questionsnumber_'.$cleanhuburl);
164-
$resourcesnumber = get_config('hub', 'site_resourcesnumber_'.$cleanhuburl);
165-
$mediancoursesize = get_config('hub', 'site_mediancoursesize_'.$cleanhuburl);
164+
$geolocation = get_config('hub', 'site_geolocation_' . $cleanhuburl);
165+
$contactable = get_config('hub', 'site_contactable_' . $cleanhuburl);
166+
$emailalert = get_config('hub', 'site_emailalert_' . $cleanhuburl);
167+
$coursesnumber = get_config('hub', 'site_coursesnumber_' . $cleanhuburl);
168+
$usersnumber = get_config('hub', 'site_usersnumber_' . $cleanhuburl);
169+
$roleassignmentsnumber = get_config('hub', 'site_roleassignmentsnumber_' . $cleanhuburl);
170+
$postsnumber = get_config('hub', 'site_postsnumber_' . $cleanhuburl);
171+
$questionsnumber = get_config('hub', 'site_questionsnumber_' . $cleanhuburl);
172+
$resourcesnumber = get_config('hub', 'site_resourcesnumber_' . $cleanhuburl);
173+
$mediancoursesize = get_config('hub', 'site_mediancoursesize_' . $cleanhuburl);
166174

167175
//hidden parameters
168176
$mform->addElement('hidden', 'huburl', $huburl);
@@ -172,7 +180,7 @@ public function definition() {
172180
//the input parameters
173181
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));
174182

175-
$mform->addElement('text','name' , get_string('sitename', 'hub'),
183+
$mform->addElement('text', 'name', get_string('sitename', 'hub'),
176184
array('class' => 'registration_textfield'));
177185
$mform->addRule('name', $strrequired, 'required', null, 'client');
178186
$mform->setType('name', PARAM_TEXT);
@@ -190,30 +198,30 @@ public function definition() {
190198
unset($options);
191199

192200
$mform->addElement('textarea', 'description', get_string('sitedesc', 'hub'),
193-
array('rows'=>8, 'cols'=>41));
201+
array('rows' => 8, 'cols' => 41));
194202
$mform->addRule('description', $strrequired, 'required', null, 'client');
195203
$mform->setDefault('description', $sitedescription);
196204
$mform->setType('description', PARAM_TEXT);
197205
$mform->addHelpButton('description', 'sitedesc', 'hub');
198206

199-
$mform->addElement('static', 'urlstring',get_string('siteurl', 'hub'), $CFG->wwwroot);
207+
$mform->addElement('static', 'urlstring', get_string('siteurl', 'hub'), $CFG->wwwroot);
200208
$mform->addHelpButton('urlstring', 'siteurl', 'hub');
201209

202210
$languages = get_string_manager()->get_list_of_languages();
203-
$mform->addElement('static', 'langstring',get_string('sitelang', 'hub'), $languages[current_language()]);
211+
$mform->addElement('static', 'langstring', get_string('sitelang', 'hub'), $languages[current_language()]);
204212
$mform->addElement('hidden', 'language', current_language());
205213
$mform->addHelpButton('langstring', 'sitelang', 'hub');
206214

207-
$mform->addElement('static', 'versionstring',get_string('siteversion', 'hub'), $CFG->version);
215+
$mform->addElement('static', 'versionstring', get_string('siteversion', 'hub'), $CFG->version);
208216
$mform->addElement('hidden', 'moodleversion', $CFG->version);
209217
$mform->addHelpButton('versionstring', 'siteversion', 'hub');
210218

211-
$mform->addElement('static', 'releasestring',get_string('siterelease', 'hub'), $CFG->release);
219+
$mform->addElement('static', 'releasestring', get_string('siterelease', 'hub'), $CFG->release);
212220
$mform->addElement('hidden', 'moodlerelease', $CFG->release);
213221
$mform->addHelpButton('releasestring', 'siterelease', 'hub');
214222

215-
$mform->addElement('textarea','address' , get_string('postaladdress', 'hub'),
216-
array('rows'=>4, 'cols'=>41));
223+
$mform->addElement('textarea', 'address', get_string('postaladdress', 'hub'),
224+
array('rows' => 4, 'cols' => 41));
217225
$mform->setType('address', PARAM_TEXT);
218226
$mform->setDefault('address', $address);
219227
$mform->addHelpButton('address', 'postaladdress', 'hub');
@@ -228,7 +236,7 @@ public function definition() {
228236
$mform->setDefault('countrycode', $country);
229237
$mform->addHelpButton('countrycode', 'sitecountry', 'hub');
230238

231-
$mform->addElement('text','geolocation' , get_string('sitegeolocation', 'hub'),
239+
$mform->addElement('text', 'geolocation', get_string('sitegeolocation', 'hub'),
232240
array('class' => 'registration_textfield'));
233241
$mform->setDefault('geolocation', $geolocation);
234242
$mform->addHelpButton('geolocation', 'sitegeolocation', 'hub');
@@ -240,7 +248,7 @@ public function definition() {
240248
$mform->setDefault('contactname', $contactname);
241249
$mform->addHelpButton('contactname', 'siteadmin', 'hub');
242250

243-
$mform->addElement('text','contactphone' , get_string('sitephone', 'hub'),
251+
$mform->addElement('text', 'contactphone', get_string('sitephone', 'hub'),
244252
array('class' => 'registration_textfield'));
245253
$mform->setType('contactphone', PARAM_TEXT);
246254
$mform->addHelpButton('contactphone', 'sitephone', 'hub');
@@ -270,83 +278,82 @@ public function definition() {
270278

271279
//TODO site logo
272280
$mform->addElement('hidden', 'imageurl', ''); //TODO: temporary
273-
274281
/// Display statistic that are going to be retrieve by the hub
275-
$coursecount = $DB->count_records('course')-1;
276-
$usercount = $DB->count_records('user', array('deleted'=>0));
282+
$coursecount = $DB->count_records('course') - 1;
283+
$usercount = $DB->count_records('user', array('deleted' => 0));
277284
$roleassigncount = $DB->count_records('role_assignments');
278285
$postcount = $DB->count_records('forum_posts');
279286
$questioncount = $DB->count_records('question');
280287
$resourcecount = $DB->count_records('resource');
281-
require_once($CFG->dirroot."/course/lib.php");
282-
$participantnumberaverage= average_number_of_participants();
283-
$modulenumberaverage= average_number_of_courses_modules();
288+
require_once($CFG->dirroot . "/course/lib.php");
289+
$participantnumberaverage = average_number_of_participants();
290+
$modulenumberaverage = average_number_of_courses_modules();
284291

285292
if (HUB_MOODLEORGHUBURL != $huburl) {
286-
$mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
287-
" ".get_string('coursesnumber', 'hub', $coursecount));
293+
$mform->addElement('checkbox', 'courses', get_string('sendfollowinginfo', 'hub'),
294+
" " . get_string('coursesnumber', 'hub', $coursecount));
288295
$mform->setDefault('courses', true);
289296
$mform->addHelpButton('courses', 'sendfollowinginfo', 'hub');
290297

291298
$mform->addElement('checkbox', 'users', '',
292-
" ".get_string('usersnumber', 'hub', $usercount));
299+
" " . get_string('usersnumber', 'hub', $usercount));
293300
$mform->setDefault('users', true);
294301

295302
$mform->addElement('checkbox', 'roleassignments', '',
296-
" ".get_string('roleassignmentsnumber', 'hub', $roleassigncount));
303+
" " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
297304
$mform->setDefault('roleassignments', true);
298305

299306
$mform->addElement('checkbox', 'posts', '',
300-
" ".get_string('postsnumber', 'hub', $postcount));
307+
" " . get_string('postsnumber', 'hub', $postcount));
301308
$mform->setDefault('posts', true);
302309

303310
$mform->addElement('checkbox', 'questions', '',
304-
" ".get_string('questionsnumber', 'hub', $questioncount));
311+
" " . get_string('questionsnumber', 'hub', $questioncount));
305312
$mform->setDefault('questions', true);
306313

307314
$mform->addElement('checkbox', 'resources', '',
308-
" ".get_string('resourcesnumber', 'hub', $resourcecount));
315+
" " . get_string('resourcesnumber', 'hub', $resourcecount));
309316
$mform->setDefault('resources', true);
310317

311318
$mform->addElement('checkbox', 'participantnumberaverage', '',
312-
" ".get_string('participantnumberaverage', 'hub', $participantnumberaverage));
319+
" " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
313320
$mform->setDefault('participantnumberaverage', true);
314321

315322
$mform->addElement('checkbox', 'modulenumberaverage', '',
316-
" ".get_string('modulenumberaverage', 'hub', $modulenumberaverage));
323+
" " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
317324
$mform->setDefault('modulenumberaverage', true);
318325
} else {
319-
$mform->addElement('static', 'courseslabel',get_string('sendfollowinginfo', 'hub'),
320-
" ".get_string('coursesnumber', 'hub', $coursecount));
326+
$mform->addElement('static', 'courseslabel', get_string('sendfollowinginfo', 'hub'),
327+
" " . get_string('coursesnumber', 'hub', $coursecount));
321328
$mform->addElement('hidden', 'courses', true);
322-
$mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
329+
$mform->addHelpButton('courseslabel', 'sendfollowinginfo', 'hub');
323330

324331
$mform->addElement('static', 'userslabel', '',
325-
" ".get_string('usersnumber', 'hub', $usercount));
332+
" " . get_string('usersnumber', 'hub', $usercount));
326333
$mform->addElement('hidden', 'users', true);
327334

328335
$mform->addElement('static', 'roleassignmentslabel', '',
329-
" ".get_string('roleassignmentsnumber', 'hub', $roleassigncount));
336+
" " . get_string('roleassignmentsnumber', 'hub', $roleassigncount));
330337
$mform->addElement('hidden', 'roleassignments', true);
331338

332339
$mform->addElement('static', 'postslabel', '',
333-
" ".get_string('postsnumber', 'hub', $postcount));
340+
" " . get_string('postsnumber', 'hub', $postcount));
334341
$mform->addElement('hidden', 'posts', true);
335342

336343
$mform->addElement('static', 'questionslabel', '',
337-
" ".get_string('questionsnumber', 'hub', $questioncount));
344+
" " . get_string('questionsnumber', 'hub', $questioncount));
338345
$mform->addElement('hidden', 'questions', true);
339346

340347
$mform->addElement('static', 'resourceslabel', '',
341-
" ".get_string('resourcesnumber', 'hub', $resourcecount));
348+
" " . get_string('resourcesnumber', 'hub', $resourcecount));
342349
$mform->addElement('hidden', 'resources', true);
343350

344351
$mform->addElement('static', 'participantnumberaveragelabel', '',
345-
" ".get_string('participantnumberaverage', 'hub', $participantnumberaverage));
352+
" " . get_string('participantnumberaverage', 'hub', $participantnumberaverage));
346353
$mform->addElement('hidden', 'participantnumberaverage', true);
347354

348355
$mform->addElement('static', 'modulenumberaveragelabel', '',
349-
" ".get_string('modulenumberaverage', 'hub', $modulenumberaverage));
356+
" " . get_string('modulenumberaverage', 'hub', $modulenumberaverage));
350357
$mform->addElement('hidden', 'modulenumberaverage', true);
351358
}
352359

@@ -355,16 +362,16 @@ public function definition() {
355362

356363
if (!empty($hubregistered)) {
357364
$buttonlabel = get_string('updatesite', 'hub',
358-
!empty($hubname)?$hubname:$huburl);
365+
!empty($hubname) ? $hubname : $huburl);
359366
$mform->addElement('hidden', 'update', true);
360367
} else {
361368
$buttonlabel = get_string('registersite', 'hub',
362-
!empty($hubname)?$hubname:$huburl);
369+
!empty($hubname) ? $hubname : $huburl);
363370
}
364371

365372
$this->add_action_buttons(false, $buttonlabel);
366373
}
367374

368375
}
369376

370-
?>
377+

lang/en/hub.php

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
$string['errorcourseinfo'] = 'An error occured when retrieving course metadata from the hub ({$a}). Please try again to retrieve the course metadata from the hub by reloading this page later. Otherwise you can decide to continue the registration process with the following default metadata. ';
9696
$string['errorcoursepublish'] = 'An error occured during the course publication ({$a}). Please try again later.';
9797
$string['errorcoursewronglypublished'] = 'A publication error has been returned by the hub. Please try again later.';
98+
$string['errorhublisting'] = 'An error occured when retrieving the hub listing from Moodle.org, please try again later. ({$a})';
9899
$string['errorlangnotrecognized'] = 'Language code is unknown by Moodle. Please contact {$a}';
99100
$string['errorregistration'] = 'An error occured during registration, please try again later. ({$a})';
100101
$string['existingscreenshotnumber'] = '{$a} existing screenshots. You will be able to see these screenshots on this page, only once the hub administrator enables your course.';

0 commit comments

Comments
 (0)