From a60b24a14ab3afba7d08102e27ea808fe53f702c Mon Sep 17 00:00:00 2001 From: iglocska Date: Mon, 20 Aug 2018 07:45:38 +0200 Subject: [PATCH] chg: [API] Fixed fetchAttributes lookup on value to be only optionally a substring search --- app/Model/Attribute.php | 2 +- app/Model/Event.php | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 60271d9d0..7fbed0faf 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -2906,7 +2906,7 @@ class Attribute extends AppModel } $attributes[] = $results[$key]; } - if ($break) { + if (!empty($break)) { break; } } diff --git a/app/Model/Event.php b/app/Model/Event.php index 6bd9c39de..0e7812477 100755 --- a/app/Model/Event.php +++ b/app/Model/Event.php @@ -4453,7 +4453,7 @@ class Event extends AppModel if ($parameterKey === 'org') { $found_orgs = $this->Org->find('all', array( 'recursive' => -1, - 'conditions' => array('LOWER(name) LIKE' => '%' . strtolower(substr($v, 1)) . '%'), + 'conditions' => array('name' => substr($v, 1)), )); foreach ($found_orgs as $o) { $subcondition['AND'][] = array('Event.orgc_id !=' => $o['Org']['id']); @@ -4468,7 +4468,12 @@ class Event extends AppModel $subcondition['AND'][] = array('Event.uuid !=' => substr($v, 1)); $subcondition['AND'][] = array('Attribute.uuid !=' => substr($v, 1)); } else { - $subcondition['AND'][] = array('Attribute.' . $parameterKey . ' NOT LIKE' => '%'.substr($v, 1).'%'); + $lookup = substr($v, 1); + if (strlen($lookup) != strlen(trim($lookup, '%'))) { + $subcondition['AND'][] = array('Attribute.' . $parameterKey . ' NOT LIKE' => $lookup); + } else { + $subcondition['AND'][] = array('NOT' => array('Attribute.' . $parameterKey => $lookup)); + } } } } else { @@ -4484,7 +4489,7 @@ class Event extends AppModel if ($parameterKey === 'org') { $found_orgs = $this->Org->find('all', array( 'recursive' => -1, - 'conditions' => array('LOWER(name) LIKE' => '%' . strtolower($v) . '%'), + 'conditions' => array('name' => $v), )); foreach ($found_orgs as $o) { $subcondition['OR'][] = array('Event.orgc_id' => $o['Org']['id']); @@ -4500,7 +4505,11 @@ class Event extends AppModel $subcondition['OR'][] = array('Event.uuid' => $v); } else { if (!empty($v)) { - $subcondition['OR'][] = array('Attribute.' . $parameterKey . ' LIKE' => '%'.$v.'%'); + if (strlen($v) != strlen(trim($v, '%'))) { + $subcondition['AND'][] = array('Attribute.' . $parameterKey . ' LIKE' => $v); + } else { + $subcondition['AND'][] = array('Attribute.' . $parameterKey => $v); + } } } }