Fix fatal error when sorting by status in activity search #15911
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.
Overview
This fixes an issue where sorting activity search results by activity status fails with a fatal error because the pseudoconstants are not loaded with the correct field name.
Before
Sorting activity search results by activity status results in a fatal error.
After
Sorting by activity status works.
Technical Details
The underlying issue is that
prepareOrderBy()
hitsbuildOptions()
withactivity_status
, but onlyactivity_status_id
orstatus_id
would actually return the pseudoconstants. This builds on top of #15899 and setswhere
for the field as it would otherwise cause a DB error as well (sinceactivity_status
is not the name of the column).Comments
Not entirely sure about this fix - perhaps there's a better place to apply these changes or set an alias for this column. The pseudoconstant bit of the fix could also be done by adding a special case for
activity_status
inCRM_Activity_BAO_Activity::buildOptions()
, but that feels a bit hacky.I put this against 5.20 since it's similar to #15899, but this regression has been around a bit longer (confirmed broken on 5.13), so I can rebase if needed.