replaced caching
This commit is contained in:
parent
0145dafc53
commit
2efbc6d370
|
@ -35,6 +35,11 @@ $Id$
|
||||||
*/
|
*/
|
||||||
class nisnetgroup extends baseModule {
|
class nisnetgroup extends baseModule {
|
||||||
|
|
||||||
|
/* caches to reduce LDAP queries */
|
||||||
|
private $cachedUserList = null;
|
||||||
|
private $cachedHostList = null;
|
||||||
|
private $cachedGroupList = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns meta data that is interpreted by parent class
|
* Returns meta data that is interpreted by parent class
|
||||||
*
|
*
|
||||||
|
@ -353,12 +358,7 @@ class nisnetgroup extends baseModule {
|
||||||
*/
|
*/
|
||||||
function display_html_group() {
|
function display_html_group() {
|
||||||
// load list with all groups
|
// load list with all groups
|
||||||
$dn_groups = $_SESSION['cache']->get_cache('cn', 'nisNetgroup', 'netgroup');
|
$allGroups = $this->getGroupList();
|
||||||
$DNs = array_keys($dn_groups);
|
|
||||||
$allGroups = array();
|
|
||||||
foreach ($DNs as $DN) {
|
|
||||||
$allGroups[] = $dn_groups[$DN][0];
|
|
||||||
}
|
|
||||||
// remove own entry
|
// remove own entry
|
||||||
if (!$this->getAccountContainer()->isNewAccount) {
|
if (!$this->getAccountContainer()->isNewAccount) {
|
||||||
$allGroups = array_delete($this->attributes['cn'][0], $allGroups);
|
$allGroups = array_delete($this->attributes['cn'][0], $allGroups);
|
||||||
|
@ -443,25 +443,25 @@ class nisnetgroup extends baseModule {
|
||||||
$options = array();
|
$options = array();
|
||||||
if ($selectHost) {
|
if ($selectHost) {
|
||||||
// load list with all hosts
|
// load list with all hosts
|
||||||
$dn_hosts = $_SESSION['cache']->get_cache('uid', 'account', 'host');
|
$options = $this->getHostList();
|
||||||
$DNs = array_keys($dn_hosts);
|
$count = sizeof($options);
|
||||||
foreach ($DNs as $DN) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
if (get_preg($dn_hosts[$DN][0], 'DNSname')) {
|
if (!get_preg($options[$i], 'DNSname') || (($filter != '') && (strpos($options[$i], $filter) === false))) {
|
||||||
if (($filter == '') || !(strpos($dn_hosts[$DN][0], $filter) === false)) {
|
unset($options[$i]);
|
||||||
$options[] = $dn_hosts[$DN][0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$options = array_values($options);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// load list with all users
|
// load list with all users
|
||||||
$dn_users = $_SESSION['cache']->get_cache('uid', 'posixAccount', 'user');
|
$options = $this->getUserList();
|
||||||
$DNs = array_keys($dn_users);
|
$count = sizeof($options);
|
||||||
foreach ($DNs as $DN) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
if (($filter == '') || !(strpos($dn_users[$DN][0], $filter) === false)) {
|
if (($filter != '') && (strpos($options[$i], $filter) === false)) {
|
||||||
$options[] = $dn_users[$DN][0];
|
unset($options[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
$options = array_values($options);
|
||||||
}
|
}
|
||||||
$return->addElement(new htmlOutputText(_('Filter')));
|
$return->addElement(new htmlOutputText(_('Filter')));
|
||||||
$return->addElement(new htmlInputField('filter', $filter));
|
$return->addElement(new htmlInputField('filter', $filter));
|
||||||
|
@ -515,11 +515,7 @@ class nisnetgroup extends baseModule {
|
||||||
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
|
function build_uploadAccounts($rawAccounts, $ids, &$partialAccounts, $selectedModules) {
|
||||||
$messages = array();
|
$messages = array();
|
||||||
// get list of existing groups
|
// get list of existing groups
|
||||||
$dnGroups = $_SESSION['cache']->get_cache('cn', 'nisNetgroup', 'netgroup');
|
$existingGroups = $this->getGroupList();
|
||||||
$existingGroups = array();
|
|
||||||
foreach ($dnGroups as $dn) {
|
|
||||||
$existingGroups[] = $dn[0];
|
|
||||||
}
|
|
||||||
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
for ($i = 0; $i < sizeof($rawAccounts); $i++) {
|
||||||
// add object class
|
// add object class
|
||||||
if (!in_array('nisNetgroup', $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = 'nisNetgroup';
|
if (!in_array('nisNetgroup', $partialAccounts[$i]['objectClass'])) $partialAccounts[$i]['objectClass'][] = 'nisNetgroup';
|
||||||
|
@ -600,6 +596,54 @@ class nisnetgroup extends baseModule {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of existing NIS net groups.
|
||||||
|
*
|
||||||
|
* @return array group names
|
||||||
|
*/
|
||||||
|
private function getGroupList() {
|
||||||
|
if ($this->cachedGroupList != null) {
|
||||||
|
return $this->cachedGroupList;
|
||||||
|
}
|
||||||
|
$this->cachedGroupList = searchLDAPByAttribute('cn', '*', 'nisNetgroup', array('cn'), array('netgroup'));
|
||||||
|
for ($i = 0; $i < sizeof($this->cachedGroupList); $i++) {
|
||||||
|
$this->cachedGroupList[$i] = $this->cachedGroupList[$i]['cn'][0];
|
||||||
|
}
|
||||||
|
return $this->cachedGroupList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of existing users.
|
||||||
|
*
|
||||||
|
* @return array user names
|
||||||
|
*/
|
||||||
|
private function getUserList() {
|
||||||
|
if ($this->cachedUserList != null) {
|
||||||
|
return $this->cachedUserList;
|
||||||
|
}
|
||||||
|
$this->cachedUserList = searchLDAPByAttribute('uid', '*', 'posixAccount', array('uid'), array('user'));
|
||||||
|
for ($i = 0; $i < sizeof($this->cachedUserList); $i++) {
|
||||||
|
$this->cachedUserList[$i] = $this->cachedUserList[$i]['uid'][0];
|
||||||
|
}
|
||||||
|
return $this->cachedUserList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list of existing hosts.
|
||||||
|
*
|
||||||
|
* @return array host names
|
||||||
|
*/
|
||||||
|
private function getHostList() {
|
||||||
|
if ($this->cachedHostList != null) {
|
||||||
|
return $this->cachedHostList;
|
||||||
|
}
|
||||||
|
$this->cachedHostList = searchLDAPByAttribute('uid', '*', 'account', array('uid'), array('host'));
|
||||||
|
for ($i = 0; $i < sizeof($this->cachedHostList); $i++) {
|
||||||
|
$this->cachedHostList[$i] = $this->cachedHostList[$i]['uid'][0];
|
||||||
|
}
|
||||||
|
return $this->cachedHostList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue