Skip to content

Commit

Permalink
Bug: 14719 Fix filtering on returnFields.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Oct 29, 2017
1 parent 368360a commit 1a79f02
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions lib/Api.php
Expand Up @@ -1160,7 +1160,8 @@ public function replace($uid, $content, $contentType, $sources = null)
* DEFAULT: false
* - matchBegin: (boolean) Match word boundaries only?
* DEFAULT: false
* - returnFields: Only return these fields.
* - returnFields: Only return these fields. Note that the __key field
* will always be returned.
* DEFAULT: Return all fields.
* - rfc822Return: Return a Horde_Mail_Rfc822_List object.
* DEFAULT: Returns an array of search results.
Expand Down Expand Up @@ -1349,7 +1350,10 @@ public function search($names = null, array $opts = array())
);

foreach (array_keys($ob->driver->getCriteria()) as $key) {
$att[$key] = $ob->getValue($key);
if (empty($opts['returnFields']) ||
(!empty($opts['returnFields']) && in_array($key, $opts['returnFields']))) {
$att[$key] = $ob->getValue($key);
}
}

$email = new Horde_Mail_Rfc822_List();
Expand All @@ -1360,6 +1364,12 @@ public function search($names = null, array $opts = array())
unset($tdisplay_name);
$email_fields = array();
foreach (array_keys($att) as $key) {
// Only concerned about keys that we want returned.
if (!empty($opts['returnFields']) &&
!in_array($key, $opts['returnFields'])) {
continue;
}

if ($ob->getValue($key) &&
isset($attributes[$key]) &&
($attributes[$key]['type'] == 'email')) {
Expand Down Expand Up @@ -1423,13 +1433,37 @@ public function search($names = null, array $opts = array())

if (empty($opts['rfc822Return'])) {
foreach ($emails as $val) {
$out[] = array_merge($att, array(
$atts = array(
'__type' => 'Object',
'email' => $val,
'id' => $att['__key'],
'name' => $display_name,
'source' => $source
));
);
if (empty($opts['returnFields'])) {
$atts = array(
'__type' => 'Object',
'id' => $att['__key'],
'source' => $source,
'email' => $val,
'name' => $display_name
);
} else {
$atts = array();
$fields = array(
'__type' => 'Object',
'id' => $att['__key'],
'source' => $source,
'email' => $val,
'name' => $display_name
);
foreach($fields as $field => $value) {
if (in_array($field, $opts['returnFields'])) {
var_dump($field);
$atts[$field] = $value;
}
}
}

$out[] = array_merge($att, $atts);
}
}
}
Expand Down

0 comments on commit 1a79f02

Please sign in to comment.