Skip to content

Commit 7195769

Browse files
committed
Rolled back changes for unrolling students
1 parent 6aba0d0 commit 7195769

1 file changed

Lines changed: 0 additions & 144 deletions

File tree

src/GroupLMSUserSyncAPI.php

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ public function syncUsersToGroups(): int {
283283
* for each member, query the API if the student exists in any of these
284284
* groups identified by the OU (to implement the endpoint)
285285
* if not, remove it */
286-
$this->removeUnenrolledStudentsFromGroups();
287286

288287
} else {
289288
// Endpoint URL was not set or is empty
@@ -475,149 +474,6 @@ public function getAPIEndpoint(): string {
475474
return ($this->endpoint_url . '/' . $this->api_version);
476475
}
477476

478-
/**
479-
* Removes unenrolled students (not listed in the API Groups) from the Drupal Groups
480-
*
481-
* @return int
482-
* TRUE on success or FALSE on error
483-
*/
484-
private function removeUnenrolledStudentsFromGroups(): bool {
485-
// Create an httpClient Object that will be used for all the requests.
486-
$client = \Drupal::httpClient();
487-
488-
$endpoint_data = json_decode($this->endpoint_data);
489-
$this->endpoint_url = $endpoint_data->url;
490-
$auth = 'Basic '. base64_encode($endpoint_data->username . ':' . $endpoint_data->password);
491-
492-
/* Loop through the Drupal Groups, for each group, get the members
493-
* Get the Group OUs for each group.
494-
* for each member, query the API if the student exists in any of these
495-
* groups identified by the OU (the Drupal Group can have more than more
496-
* OUs stored in the field_course_ou field) if not, remove it */
497-
$group_api_ids = [];
498-
499-
$gids = \Drupal::entityQuery('group')
500-
->exists('field_course_ou')
501-
->accessCheck(FALSE)
502-
->execute();
503-
504-
if (count($gids) > 0) {
505-
foreach ($gids as $gid) {
506-
$group = Group::load($gid);
507-
508-
$api_ou = $group->field_course_ou->getValue();
509-
510-
// Get the Group OUs of the group
511-
foreach ($api_ou as $ou) {
512-
$group_api_ids[] = $ou["value"];
513-
}
514-
515-
// Get the group members
516-
$group_members = $group->getMembers();
517-
518-
foreach ($group_members as $membership) {
519-
$group_user = $membership->getUser();
520-
521-
foreach ($group_api_ids as $group_id) {
522-
try {
523-
$request = $client->get($this->endpoint_url . '/' . $this->api_version . '/' . $group_id . '/' . $group_user->getAccountName(), [
524-
'http_errors' => TRUE,
525-
'query' => [
526-
'_format' => 'json'
527-
],
528-
'headers' => [
529-
'Authorization' => $auth,
530-
'Content-Type' => 'application/json',
531-
'Accept' => 'application/json',
532-
],
533-
]);
534-
535-
if (!empty($request)) {
536-
if ($request->getBody()) {
537-
$student_info = json_decode($request->getBody());
538-
$group_name = $group->label();
539-
$username = $group_user->getAccountName();
540-
541-
if (!is_array($student_info) || (count($student_info) < 1)) {
542-
file_put_contents("/tmp/un-studentinfo".$group_user->id()."-".$group_id."-".$username, json_encode($student_info));
543-
/* $group->removeMember($group_user);
544-
545-
// Logs Group Activity
546-
$group_log_event = GroupLog::create(array(
547-
'name' => $group_name . "-" . $group_name . "-" . $username,
548-
'group_name' => $group_name,
549-
'group_ou' => $group_id,
550-
'username' => $username,
551-
'enroll_status' => 0,
552-
));
553-
$group_log_event->save();
554-
555-
$this->messenger->addStatus(t("Removed user @username from group @groupname", ['@username' => $username, '@groupname' => $group_id]));
556-
$this->logger->notice("Removed user @username from group @groupname", ['@username' => $username, '@groupname' => $group_id]); */
557-
} else {
558-
file_put_contents("/tmp/studentinfo".$group_user->id()."-".$group_id."-".$username, json_encode($student_info));
559-
}
560-
}
561-
}
562-
563-
564-
} catch (\Exception $e) {
565-
watchdog_exception('group_lms_user_sync', $e);
566-
return FALSE;
567-
}
568-
}
569-
}
570-
}
571-
}
572-
573-
/*if (is_array($classroom)) {
574-
$group_members = $group->getMembers();
575-
576-
foreach ($group_members as $membership) {
577-
$group_user = $membership->getUser();
578-
$user_in_group = FALSE;
579-
580-
foreach ($classroom as $student) {
581-
$user_email_api = $student->Email;
582-
583-
// NOTE
584-
585-
if ($group_user->getEmail() == $user_email_api) {
586-
$user_in_group = TRUE;
587-
break;
588-
}
589-
}
590-
591-
if (!$user_in_group) {
592-
$group->removeMember($group_user);
593-
$group_name = $group->label();
594-
$username = $group_user->getAccountName();
595-
596-
// Logs Group Activity
597-
$group_log_event = GroupLog::create(array(
598-
'name' => $group_name . "-" . $group_name . "-" . $username,
599-
'group_name' => $group_name,
600-
'group_ou' => $group_name,
601-
'username' => $username,
602-
'enroll_status' => 0,
603-
));
604-
$group_log_event->save();
605-
606-
$this->messenger->addStatus(t("Removed user @username from group @groupname", ['@username' => $username, '@groupname' => $group_id_api]));
607-
$this->logger->notice("Removed user @username from group @groupname", ['@username' => $username, '@groupname' => $group_id_api]);
608-
609-
return TRUE;
610-
}
611-
}
612-
613-
return TRUE;
614-
} else {
615-
return FALSE;
616-
} */
617-
618-
return TRUE;
619-
}
620-
621477
/**
622478
* Create a new user with the paramaters given from the API.
623479
*

0 commit comments

Comments
 (0)