Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-10331

Enable enrol/ldap to page large courses

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 1.8.1
    • Fix Version/s: None
    • Component/s: Enrolments
    • Labels:
      None
    • Affected Branches:
      MOODLE_18_STABLE

      Description

      If a course has enrollments that exceed the maximum returned number of attributes of the LDAP server, that course's enrollments will be truncated. This can be addressed by paging the returned group membership.

      Example code (modifying enrol/ldap/enrol.php v1.20) for ActiveDirectory is below:

      Remove the membership query from the initial search, deferring it until later, by deleting:
      167 if($enrol){
      168 array_push($ldap_fields_wanted, $CFG->

      {'enrol_ldap_memberattribute_role'.$role->id});
      169 }

      Add paging code at line 238 (for example):
      // LOCAL: Enable large member results in AD
      $rangeStart = 0;
      $rangeLength = 500;
      $member = $CFG->{'enrol_ldap_memberattribute_role'.$role->id}

      ;
      $tempMembers = array('count' => 0);
      while ($rangeStart > -1) {
      if (1 == 1) { // MS-AD
      $member = $CFG->

      {'enrol_ldap_memberattribute_role'.$role->id}.';Range='.$rangeStart.'-'.($rangeStart+$rangeLength-1);
      }
      $ldap_fields_wanted = array('dn', $member);
      if ($CFG->enrol_ldap_search_sub){ //use ldap_search to find first group from subtree $ldap_result = @ldap_search($ldap_connection, $context, $ldap_search_pattern, $ldap_fields_wanted); } else { //search only in this context $ldap_result = @ldap_list($ldap_connection, $context, $ldap_search_pattern, $ldap_fields_wanted,0,0); }

      // check and push results
      $records = $ldap_result ? ldap_get_entries($ldap_connection,$ldap_result) : array('count' => 0);
      $record = $records[0];

      if (array_key_exists(strtolower($CFG->{'enrol_ldap_memberattribute_role'.$role->id}

      .';Range='.$rangeStart.'-*'), $record)) {
      $record[strtolower($CFG->

      {'enrol_ldap_memberattribute_role'.$role->id}.';Range='.$rangeStart.'-*')][count] += $tempMembers['count'];
      unset($tempMembers['count']);
      $tempMembers = array_merge($tempMembers, $record[strtolower($CFG->{'enrol_ldap_memberattribute_role'.$role->id}

      .';Range='.$rangeStart.'-*')]);
      $rangeStart = -1;
      } else if (array_key_exists(strtolower($CFG->

      {'enrol_ldap_memberattribute_role'.$role->id}.';Range='.$rangeStart.'-'.($rangeStart+$rangeLength-1)), $record)) {
      $record[strtolower($CFG->{'enrol_ldap_memberattribute_role'.$role->id}

      .'Range='.$rangeStart.'-'.($rangeStart+$rangeLength-1))][count] += $tempMembers['count'];
      unset($tempMembers['count']);
      $tempMembers = array_merge($tempMembers, $record[strtolower($CFG->

      {'enrol_ldap_memberattribute_role'.$role->id}.';Range='.$rangeStart.'-'.($rangeStart+$rangeLength-1))]);
      $rangeStart = $rangeStart + $rangeLength;
      } else {
      $tempMembers = $record[strtolower($CFG->{'enrol_ldap_memberattribute_role'.$role->id}

      )];
      $rangeStart = -1;
      }
      }
      $course[strtolower($CFG->

      {'enrol_ldap_memberattribute_role'.$role->id}

      )] = $tempMembers;
      // END LOCAL

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              bluenovember Clinton Graham
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              2 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: