MDL-26061 Prevent fatal error in remote enrolment client when there are no roaming...
authorDavid Mudrak <david@moodle.com>
Wed, 19 Jan 2011 18:14:00 +0000 (19:14 +0100)
committerDavid Mudrak <david@moodle.com>
Wed, 19 Jan 2011 18:39:19 +0000 (19:39 +0100)
mnet/service/enrol/index.php
mnet/service/enrol/lang/en/mnetservice_enrol.php
mnet/service/enrol/locallib.php

index 53e18c4..221a28f 100644 (file)
@@ -40,6 +40,14 @@ if (!$service->is_available()) {
     die();
 }
 
+$roamingusers = get_users_by_capability(get_system_context(), 'moodle/site:mnetlogintoremote', 'u.id');
+if (empty($roamingusers)) {
+    $capname = get_string('site:mnetlogintoremote', 'role');
+    $url = new moodle_url('/admin/roles/manage.php');
+    echo notice(get_string('noroamingusers', 'mnetservice_enrol', $capname), $url);
+}
+unset($roamingusers);
+
 // remote hosts that may publish remote enrolment service and we are subscribed to it
 $hosts = $service->get_remote_publishers();
 
index 461f777..2a0f479 100644 (file)
@@ -33,6 +33,7 @@ $string['hostappname'] = 'Application';
 $string['hostname'] = 'Host name';
 $string['hosturl'] = 'Remote host URL';
 $string['nopublishers'] = 'No remote peers available.';
+$string['noroamingusers'] = 'Users need capability \'{$a}\' to be enrolled to remote courses. No users with such capability were found. Click the continue button to assign the required capability to some roles at your site.';
 $string['otherenrolledusers'] = 'Other enrolled users';
 $string['pluginname'] = 'Remote enrolment service';
 $string['refetch'] = 'Re-fetch up to date state from remote hosts';
index b0c260a..ffe7e6d 100644 (file)
@@ -552,6 +552,10 @@ class mnetservice_enrol_potential_users_selector extends user_selector_base {
         $systemcontext = get_system_context();
         $userids = get_users_by_capability($systemcontext, 'moodle/site:mnetlogintoremote', 'u.id');
 
+        if (empty($userids)) {
+            return array();
+        }
+
         list($usql, $uparams) = $DB->get_in_or_equal(array_keys($userids), SQL_PARAMS_NAMED, 'uid0000');
 
         list($wherecondition, $params) = $this->search_sql($search, 'u');