-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRM-21111 Refactor include/exclude activity types into it's own function and im… #10909
CRM-21111 Refactor include/exclude activity types into it's own function and im… #10909
Conversation
30f54e9
to
ebf3dd1
Compare
ebf3dd1
to
fa4acd0
Compare
test this please |
CRM/Activity/BAO/Activity.php
Outdated
} | ||
elseif (!empty($activityTypes) && count($activityTypes)) { | ||
$activityParams['activity_type_id'] = array('IN' => array_keys($activityTypes)); | ||
if ($params['context'] != 'activity') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure where $params['context'] came in from - original line is
- if (!empty($params['activity_status_id'])) {
- $activityParams['activity_status_id'] = array('IN' => explode(',', $params['activity_status_id']));
- }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm not sure either. I've changed it back to the original.
CRM/Activity/BAO/Activity.php
Outdated
@@ -840,10 +808,10 @@ public static function getActivities($params, $getCount = FALSE) { | |||
else { | |||
$activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity); | |||
if ($apiKey == 'activity_type_id') { | |||
$activities[$id]['activity_type'] = CRM_Utils_Array::value($activities[$id][$expectedName], $activityTypes); | |||
$activities[$id]['activity_type'] = CRM_Core_PseudoConstant::getName(__CLASS__, 'activity_type_id', $activities[$id][$expectedName]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to put in the class name in case the function ever gets moved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changed all instances
CRM/Activity/BAO/Activity.php
Outdated
} | ||
elseif ($apiKey == 'campaign_id') { | ||
$activities[$id]['campaign'] = CRM_Utils_Array::value($activities[$id][$expectedName], $allCampaigns); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually feel a bit nervous about this line - as an unrelated change I feel like I have to work quite hard to validate it or let it skate through (& the latter is not good)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changed back to original.
CRM/Activity/BAO/Activity.php
Outdated
if (!empty($activityTypes) && count($activityTypes)) { | ||
return array('IN' => array_keys($activityTypes)); | ||
} | ||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this would only be hit if there were NO enabled activity types configured for the site at all? (in which case only inactive ones would be displayed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty unlikely to hit NULL yes. As the return parameter is used as an API parameter it would return no activity types.
CRM/Activity/BAO/Activity.php
Outdated
|
||
// If no activity types are specified or excluded, return the list of all active ones | ||
if (empty($params['activity_type_id']) && empty($params['activity_type_exclude_id'])) { | ||
if (!empty($activityTypes) && count($activityTypes)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think !empty is enough without count
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@mattwire I took a look at this & I get what you are doing and I think it makes sense. I checked and this function has heavy test coverage - in fact it is currently ONLY reachable from the unit tests. The function has / had performance issues so we switched back to the deprecated function. Given the above I'm happy to merge this if you can respond to the in-line comments. At least we will be in a better place if we later re-enable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eileenmcnaughton Let me know if you are happy with the changes and I'll squash the commits
CRM/Activity/BAO/Activity.php
Outdated
if (!empty($activityTypes) && count($activityTypes)) { | ||
return array('IN' => array_keys($activityTypes)); | ||
} | ||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty unlikely to hit NULL yes. As the return parameter is used as an API parameter it would return no activity types.
CRM/Activity/BAO/Activity.php
Outdated
|
||
// If no activity types are specified or excluded, return the list of all active ones | ||
if (empty($params['activity_type_id']) && empty($params['activity_type_exclude_id'])) { | ||
if (!empty($activityTypes) && count($activityTypes)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
CRM/Activity/BAO/Activity.php
Outdated
} | ||
elseif ($apiKey == 'campaign_id') { | ||
$activities[$id]['campaign'] = CRM_Utils_Array::value($activities[$id][$expectedName], $allCampaigns); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changed back to original.
CRM/Activity/BAO/Activity.php
Outdated
@@ -840,10 +808,10 @@ public static function getActivities($params, $getCount = FALSE) { | |||
else { | |||
$activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity); | |||
if ($apiKey == 'activity_type_id') { | |||
$activities[$id]['activity_type'] = CRM_Utils_Array::value($activities[$id][$expectedName], $activityTypes); | |||
$activities[$id]['activity_type'] = CRM_Core_PseudoConstant::getName(__CLASS__, 'activity_type_id', $activities[$id][$expectedName]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, changed all instances
CRM/Activity/BAO/Activity.php
Outdated
} | ||
elseif (!empty($activityTypes) && count($activityTypes)) { | ||
$activityParams['activity_type_id'] = array('IN' => array_keys($activityTypes)); | ||
if ($params['context'] != 'activity') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm not sure either. I've changed it back to the original.
fa4acd0
to
cddf679
Compare
@mattwire sure - please squash & cheer up jenkins re e-notice & we can merge |
…prove performance (don't retrieve excluded activity types)
cddf679
to
5b22d1b
Compare
@eileenmcnaughton Squashed, pending tests |
…prove performance (don't retrieve excluded activity types)
Before
API retrieved all activities, excluded activity types were removed afterwards.
After
API doesn't retrieve excluded activity types.
Technical Details
Extract activity type filtering to a new function filterActivityTypes();
Comments
The getActivities function is not actually in use anywhere yet so should be a relatively safe merge.