Avoid DB error due to invalid integer value while adding object to the search index #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
You run into a DB error if you use the default search engine (not solr) and an attribute happens to contain a number that is bigger than the maximal integer size allowed by the DB.
How to reproduce the issue:
It will result in a fatal error, showing a DB transaction error.
That's due to the fact that
kernel/search/plugins/ezsearchengine/ezsearchengine.php
tries to save an integer value in the DB tableezsearch_object_word_link
columninteger_value
. That PHP file is checking if the given attribute value is a numeric value:https://github.com/mugoweb/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L97
If that's the case, it will try to store the integer value but it does not check if the value can be saved to the DB due to the limitation (max/min value) of a integer column in the DB.
This patch is limiting the integer value to the maximal/minimal value the DB can handle. Therefore it will not run into a SQL error (transaction error message).
That issue is known - here is the issue report:
https://jira.ez.no/browse/EZP-26209?jql=text%20~%20%22Out%20of%20range%20value%20for%20column%20%27integer_value%27%22
There is even a pull request:
ezsystems#1268
I decided not to use the pull request because it's not checking for the min value. Also, the information about the max/min integer value should be set in the DB API classes and not in
https://github.com/mugoweb/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php
References:
https://dev.mysql.com/doc/refman/5.7/en/integer-types.html
https://www.postgresql.org/docs/9.1/static/datatype-numeric.html