@@ -301,7 +301,7 @@ protected function refreshAssignmentStatus(object $course_member, int $obj_id, ?
301301
302302 $ this ->log ->debug ('Local user assignment: ' . $ usr_id . ' <-> ' . $ login );
303303
304- if ($ il_usr_id = ilObjUser:: _lookupId ($ login )) {
304+ if ($ il_usr_id = self :: lookupUserIdByLogin ($ login )) {
305305 // this removes also admin, tutor roles
306306 $ part ->delete ($ il_usr_id );
307307 $ this ->log ->info ('Deassigning user ' . $ usr_id . ' ' . 'from course ' . ilObject::_lookupTitle ($ obj_id ));
@@ -329,7 +329,7 @@ protected function refreshAssignmentStatus(object $course_member, int $obj_id, ?
329329 $ this ->log ->info ('Handling user ' . $ person_id );
330330
331331 if (in_array ($ person_id , $ usr_ids , true )) {
332- if ($ il_usr_id = ilObjUser:: _lookupId ($ login )) {
332+ if ($ il_usr_id = self :: lookupUserIdByLogin ($ login )) {
333333 $ this ->log ->info ('Update user assignment for: ' . $ person_id );
334334 $ part ->updateRoleAssignments ($ il_usr_id , array ($ part ->getAutoGeneratedRoleId ($ role )));
335335 } elseif ($ role_info ['create ' ]) {
@@ -339,13 +339,13 @@ protected function refreshAssignmentStatus(object $course_member, int $obj_id, ?
339339 $ this ->mapping ->getAuthMode (),
340340 (string ) $ person_id
341341 );
342- if ($ role && $ il_usr_id = ilObjUser:: _lookupId ($ login )) {
342+ if ($ role && $ il_usr_id = self :: lookupUserIdByLogin ($ login )) {
343343 $ part ->add ($ il_usr_id , $ role );
344344 $ part ->sendNotification (ilCourseMembershipMailNotification::TYPE_ADMISSION_MEMBER , $ il_usr_id );
345345 }
346346 }
347347 } else {
348- if ($ il_usr_id = ilObjUser:: _lookupId ($ login )) {
348+ if ($ il_usr_id = self :: lookupUserIdByLogin ($ login )) {
349349 // user exists => assign to course/group
350350 if ($ role ) {
351351 // Assign user
@@ -364,7 +364,7 @@ protected function refreshAssignmentStatus(object $course_member, int $obj_id, ?
364364 );
365365 }
366366 // Assign to role
367- if ($ role && $ il_usr_id = ilObjUser:: _lookupId ($ login )) {
367+ if ($ role && $ il_usr_id = self :: lookupUserIdByLogin ($ login )) {
368368 $ this ->log ->info ('Assigning new role to existing user ' . $ person_id . ' ' . 'to ' . ilObject::_lookupTitle ($ obj_id ) . ' using role: ' . $ role );
369369 $ part ->add ($ il_usr_id , $ role );
370370 $ part ->sendNotification (ilCourseMembershipMailNotification::TYPE_ADMISSION_MEMBER , $ il_usr_id );
@@ -485,4 +485,20 @@ private function readCourse($course_member)
485485 }
486486 return (new ilECSCourseConnector ($ this ->getServer ()))->getCourse ($ ecs_id );
487487 }
488+
489+ /**
490+ * Wrapper method to Lookup an user id by a login string.
491+ *
492+ * Returns null if $login is null, empty or no user can be found with the given name.
493+ *
494+ * @param string|null $login
495+ * @return int|null
496+ */
497+ private function lookupUserIdByLogin (?string $ login ): ?int
498+ {
499+ if ($ login === null || $ login === '' ) {
500+ return null ;
501+ }
502+ return ilObjUser::_lookupId ($ login );
503+ }
488504}
0 commit comments