fix indentation

use identity test where appropriate
use camelcase variable names
_getGroupsByMember is a private function
This commit is contained in:
root 2013-12-11 10:43:48 +01:00
parent a18cff4479
commit 2b127a6ac5
1 changed files with 41 additions and 41 deletions

View File

@ -88,37 +88,37 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface {
return $isInGroup;
}
private function _groupMembers($dn_group, &$groups_seen = null) {
if ($groups_seen == null) {
$groups_seen = array();
private function _groupMembers($dnGroup, &$seen = null) {
if ($seen === null) {
$seen = array();
}
$all_members = array();
if (array_key_exists($dn_group, $groups_seen)) {
$allMembers = array();
if (array_key_exists($dnGroup, $seen)) {
// avoid loops
return array();
}
// used extensively in cron job, caching makes sense for nested groups
$cache_key = '_groupMembers'.$dn_group;
if($this->access->connection->isCached($cache_key)) {
return $this->access->connection->getFromCache($cache_key);
$cacheKey = '_groupMembers'.$dnGroup;
if($this->access->connection->isCached($cacheKey)) {
return $this->access->connection->getFromCache($cacheKey);
}
$groups_seen[$dn_group] = 1;
$members = $this->access->readAttribute($dn_group, $this->access->connection->ldapGroupMemberAssocAttr,
$this->access->connection->ldapGroupFilter);
$seen[$dnGroup] = 1;
$members = $this->access->readAttribute($dnGroup, $this->access->connection->ldapGroupMemberAssocAttr,
$this->access->connection->ldapGroupFilter);
if ($members) {
foreach ($members as $member_dn) {
$all_members[$member_dn] = 1;
if ($this->access->connection->ldapNestedGroups) {
$submembers = $this->_groupMembers($member_dn, $groups_seen);
if ($submembers) {
$all_members = array_merge($all_members, $submembers);
}
}
}
foreach ($members as $memberDN) {
$allMembers[$memberDN] = 1;
if ($this->access->connection->ldapNestedGroups) {
$subMembers = $this->_groupMembers($memberDN, $seen);
if ($subMembers) {
$allMembers = array_merge($allMembers, $subMembers);
}
}
}
}
$this->access->connection->writeToCache($cache_key, $all_members);
return $all_members;
}
$this->access->connection->writeToCache($cacheKey, $allMembers);
return $allMembers;
}
/**
* @brief Get all groups a user belongs to
@ -162,11 +162,11 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface {
return $groups;
}
/* private */ public function _getGroupsByMember($dn, &$seen = null) {
if ($seen == null) {
$seen = array();
private function _getGroupsByMember($dn, &$seen = null) {
if ($seen === null) {
$seen = array();
}
$all_groups = array();
$allGroups = array();
if (array_key_exists($dn, $seen)) {
// avoid loops
return array();
@ -177,20 +177,20 @@ class GROUP_LDAP extends BackendUtility implements \OCP\GroupInterface {
$this->access->connection->ldapGroupMemberAssocAttr.'='.$dn
));
$groups = $this->access->fetchListOfGroups($filter,
array($this->access->connection->ldapGroupDisplayName, 'dn'));
if ($groups) {
foreach ($groups as $groupobj) {
$group_dn = $groupobj['dn'];
$all_groups[$group_dn] = $groupobj;
if ($this->access->connection->ldapNestedGroups) {
$supergroups = $this->_getGroupsByMember($group_dn, $seen);
if ($supergroups) {
$all_groups = array_merge($all_groups, $supergroups);
}
}
}
}
return $all_groups;
array($this->access->connection->ldapGroupDisplayName, 'dn'));
if ($groups) {
foreach ($groups as $groupobj) {
$groupDN = $groupobj['dn'];
$allGroups[$groupDN] = $groupobj;
if ($this->access->connection->ldapNestedGroups) {
$supergroups = $this->_getGroupsByMember($groupDN, $seen);
if ($supergroups) {
$allGroups = array_merge($allGroups, $supergroups);
}
}
}
}
return $allGroups;
}
/**