diff options
author | Morris Jobke <hey@morrisjobke.de> | 2019-07-19 18:03:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-19 18:03:37 +0200 |
commit | a085a88205ccf833c347c1b0a5021ca2ee8db484 (patch) | |
tree | ec1389dea6c027f3c90513576cad579ba0c37892 /apps/dav/lib/CardDAV | |
parent | c00d6f4eac9075e651fbef791f4e7c7157cad709 (diff) | |
parent | 2c5ebac458f899af190d2ef7bf8702624e700049 (diff) | |
download | nextcloud-server-a085a88205ccf833c347c1b0a5021ca2ee8db484.tar.gz nextcloud-server-a085a88205ccf833c347c1b0a5021ca2ee8db484.zip |
Merge pull request #14954 from tacruc/searchPatterns
Allow to search for real pattern in contacts
Diffstat (limited to 'apps/dav/lib/CardDAV')
-rw-r--r-- | apps/dav/lib/CardDAV/AddressBookImpl.php | 8 | ||||
-rw-r--r-- | apps/dav/lib/CardDAV/CardDavBackend.php | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/apps/dav/lib/CardDAV/AddressBookImpl.php b/apps/dav/lib/CardDAV/AddressBookImpl.php index 351e064595b..918b4eb2255 100644 --- a/apps/dav/lib/CardDAV/AddressBookImpl.php +++ b/apps/dav/lib/CardDAV/AddressBookImpl.php @@ -97,20 +97,22 @@ class AddressBookImpl implements IAddressBook { /** * @param string $pattern which should match within the $searchProperties * @param array $searchProperties defines the properties within the query pattern should match - * @param array $options Options to define the output format - * - types boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array + * @param array $options Options to define the output format and search behavior + * - 'types' boolean (since 15.0.0) If set to true, fields that come with a TYPE property will be an array * example: ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['type => 'HOME', 'value' => 'g@h.i']] + * - 'escape_like_param' - If set to false wildcards _ and % are not escaped * @return array an array of contacts which are arrays of key-value-pairs * example result: * [ * ['id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'], * ['id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => ['d@e.f', 'g@h.i']] * ] + * @param array $options = array() 'escape_like_param' - to not escape wildcards _ and % - for future use. One should always have options! * @return array an array of contacts which are arrays of key-value-pairs * @since 5.0.0 */ public function search($pattern, $searchProperties, $options) { - $results = $this->backend->search($this->getKey(), $pattern, $searchProperties); + $results = $this->backend->search($this->getKey(), $pattern, $searchProperties, $options = $options); $withTypes = \array_key_exists('types', $options) && $options['types'] === true; diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index b16bcd993cf..7dbd41a69c8 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -903,9 +903,11 @@ class CardDavBackend implements BackendInterface, SyncSupport { * @param int $addressBookId * @param string $pattern which should match within the $searchProperties * @param array $searchProperties defines the properties within the query pattern should match + * @param array $options = array() to define the search behavior + * - 'escape_like_param' - If set to false wildcards _ and % are not escaped, otherwise they are * @return array an array of contacts which are arrays of key-value-pairs */ - public function search($addressBookId, $pattern, $searchProperties) { + public function search($addressBookId, $pattern, $searchProperties, $options = array()) { $query = $this->db->getQueryBuilder(); $query2 = $this->db->getQueryBuilder(); @@ -919,7 +921,11 @@ class CardDavBackend implements BackendInterface, SyncSupport { // No need for like when the pattern is empty if ('' !== $pattern) { - $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))); + if(\array_key_exists('escape_like_param', $options) && $options['escape_like_param'] === false) { + $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter($pattern))); + } else { + $query2->andWhere($query2->expr()->ilike('cp.value', $query->createNamedParameter('%' . $this->db->escapeLikeParameter($pattern) . '%'))); + } } $query->select('c.carddata', 'c.uri')->from($this->dbCardsTable, 'c') |