7
7
class UnityOrg
8
8
{
9
9
public $ gid ;
10
+ private $ entry ;
10
11
11
12
private $ MAILER ;
12
13
private $ SQL ;
@@ -17,6 +18,7 @@ class UnityOrg
17
18
public function __construct ($ gid , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK )
18
19
{
19
20
$ this ->gid = $ gid ;
21
+ $ this ->entry = $ LDAP ->getOrgGroupEntry ($ this ->gid );
20
22
21
23
$ this ->LDAP = $ LDAP ;
22
24
$ this ->SQL = $ SQL ;
@@ -27,27 +29,20 @@ public function __construct($gid, $LDAP, $SQL, $MAILER, $REDIS, $WEBHOOK)
27
29
28
30
public function init ()
29
31
{
30
- $ org_group = $ this ->getLDAPOrgGroup ();
31
-
32
- if (!$ org_group ->exists ()) {
32
+ if (!$ this ->entry ->exists ()) {
33
33
$ nextGID = $ this ->LDAP ->getNextOrgGIDNumber ($ this ->SQL );
34
34
35
- $ org_group ->setAttribute ("objectclass " , UnityLDAP::POSIX_GROUP_CLASS );
36
- $ org_group ->setAttribute ("gidnumber " , strval ($ nextGID ));
37
- $ org_group ->write ();
35
+ $ this -> entry ->setAttribute ("objectclass " , UnityLDAP::POSIX_GROUP_CLASS );
36
+ $ this -> entry ->setAttribute ("gidnumber " , strval ($ nextGID ));
37
+ $ this -> entry ->write ();
38
38
}
39
39
40
40
$ this ->REDIS ->appendCacheArray ("sorted_orgs " , "" , $ this ->gid );
41
41
}
42
42
43
43
public function exists ()
44
44
{
45
- return $ this ->getLDAPOrgGroup ()->exists ();
46
- }
47
-
48
- public function getLDAPOrgGroup ()
49
- {
50
- return $ this ->LDAP ->getOrgGroupEntry ($ this ->gid );
45
+ return $ this ->entry ->exists ();
51
46
}
52
47
53
48
public function inOrg ($ user , $ ignorecache = false )
@@ -83,8 +78,7 @@ public function getOrgMemberUIDs($ignorecache = false)
83
78
}
84
79
$ updatecache = false ;
85
80
if (!isset ($ members )) {
86
- $ org_group = $ this ->getLDAPOrgGroup ();
87
- $ members = $ org_group ->getAttribute ("memberuid " );
81
+ $ members = $ this ->entry ->getAttribute ("memberuid " );
88
82
$ updatecache = true ;
89
83
}
90
84
if (!$ ignorecache && $ updatecache ) {
@@ -96,17 +90,15 @@ public function getOrgMemberUIDs($ignorecache = false)
96
90
97
91
public function addUser ($ user )
98
92
{
99
- $ org_group = $ this ->getLDAPOrgGroup ();
100
- $ org_group ->appendAttribute ("memberuid " , $ user ->uid );
101
- $ org_group ->write ();
93
+ $ this ->entry ->appendAttribute ("memberuid " , $ user ->uid );
94
+ $ this ->entry ->write ();
102
95
$ this ->REDIS ->appendCacheArray ($ this ->gid , "members " , $ user ->uid );
103
96
}
104
97
105
98
public function removeUser ($ user )
106
99
{
107
- $ org_group = $ this ->getLDAPOrgGroup ();
108
- $ org_group ->removeAttributeEntryByValue ("memberuid " , $ user ->uid );
109
- $ org_group ->write ();
100
+ $ this ->entry ->removeAttributeEntryByValue ("memberuid " , $ user ->uid );
101
+ $ this ->entry ->write ();
110
102
$ this ->REDIS ->removeCacheArray ($ this ->gid , "members " , $ user ->uid );
111
103
}
112
104
}
0 commit comments