Skip to content
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

dev/core#3692: use buildOptions for activityType, activityStatus where easy. Also a relationshipType #23880

Closed
wants to merge 3 commits into from

Conversation

herbdool
Copy link
Contributor

Fixes https://lab.civicrm.org/dev/core/-/issues/3692

This might be hard to test. I focused on the ones that were more straightforward and left the ones that might need more decisions.

@civibot
Copy link

civibot bot commented Jun 24, 2022

(Standard links)

@civibot civibot bot added the master label Jun 24, 2022
@demeritcowboy demeritcowboy changed the title Issue 3692: use buildOptions for activityType, activityStatus where easy. Also a relationshipType dev/core#3692: use buildOptions for activityType, activityStatus where easy. Also a relationshipType Jun 24, 2022
@herbdool
Copy link
Contributor Author

I made another pass. I changed some of the "get" to "search" for fetching statuses, where the original code was not including inactive items. And I fixed a few others. In all cases I tried to ensure the original filtering was preserved. Where fetching an array of activity types or statuses was only used to find the label I either left it to fetch all, or switched it to use CRM_Core_Pseudoconstant::getLabel().

There were a couple tricky spots where it either needed to only include case activities or exclude. For that I used CRM_Core_OptionGroup::values() which I saw was being used in a report already. Though it is quite low level I didn't see any warnings about using it or not. And it appears to be cached.

For reference the original CRM_Core_PseudoConstant::activityType() uses this to include/exclude:

$all, defaults to TRUE
$includeCaseActivities, defaults to FALSE
$reset, defaults to FALSE
$returnColumn, defaults to 'label'
$includeCampaignActivities, defaults to FALSE
$onlyComponentActivities, defaults to FALSE

In each case I went over the flags and ensured they would still match. The replacement buildOptions doesn't care about including case/campaign/component activities - they're included by default with 'get' and with 'search' are excluded only if they are disabled or if the component is disabled.

@@ -564,7 +564,8 @@ public function where($recordType = NULL) {
empty($this->_params['activity_type_id_value'])
) {
if (empty($this->_params['include_case_activities_value'])) {
$this->activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'label', TRUE);
$componentId = CRM_Core_Component::getComponentID('CiviCase');
$this->activityTypes = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, " AND v.component_id !={$componentId} OR v.component_id IS NULL");
Copy link
Contributor

@demeritcowboy demeritcowboy Jun 27, 2022

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll see if my update fixes that.

@@ -2511,7 +2509,7 @@ public static function getContactActivitySelector(&$params) {
}

$activity['activity_date_time'] = CRM_Utils_Date::customFormat($values['activity_date_time']);
$activity['status_id'] = $activityStatus[$values['status_id']];
$activity['status_id'] = CRM_Core_Pseudoconstant::getLabel('CRM_Activity_BAO_Activity', 'status_id', $values['status_id']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't the same - it now includes disabled. I personally like that but some people won't.

@@ -143,7 +143,7 @@ public function getDefaultEntity() {
public function setFields() {
// Remove print document activity type
$unwanted = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, "AND v.name = 'Print PDF Letter'");
$activityTypes = array_diff_key(CRM_Core_PseudoConstant::ActivityType(FALSE), $unwanted);
$activityTypes = array_diff_key(CRM_Activity_BAO_Activity::buildOptions('activity_type_id', 'search'), $unwanted);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't the same. Before it didn't include case activity types and now it does and also all the ones with filter=1.

@@ -25,7 +25,7 @@ public function setUp(): void {
}

public function testSequence() {
$actStatuses = array_flip(\CRM_Core_PseudoConstant::activityStatus('name'));
$actStatuses = array_flip(\CRM_Activity_BAO_Activity::buildOptions('status_id', 'validate'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the same, but for it's use here in the test is ok.

@@ -1234,7 +1235,7 @@ public static function deleteContribution($id) {
$params = [
'source_record_id' => $id,
// activity type id for contribution
'activity_type_id' => 6,
'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Contribution'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the number 6, but ok. (grin)

@eileenmcnaughton
Copy link
Contributor

Unfortunately this has gone stale & needs a rebase - I pulled out a handful of small changes into separate commits so this will lose a bit of bulk when it is rebased

@herbdool
Copy link
Contributor Author

I've rebased this. Though would need to check a few more comments before it's ready.

@demeritcowboy demeritcowboy added the needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state label Oct 4, 2022
@civicrm-builder
Copy link

Can one of the admins verify this patch?

@@ -70,7 +70,7 @@ public function preProcess() {
CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails);

//get the survey activities.
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@demeritcowboy these swaps are safe aren't they? This PR is stale & I think turned out to be way trickier than initial appearance but I'm thinking maybe I can salvage some of the bits that are straight foward

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of them might be.

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Nov 30, 2023
civicrm#23880 is
thoroughly stale so I'm closing it - but just thought I'd rescue a couple of changes

These are in the barely maintained legacycustomsearches so of marginal risk &
marginal benefit but since I looked maybe no-one else has to ever again...
eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Nov 30, 2023
civicrm#23880 is
thoroughly stale so I'm closing it - but just thought I'd rescue a couple of changes

These are in the barely maintained legacycustomsearches so of marginal risk &
marginal benefit but since I looked maybe no-one else has to ever again...
@eileenmcnaughton
Copy link
Contributor

I'm going to close this out because it's stale - it probably stalled on some of the challenges picked up in the review. I did save the last couple of changes in #28384 (just because I randomly started from the bottom)

eileenmcnaughton added a commit to eileenmcnaughton/civicrm-core that referenced this pull request Nov 30, 2023
civicrm#23880 is
thoroughly stale so I'm closing it - but just thought I'd rescue a couple of changes

These are in the barely maintained legacycustomsearches so of marginal risk &
marginal benefit but since I looked maybe no-one else has to ever again...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master needs-work-not-review-ready Submitter required to take action, will be closed after 1-2 weeks in this state
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants