@@ -12,6 +12,7 @@ class UnityGroup
12
12
public const PI_PREFIX = "pi_ " ;
13
13
14
14
public $ gid ;
15
+ private $ entry ;
15
16
16
17
// Services
17
18
private $ LDAP ;
@@ -30,6 +31,7 @@ class UnityGroup
30
31
public function __construct ($ gid , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK )
31
32
{
32
33
$ this ->gid = $ gid ;
34
+ $ this ->entry = $ LDAP ->getPIGroupEntry ($ gid );
33
35
34
36
$ this ->LDAP = $ LDAP ;
35
37
$ this ->SQL = $ SQL ;
@@ -59,7 +61,7 @@ public function __toString()
59
61
*/
60
62
public function exists ()
61
63
{
62
- return $ this ->getLDAPPiGroup () ->exists ();
64
+ return $ this ->entry ->exists ();
63
65
}
64
66
65
67
//
@@ -255,9 +257,8 @@ public function cancelGroupJoinRequest($user, $send_mail = true)
255
257
// $users = $this->getGroupMembers();
256
258
257
259
// // now we delete the ldap entry
258
- // $ldapPiGroupEntry = $this->getLDAPPiGroup();
259
- // if ($ldapPiGroupEntry->exists()) {
260
- // $ldapPiGroupEntry->delete();
260
+ // if ($this->entry->exists()) {
261
+ // $this->entry->delete();
261
262
// $this->REDIS->removeCacheArray("sorted_groups", "", $this->gid);
262
263
// foreach ($users as $user) {
263
264
// $this->REDIS->removeCacheArray($user->uid, "groups", $this->gid);
@@ -486,8 +487,7 @@ public function getGroupMemberUIDs($ignorecache = false)
486
487
}
487
488
$ updatecache = false ;
488
489
if (!isset ($ members )) {
489
- $ pi_group = $ this ->getLDAPPiGroup ();
490
- $ members = $ pi_group ->getAttribute ("memberuid " );
490
+ $ members = $ this ->entry ->getAttribute ("memberuid " );
491
491
$ updatecache = true ;
492
492
}
493
493
if (!$ ignorecache && $ updatecache ) {
@@ -520,16 +520,13 @@ private function init()
520
520
// make this user a PI
521
521
$ owner = $ this ->getOwner ();
522
522
523
- // (1) Create LDAP PI group
524
- $ ldapPiGroupEntry = $ this ->getLDAPPiGroup ();
525
-
526
- if (!$ ldapPiGroupEntry ->exists ()) {
523
+ if (!$ this ->entry ->exists ()) {
527
524
$ nextGID = $ this ->LDAP ->getNextPiGIDNumber ($ this ->SQL );
528
525
529
- $ ldapPiGroupEntry ->setAttribute ("objectclass " , UnityLDAP::POSIX_GROUP_CLASS );
530
- $ ldapPiGroupEntry ->setAttribute ("gidnumber " , strval ($ nextGID ));
531
- $ ldapPiGroupEntry ->setAttribute ("memberuid " , array ($ owner ->uid ));
532
- $ ldapPiGroupEntry ->write ();
526
+ $ this -> entry ->setAttribute ("objectclass " , UnityLDAP::POSIX_GROUP_CLASS );
527
+ $ this -> entry ->setAttribute ("gidnumber " , strval ($ nextGID ));
528
+ $ this -> entry ->setAttribute ("memberuid " , array ($ owner ->uid ));
529
+ $ this -> entry ->write ();
533
530
}
534
531
535
532
$ this ->REDIS ->appendCacheArray ("sorted_groups " , "" , $ this ->gid );
@@ -540,19 +537,17 @@ private function init()
540
537
private function addUserToGroup ($ new_user )
541
538
{
542
539
// Add to LDAP Group
543
- $ pi_group = $ this ->getLDAPPiGroup ();
544
- $ pi_group ->appendAttribute ("memberuid " , $ new_user ->uid );
545
- $ pi_group ->write ();
540
+ $ this ->entry ->appendAttribute ("memberuid " , $ new_user ->uid );
541
+ $ this ->entry ->write ();
546
542
$ this ->REDIS ->appendCacheArray ($ this ->gid , "members " , $ new_user ->uid );
547
543
$ this ->REDIS ->appendCacheArray ($ new_user ->uid , "groups " , $ this ->gid );
548
544
}
549
545
550
546
private function removeUserFromGroup ($ old_user )
551
547
{
552
548
// Remove from LDAP Group
553
- $ pi_group = $ this ->getLDAPPiGroup ();
554
- $ pi_group ->removeAttributeEntryByValue ("memberuid " , $ old_user ->uid );
555
- $ pi_group ->write ();
549
+ $ this ->entry ->removeAttributeEntryByValue ("memberuid " , $ old_user ->uid );
550
+ $ this ->entry ->write ();
556
551
$ this ->REDIS ->removeCacheArray ($ this ->gid , "members " , $ old_user ->uid );
557
552
$ this ->REDIS ->removeCacheArray ($ old_user ->uid , "groups " , $ this ->gid );
558
553
}
@@ -583,11 +578,6 @@ public function getOwner()
583
578
);
584
579
}
585
580
586
- public function getLDAPPiGroup ()
587
- {
588
- return $ this ->LDAP ->getPIGroupEntry ($ this ->gid );
589
- }
590
-
591
581
public static function ownerUID2GID ($ uid )
592
582
{
593
583
return self ::PI_PREFIX . $ uid ;
0 commit comments