"fixed not working limited result and sorting for type 'both', caused by an (now disabled) optimisation, which only works for type 'accounts'"

This commit is contained in:
Ralf Becker 2010-04-20 11:07:02 +00:00
parent 9284452553
commit 6aebe8485b

View File

@ -693,69 +693,60 @@ class accounts_ldap
$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter); $filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter);
$filter .= ')'; $filter .= ')';
// folw: if ($param['type'] != 'both')
// - first query only few attributes for sorting and throwing away not needed results
// - throw away & sort
// - fetch relevant accounts with full information
// - map and resolve
$propertyMap = array(
'account_id' => 'uidnumber',
'account_lid' => 'uid',
'account_firstname' => 'givenname',
'account_lastname' => 'sn',
'account_email' => 'email'
);
$order = $propertyMap[$param['order']] ? $propertyMap[$param['order']] : 'uid';
$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order));
$fullSet = array();
foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry)
{ {
if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0]; // folw:
} // - first query only few attributes for sorting and throwing away not needed results
// - throw away & sort
if (is_numeric($param['type'])) // return only group-members // - fetch relevant accounts with full information
{ // - map and resolve
$relevantAccounts = array(); $propertyMap = array(
$sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid')); 'account_id' => 'uidnumber',
$group = ldap_get_entries($this->ds, $sri); 'account_lid' => 'uid',
'account_firstname' => 'givenname',
if (isset($group[0]['memberuid'])) 'account_lastname' => 'sn',
'account_email' => 'email',
'account_fullname' => 'cn',
);
$orders = explode(',',$param['order']);
$order = isset($propertyMap[$orders[0]]) ? $propertyMap[$orders[0]] : 'uid';
$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid', $order));
$fullSet = array();
foreach ((array)ldap_get_entries($this->ds, $sri) as $key => $entry)
{ {
$fullSet = array_intersect_key($fullSet, array_flip($group[0]['memberuid'])); if ($key !== 'count') $fullSet[$entry['uid'][0]] = $entry[$order][0];
} }
}
$totalcount = count($fullSet);
$sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort'; if (is_numeric($param['type'])) // return only group-members
$sortFn($fullSet); {
$relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet); $relevantAccounts = array();
// if we do not have a start, or want the members of a certain group, we want all, that way we dont want to or the uids $sri = ldap_search($this->ds,$this->group_context,"(&(objectClass=posixGroup)(gidnumber=" . abs($param['type']) . "))",array('memberuid'));
// since if we have a whole lot of members, it slows the query down $group = ldap_get_entries($this->ds, $sri);
// if you work with very big groups, it may present a problem
if (is_numeric($start) || is_numeric($param['type']))
{
$filter = "(" . "&(objectclass=posixaccount)" . '(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter . ")";
}
else
{
$filter = "(" . "&(objectclass=posixaccount)" . $this->account_filter . ")";
}
$filter = "(" . "&(objectclass=posixaccount)" . '(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter . ")"; if (isset($group[0]['memberuid']))
$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter); {
$fullSet = array_intersect_key($fullSet, array_flip($group[0]['memberuid']));
}
}
$totalcount = count($fullSet);
$sortFn = $param['sort'] == 'DESC' ? 'arsort' : 'asort';
$sortFn($fullSet);
$relevantAccounts = is_numeric($start) ? array_slice(array_keys($fullSet), $start, $offset) : array_keys($fullSet);
$filter = '(&(objectclass=posixaccount)(|(uid='.implode(')(uid=',$relevantAccounts).'))' . $this->account_filter.')';
$filter = str_replace(array('%user','%domain'),array('*',$GLOBALS['egw_info']['user']['domain']),$filter);
}
$sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn','mail','shadowExpire','createtimestamp','modifytimestamp')); $sri = ldap_search($this->ds, $this->user_context, $filter,array('uid','uidNumber','givenname','sn','mail','shadowExpire','createtimestamp','modifytimestamp'));
//echo "<p>ldap_search(,$this->user_context,'$filter',) ".($sri ? '' : ldap_error($this->ds)).microtime()."</p>\n"; //echo "<p>ldap_search(,$this->user_context,'$filter',) ".($sri ? '' : ldap_error($this->ds)).microtime()."</p>\n";
$allValues = ldap_get_entries($this->ds, $sri);
$utc_diff = date('Z'); $utc_diff = date('Z');
while (list($null,$allVals) = @each($allValues)) foreach(ldap_get_entries($this->ds, $sri) as $allVals)
{ {
settype($allVals,'array'); settype($allVals,'array');
$test = @$allVals['uid'][0]; $test = @$allVals['uid'][0];
if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0]) if (!$this->frontend->config['global_denied_users'][$test] && $allVals['uid'][0])
{ {
$accounts[$allVals['uidnumber'][0]] = Array( $account = Array(
'account_id' => $allVals['uidnumber'][0], 'account_id' => $allVals['uidnumber'][0],
'account_lid' => translation::convert($allVals['uid'][0],'utf-8'), 'account_lid' => translation::convert($allVals['uid'][0],'utf-8'),
'account_type' => 'u', 'account_type' => 'u',
@ -765,8 +756,9 @@ class accounts_ldap
'account_email' => $allVals['mail'][0], 'account_email' => $allVals['mail'][0],
'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null, 'account_created' => isset($allVals['createtimestamp'][0]) ? self::accounts_ldap2ts($allVals['createtimestamp'][0]) : null,
'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null, 'account_modified' => isset($allVals['modifytimestamp'][0]) ? self::accounts_ldap2ts($allVals['modifytimestamp'][0]) : null,
); );
$account['account_fullname'] = common::display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname']);
$accounts[$account['account_id']] = $account;
} }
} }
} }
@ -793,8 +785,7 @@ class accounts_ldap
$filter = "(&(objectclass=posixgroup)(cn=$query))"; $filter = "(&(objectclass=posixgroup)(cn=$query))";
} }
$sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber')); $sri = ldap_search($this->ds, $this->group_context, $filter,array('cn','gidNumber'));
$allValues = ldap_get_entries($this->ds, $sri); foreach((array)ldap_get_entries($this->ds, $sri) as $allVals)
while (list($null,$allVals) = @each($allValues))
{ {
settype($allVals,'array'); settype($allVals,'array');
$test = $allVals['cn'][0]; $test = $allVals['cn'][0];
@ -807,7 +798,9 @@ class accounts_ldap
'account_firstname' => translation::convert($allVals['cn'][0],'utf-8'), 'account_firstname' => translation::convert($allVals['cn'][0],'utf-8'),
'account_lastname' => lang('Group'), 'account_lastname' => lang('Group'),
'account_status' => 'A', 'account_status' => 'A',
'account_fullname' => translation::convert($allVals['cn'][0],'utf-8'),
); );
if (isset($totalcount)) ++$totalcount;
} }
} }
} }