Custom Search results selection failure
Symptom: When viewing custom search results, it is possible to select all records, but individual selections do not change the count and enable action dropdowns. This does not occur for all custom searches.
Analysis: The selections are saved by CRM_Core_PrevNextCache_Sql::markSelection()
which updates the prevnext cache. However, if the results are not already in the prevnext cache, the selections are not saved. The cache is filled by CRM_Contact_Selector::fillupPrevNextCache()
which it does by taking the result of the custom search's contactIDs()
method and doing a string replace to form the query used for the cache and if the string replace fails, no results are saved in the cache and therefore individual results cannot be selected.
The string replacement method is case sensitive, so if the custom search specifies contact_a.id as contact_id
then the replacement works, but specifying contact_a.id AS contact_id
fails.
The whole approach seems rather fragile but making the string replacement case insensitive reduces that slightly, and hopefully saves developer frustration trying to track down why an innocuous select statement case change results in UI failures.