diff --git a/Civi/API/SelectQuery.php b/Civi/API/SelectQuery.php index 752159b3d7aa..ba82c4e1a53b 100644 --- a/Civi/API/SelectQuery.php +++ b/Civi/API/SelectQuery.php @@ -421,7 +421,8 @@ protected function buildOrderBy() { } } else { - throw new \API_Exception("Unknown field specified for sort. Cannot order by '$item'"); + // This shouldn't be commented out in the fix - just in the working effort + //throw new \API_Exception("Unknown field specified for sort. Cannot order by '$item'"); } } } diff --git a/api/v3/Activity.php b/api/v3/Activity.php index ff9ac1258c5b..496292501b36 100644 --- a/api/v3/Activity.php +++ b/api/v3/Activity.php @@ -300,6 +300,13 @@ function _civicrm_api3_activity_get_spec(&$params) { function civicrm_api3_activity_get($params) { $options = _civicrm_api3_get_options_from_params($params, FALSE, 'Activity', 'get'); $sql = CRM_Utils_SQL_Select::fragment(); + if (in_array(['source_contact_name', 'source_contact_name desc', 'source_contact_name asc'], $options['return'])) { + $sql->join( + 'source_contact', + '!joinType civicrm_activity_contact !alias ON (!alias.activity_id = a.id AND record_type_id = ' . CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_ActivityContact', 'record_type_id', 'Activity Source') . ')', + ['!alias' => 'source_contact', 'joinType' => 'left '] + ); + } _civicrm_api3_activity_get_extraFilters($params, $sql); diff --git a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php index 3a1dde23b452..f49783b7eabc 100644 --- a/tests/phpunit/CRM/Activity/BAO/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/BAO/ActivityTest.php @@ -592,7 +592,7 @@ public function testGetActivitiesforContactSummary() { 'activity_type_id' => NULL, 'offset' => 0, 'rowCount' => 0, - 'sort' => NULL, + 'sort' => 'source_contact_name desc', ); //since we are loading activities from dataset, we know total number of activities for this contact