Skip to content

Conversation

@Lainow
Copy link
Contributor

@Lainow Lainow commented Mar 5, 2025

Checklist before requesting a review

Please delete options that are not relevant.

  • I have performed a self-review of my code.
  • I have added tests (when available) that prove my fix is effective or that my feature works.
  • I have updated the CHANGELOG with a short functional description of the fix or new feature.
  • This change requires a documentation update.

Description

  • It fixes !36664
  • Here is a brief description of what this PR does
    Fix the ability to search on 'number' fields

Before :
image

After :
image

Screenshots (if appropriate):

@Lainow Lainow requested review from MyvTsv and stonebuzz and removed request for MyvTsv March 5, 2025 10:32
@Lainow Lainow self-assigned this Mar 5, 2025
@Lainow Lainow requested a review from MyvTsv March 5, 2025 10:32
@stonebuzz
Copy link
Contributor

seems a revert of

#857

Can you check whether the issue raised by this PR (857) is actually fixed with it?

@Lainow
Copy link
Contributor Author

Lainow commented Mar 6, 2025

seems a revert of

#857

Can you check whether the issue raised by this PR (857) is actually fixed with it?

Yes, the problem has been solved

@stonebuzz
Copy link
Contributor

Can you validate with customer ?

Lainow and others added 4 commits March 13, 2025 09:49
Co-authored-by: Stanislas <skita@teclib.com>
Co-authored-by: Stanislas <skita@teclib.com>
@Lainow Lainow requested a review from stonebuzz March 13, 2025 09:05
@Lainow Lainow requested a review from Rom1-B March 17, 2025 09:13
@stonebuzz
Copy link
Contributor

stonebuzz commented Mar 17, 2025

After some tests,

can you reset all changes and just apply this

diff --git a/hook.php b/hook.php
index 2ee27aa..91e041b 100644
--- a/hook.php
+++ b/hook.php
@@ -344,9 +344,32 @@ function plugin_fields_addWhere($link, $nott, $itemtype, $ID, $val, $searchtype)
     $searchopt = &Search::getOptions($itemtype);
     $table     = $searchopt[$ID]['table'];
     $field     = $searchopt[$ID]['field'];
+    $pfields_type = $searchopt[$ID]['pfields_type'] ?? '';
 
     $field_field = new PluginFieldsField();
 
+
+
+    if (
+        $field_field->getFromDBByCrit(
+            [
+                'name'     => $field,
+                'type' => 'number',
+            ],
+        )
+        && $pfields_type == 'number'
+    ) {
+        // if 'number' field with name is found with searchtype 'equals' or 'notequals'
+        // surround with with qote desired value
+        // database column is delcared as varchar while GLPI search use number
+        // prevent Truncated incorrect DECIMAL value: ''
+        // where some line are NULL or '' value in related column
+        if ($searchtype == 'equals' || $searchtype == 'notequals') {
+            $operator = ($searchtype == 'equals') ? '=' : '!=';
+            return $link . $DB->quoteName("$table" . '_' . "$field") . '.' . $DB->quoteName($field) . $operator . ' ' . $DB->quoteValue($val) ;
+        }
+    }
+
     // if 'multiple' field with name is found -> 'Dropdown-XXXX' case
     // update WHERE clause with LIKE statement
     if (
diff --git a/inc/container.class.php b/inc/container.class.php
index eb6712e..e0710f6 100644
--- a/inc/container.class.php
+++ b/inc/container.class.php
@@ -1963,6 +1963,7 @@ HTML;
                     break;
                 case 'number':
                     $opt[$i]['datatype'] = 'decimal';
+                    $opt[$i]['searchtype'] = ['contains', 'notcontains', 'equals', 'notequals'];
                     break;
                 case 'date':
                 case 'datetime':

Co-authored-by: Stanislas <skita@teclib.com>
@stonebuzz stonebuzz added the bug label Mar 20, 2025
@stonebuzz
Copy link
Contributor

@Lainow can you rebase ?

@Lainow
Copy link
Contributor Author

Lainow commented Mar 20, 2025

Ok for customer

@stonebuzz stonebuzz merged commit 8499e9f into pluginsGLPI:main Mar 20, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants