Skip to content

Commit

Permalink
getEntitySpecificJoins sometimes returns NULL, triggering deprecation…
Browse files Browse the repository at this point in the history
… warning for trim() in php 8.1

Discovered this in the wild where an api3 Contact.getcount call for a particular smartgroup
was causing this. The smartgroup otherwise works fine.

Looking at the code, it's clear that getEntitySpecificJoins is supposed to return a string,
but in the case of civicrm_activity_contact it was returning from another function which may
return NULL. I have coalesced NULL to empty string.
  • Loading branch information
artfulrobot committed Jul 21, 2023
1 parent fb38a5e commit c0ca194
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2665,7 +2665,7 @@ public static function fromClause(&$tables, $inner = NULL, $right = NULL, $prima
* @param string $primaryLocation
* @return string
*/
protected static function getEntitySpecificJoins($name, $mode, $side, $primaryLocation) {
protected static function getEntitySpecificJoins($name, $mode, $side, $primaryLocation): string {
$limitToPrimaryClause = $primaryLocation ? "AND {$name}.is_primary = 1" : '';
switch ($name) {
case 'civicrm_address':
Expand Down Expand Up @@ -2727,7 +2727,7 @@ protected static function getEntitySpecificJoins($name, $mode, $side, $primaryLo
case 'civicrm_activity_contact':
case 'source_contact':
case 'activity_priority':
return CRM_Activity_BAO_Query::from($name, $mode, $side);
return CRM_Activity_BAO_Query::from($name, $mode, $side) ?? '';

case 'civicrm_entity_tag':
$from = " $side JOIN civicrm_entity_tag ON ( civicrm_entity_tag.entity_table = 'civicrm_contact'";
Expand Down

0 comments on commit c0ca194

Please sign in to comment.