From c88f59a67d400c8a506bbac062de19544f060ed1 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 13 Mar 2025 13:28:22 +0100 Subject: [PATCH 1/7] fix(searchOption): notequals operator returns equals values for multiple dropdown --- hook.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hook.php b/hook.php index 2ee27aa7..42e94952 100644 --- a/hook.php +++ b/hook.php @@ -357,7 +357,12 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ], ) ) { - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + switch ($searchtype) { + case 'equals': + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + case 'notequals': + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + } } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case // update WHERE clause with LIKE statement @@ -371,7 +376,13 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ], ) ) { - return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + switch ($searchtype) { + case 'equals': + return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + case 'notequals': + return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'IS NULL '; + + } } else { return false; } From 2d26a0977945d0a4f1c5a12d1ee5b4cb8729a17b Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 13 Mar 2025 13:40:02 +0100 Subject: [PATCH 2/7] fix notequals --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index 42e94952..cff8fe62 100644 --- a/hook.php +++ b/hook.php @@ -361,7 +361,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) case 'equals': return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; case 'notequals': - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'IS NULL '; } } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case From 0219d642ac971ee55421aadb0ea2ebc5a9c85c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Langlois=20Ga=C3=ABtan?= <64356364+MyvTsv@users.noreply.github.com> Date: Fri, 14 Mar 2025 09:35:19 +0100 Subject: [PATCH 3/7] Update hook.php Co-authored-by: Stanislas --- hook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hook.php b/hook.php index cff8fe62..30092b34 100644 --- a/hook.php +++ b/hook.php @@ -361,7 +361,7 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) case 'equals': return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; case 'notequals': - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'IS NULL '; + return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'IS NULL '; } } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case From 9fedbce064b6a5085ada267abaea69f1e2743ab2 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 14 Mar 2025 09:56:10 +0100 Subject: [PATCH 4/7] verif not condition --- hook.php | 10 ++++++---- inc/dropdown.class.php | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/hook.php b/hook.php index 30092b34..ebb53e06 100644 --- a/hook.php +++ b/hook.php @@ -357,17 +357,19 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ], ) ) { + $tablefield = "$table" . '_' . "$field"; switch ($searchtype) { case 'equals': - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); case 'notequals': - return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . ' NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . 'IS NULL '; + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); } } else { // if 'multiple' field with cleaned name is found -> 'dropdown' case // update WHERE clause with LIKE statement $cleanfield = str_replace('plugin_fields_', '', $field); $cleanfield = str_replace('dropdowns_id', '', $cleanfield); + $tablefield = "$table" . '_' . "$cleanfield"; if ( $field_field->getFromDBByCrit( [ @@ -378,9 +380,9 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) ) { switch ($searchtype) { case 'equals': - return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); case 'notequals': - return $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName("$table" . '_' . "$cleanfield") . '.' . $DB->quoteName($field) . 'IS NULL '; + return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); } } else { diff --git a/inc/dropdown.class.php b/inc/dropdown.class.php index c3810aa7..727c6d09 100644 --- a/inc/dropdown.class.php +++ b/inc/dropdown.class.php @@ -254,4 +254,17 @@ public static function getClassname($system_name) { return 'PluginFields' . ucfirst($system_name) . 'Dropdown'; } + + public static function multipleDropdownAddWhere($link, $tablefield, $field, $val, $searchtype) + { + /** @var \DBmysql $DB */ + global $DB; + + switch ($searchtype) { + case 'equals': + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'LIKE ' . $DB->quoteValue("%\"$val\"%") ; + case 'notequals': + return $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'NOT LIKE ' . $DB->quoteValue("%\"$val\"%") . ' OR ' . $link . $DB->quoteName($tablefield) . '.' . $DB->quoteName($field) . 'IS NULL '; + } + } } From 1d47324e14cf0c1eeb3417866a50f3eab53d7369 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 14 Mar 2025 09:58:30 +0100 Subject: [PATCH 5/7] lint --- hook.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hook.php b/hook.php index ebb53e06..15f48a43 100644 --- a/hook.php +++ b/hook.php @@ -338,9 +338,6 @@ function plugin_datainjection_populate_fields() function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) { - /** @var \DBmysql $DB */ - global $DB; - $searchopt = &Search::getOptions($itemtype); $table = $searchopt[$ID]['table']; $field = $searchopt[$ID]['field']; @@ -383,7 +380,6 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype) return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'notequals' : 'equals'); case 'notequals': return PluginFieldsDropdown::multipleDropdownAddWhere($link, $tablefield, $field, $val, $nott ? 'equals' : 'notequals'); - } } else { return false; From 77a50b79f37bf8458b269373c8d66a9e7aa8b41f Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Fri, 14 Mar 2025 10:04:34 +0100 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index acb543d6..73ae59e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix container update from other context (like plugins) +- Fix "not equals" search operator returning the same results as the "equals" operator. ## [1.21.19] - 2025-02-03 From 00660d52c2782ff527b96de0bca45d2b5a11ff96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Langlois=20Ga=C3=ABtan?= <64356364+MyvTsv@users.noreply.github.com> Date: Mon, 17 Mar 2025 13:16:32 +0100 Subject: [PATCH 7/7] Update CHANGELOG.md Co-authored-by: Stanislas --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73ae59e6..de3ef73c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Fix container update from other context (like plugins) -- Fix "not equals" search operator returning the same results as the "equals" operator. +- Fix "not equals" search operator for dropdown `multiple` ## [1.21.19] - 2025-02-03