properly return empty array if nothing was found in lookup

This commit is contained in:
Alexey Shpakovsky 2021-06-03 21:14:46 +02:00
parent 1836075735
commit 1aa874e8d3
No known key found for this signature in database
GPG key ID: 5797A726A2A4230A

View file

@ -168,14 +168,13 @@ class abook_carddav extends addressbook_backend {
*/
function lookup($value, $field=SM_ABOOK_FIELD_NICKNAME) {
if (empty($value)) {
return array();
}
if (empty($value)) { return array(); }
$abook_uri_len=strlen($this->abook->getUriPath());
if($field == SM_ABOOK_FIELD_NICKNAME) {
// TODO: edit this if we use different nick-naming scheme
$uri = $this->abook->getUriPath() . $value;
try {
$one = $this->abook->getCard($uri);
/* returns Associative array with keys:
etag(string): Entity tag of the returned card
@ -183,8 +182,12 @@ class abook_carddav extends addressbook_backend {
vcard(VCard): VCard as Sabre/VObject VCard
*/
$vcard = $one['vcard'];
// TODO: verify that something was returned
return $this->vcard2sq($uri, $vcard);
} catch (\Exception $e) {
// no card was returned
return array();
}
}
if($field == SM_ABOOK_FIELD_FIRSTNAME) { } // TODO: this will be harder
if($field == SM_ABOOK_FIELD_LASTNAME) { $filter=['N' => "/$value;/^", 'EMAIL' => "//"]; }