7
7
class UnityOrg
8
8
{
9
9
private $ orgid ;
10
+ private $ entry ;
10
11
11
12
private $ MAILER ;
12
13
private $ SQL ;
@@ -17,6 +18,7 @@ class UnityOrg
17
18
public function __construct ($ orgid , $ LDAP , $ SQL , $ MAILER , $ REDIS , $ WEBHOOK )
18
19
{
19
20
$ this ->orgid = $ orgid ;
21
+ $ this ->entry = $ LDAP ->getOrgGroupEntry ($ this ->orgid );
20
22
21
23
$ this ->LDAP = $ LDAP ;
22
24
$ this ->SQL = $ SQL ;
@@ -27,27 +29,20 @@ public function __construct($orgid, $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 ->getOrgID ());
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 ->orgid );
45
+ return $ this ->entry ->exists ();
51
46
}
52
47
53
48
public function getOrgID ()
@@ -89,8 +84,7 @@ public function getOrgMemberUIDs($ignorecache = false)
89
84
}
90
85
$ updatecache = false ;
91
86
if (!isset ($ members )) {
92
- $ org_group = $ this ->getLDAPOrgGroup ();
93
- $ members = $ org_group ->getAttribute ("memberuid " );
87
+ $ members = $ this ->entry ->getAttribute ("memberuid " );
94
88
$ updatecache = true ;
95
89
}
96
90
if (!$ ignorecache && $ updatecache ) {
@@ -102,17 +96,15 @@ public function getOrgMemberUIDs($ignorecache = false)
102
96
103
97
public function addUser ($ user )
104
98
{
105
- $ org_group = $ this ->getLDAPOrgGroup ();
106
- $ org_group ->appendAttribute ("memberuid " , $ user ->getUID ());
107
- $ org_group ->write ();
108
- $ this ->REDIS ->appendCacheArray ($ this ->getOrgID (), "members " , $ user ->getUID ());
99
+ $ this ->entry ->appendAttribute ("memberuid " , $ user ->getUID ());
100
+ $ this ->entry ->write ();
101
+ $ this ->REDIS ->appendCacheArray ($ this ->getOrgID (), "members " , $ user ->uid );
109
102
}
110
103
111
104
public function removeUser ($ user )
112
105
{
113
- $ org_group = $ this ->getLDAPOrgGroup ();
114
- $ org_group ->removeAttributeEntryByValue ("memberuid " , $ user ->getUID ());
115
- $ org_group ->write ();
106
+ $ this ->entry ->removeAttributeEntryByValue ("memberuid " , $ user ->getUID ());
107
+ $ this ->entry ->write ();
116
108
$ this ->REDIS ->removeCacheArray ($ this ->getOrgID (), "members " , $ user ->getUID ());
117
109
}
118
110
}
0 commit comments