PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Authentication » LiveUser » Bug #1800

errors in LiveUser_Admin_Auth_Container_DB::getUsers()

Details

Submitted2004-07-05 23:08 UTC
Fromxav at spotk dot net
Assignedlsmith
StatusClosed
PackageLiveUser
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2004-07-05 23:08 UTC] xav at spotk dot net

Description:
------------
Hi,

i think i've spoted bugs in LiveUser_Admin_Auth_Container_DB::getUsers()

i tried to get standard user datas (auth_user_id, handle, passwd, is_active, lastlogin) with a simple call like:

----
$ret = $Auth->getUsers(array('auth_user_id' => 79));
----

but it always return only: auth_user_id, handle and passwd

after diving into getUsers(), i think there are 3 problems

1st: along the method the customFields array become: cFields (at line 420 of the current cvs version)

2nd: an ['optional'] key is missing

$this->authTableCols['is_active']
$this->authTableCols['owner_user_id']
$this->authTableCols['owner_group_id']

for these 3 fields, the ['optional'] key is missing, so customFields is never filled as it should be

3rd: the $fields variable is never populated if $this->authTableCols['custom']) = 0

see below for this point

after correcting those 3 issues, it seems that the method now returns correct values.

hope it help

Regards

Xavier

Reproduce code:
---------------
Point 3:

----

if (sizeof($this->authTableCols['custom']) > 0) {
foreach ($this->authTableCols['custom'] as $alias => $field_data) {
$cFields[] = $field_data['name'] . ' AS ' . $alias;
}
$fields = ',';
$fields .= implode(',', $cFields);
}
-----

which i've replaced by:

---------
if (sizeof($this->authTableCols['custom']) > 0) {
foreach ($this->authTableCols['custom'] as $alias => $field_data) {
$customFields[] = $field_data['name'] . ' AS ' . $alias;
}
}

if (sizeof($customFields > 0)) {
$fields = ',';
$fields .= implode(',', $customFields);
}
-----------

[2004-07-15 14:35 UTC] naturalkiller at gmx dot net

Finaly the method should look something like this, so that all configuration-settings are reflected as expected:

function getUsers($filters = array(), $order = null, $rekey = false)
{
if (!$this->init_ok) {
return false;
}

$fields = $where = '';
if (isset($this->authTableCols['optional']['lastlogin'])) {
$customFields[] = $this->authTableCols['optional']['lastlogin']['name'] . ' AS lastlogin';
}

if (isset($this->authTableCols['optional']['is_active'])) {
$customFields[] = "CASE {$this->authTableCols['optional']['is_active']['name']}
WHEN 'Y' THEN 1
WHEN 'N' THEN 0 END
AS is_active";
}

if (isset($this->authTableCols['optional']['owner_user_id'])) {
$customFields[] = $this->authTableCols['optional']['owner_user_id']['name'] . ' AS owner_user_id';
}

if (isset($this->authTableCols['optional']['owner_group_id'])) {
$customFields[] = $this->authTableCols['optional']['owner_group_id']['name'] . ' AS owner_group_id';
}

if (sizeof($this->authTableCols['custom']) > 0) {
foreach ($this->authTableCols['custom'] as $alias => $field_data) {
$customFields[] = $field_data['name'] . ' AS ' . $alias;
}
}

if (sizeof($customFields > 0)) {
$fields = ',';
$fields .= implode(',', $customFields);
}

if ( sizeof($filters) > 0 ) {
$where = ' WHERE';
foreach ($filters as $f => $v) {
if (is_array($v)) {
$cond = ' ' . $v['cond'];
$where .= ' ' . $f . $v['op'] . $this->dbc->quoteSmart($v['value']) . $cond;
} else {
$cond = ' AND';
$where .= " $f=$v" . $cond;
}
}
$where = substr($where, 0, -(strlen($cond)));
}

if (!is_null($order)) {
$order = ' ORDER BY ' . $order;
}

// First: Get all data from auth table.
$query = '
SELECT
' . $this->authTableCols['required']['auth_user_id']['name'] . ' AS auth_user_id,
' . $this->authTableCols['required']['handle']['name'] . ' AS handle,
' . $this->authTableCols['required']['passwd']['name'] . ' AS passwd
' . $fields . '
FROM
' . $this->authTable
. $where
. $order;

if ($rekey) {
$res = $this->dbc->getAssoc($query, false, array(), DB_FETCHMODE_ASSOC);
} else {
$res = $this->dbc->getAll($query, array(), DB_FETCHMODE_ASSOC);
}

return $res;
}

[2004-07-21 10:53 UTC] smith at backendmedia dot com

Thx for this patch. I have applied it to CVS with minimal changes.