From 6ead277f0d35b5872380a5d2d72b364589140f80 Mon Sep 17 00:00:00 2001 From: iglocska Date: Wed, 10 Oct 2018 15:08:05 +0200 Subject: [PATCH] fix: [API] Handle filters with no valid tags set as filter patterns correctly --- app/Model/Attribute.php | 56 ++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/app/Model/Attribute.php b/app/Model/Attribute.php index 5f13bfb43..980c45640 100644 --- a/app/Model/Attribute.php +++ b/app/Model/Attribute.php @@ -2096,32 +2096,36 @@ class Attribute extends AppModel } $temp = array(); if (!empty($tagArray[0])) { - $subquery_options = array( - 'conditions' => array( - 'tag_id' => $tagArray[0] - ), - 'fields' => array( - 'event_id' - ) - ); - $lookup_field = ($options['scope'] === 'Event') ? 'Event.id' : 'Attribute.event_id'; - $temp = array_merge( - $temp, - $this->subQueryGenerator($tag->EventTag, $subquery_options, $lookup_field) - ); - $subquery_options = array( - 'conditions' => array( - 'tag_id' => $tagArray[0] - ), - 'fields' => array( - $options['scope'] === 'Event' ? 'Event.id' : 'attribute_id' - ) - ); - $lookup_field = $options['scope'] === 'Event' ? 'Event.id' : 'Attribute.id'; - $temp = array_merge( - $temp, - $this->subQueryGenerator($tag->AttributeTag, $subquery_options, $lookup_field) - ); + if ($tagArray[0][0] === -1) { + $conditions[] = array('Event.id' => -1); + } else { + $subquery_options = array( + 'conditions' => array( + 'tag_id' => $tagArray[0] + ), + 'fields' => array( + 'event_id' + ) + ); + $lookup_field = ($options['scope'] === 'Event') ? 'Event.id' : 'Attribute.event_id'; + $temp = array_merge( + $temp, + $this->subQueryGenerator($tag->EventTag, $subquery_options, $lookup_field) + ); + $subquery_options = array( + 'conditions' => array( + 'tag_id' => $tagArray[0] + ), + 'fields' => array( + $options['scope'] === 'Event' ? 'Event.id' : 'attribute_id' + ) + ); + $lookup_field = $options['scope'] === 'Event' ? 'Event.id' : 'Attribute.id'; + $temp = array_merge( + $temp, + $this->subQueryGenerator($tag->AttributeTag, $subquery_options, $lookup_field) + ); + } } $temp = array(); if (!empty($tagArray[1])) {