Skip to content

Add optional disabled campaign penalty for create matcher - #534

Open
minyanyi wants to merge 1 commit into
Project60:masterfrom
minyanyi:feat/disabled-campaign-penalty
Open

Add optional disabled campaign penalty for create matcher#534
minyanyi wants to merge 1 commit into
Project60:masterfrom
minyanyi:feat/disabled-campaign-penalty

Conversation

@minyanyi

Copy link
Copy Markdown

Refs #133

Summary

  • add an optional disabled_campaign_penalty config value for the create campaign matcher
  • reduce the suggestion score when the matched campaign is disabled and surface that penalty in the suggestion warning
  • add a regression test that covers the reduced-score behavior for disabled campaigns

Testing

  • could not run PHPUnit locally on this machine because php and cv are not available in PATH

@dontub dontub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @minyanyi for that feature! Can you have a look at my comments?

* @return float
* Penalty added to the contact's rating.
*/
public function adjustRatingOfDisabledCampaign($campaign_id, &$contact_probability) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this could be private, couldn't it?

Can you add PHP type hints to the method signature? For $campaign_id I'd prefer to not allow strings.


if (!array_key_exists($campaign_id, $campaign_is_active)) {
try {
$campaign = civicrm_api3('Campaign', 'getsingle', ['id' => $campaign_id]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For new code we should use APIv4. You could limit the selected field to is_active.

$campaign = civicrm_api3('Campaign', 'getsingle', ['id' => $campaign_id]);
}
catch (Exception $ex) {
$this->logMessage("Campaign [{$campaign_id}] could not be loaded, disabled-campaign penalty skipped.", 'warn');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if the hyphen in disabled-campaign is correct English...

public function testCampaignMatcherAppliesDisabledCampaignPenalty(): void {
$activity_type_id_used_in_matcher_config = 4;
try {
civicrm_api3('OptionValue', 'getsingle', [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is duplicated code from testCampaignMatcherBasic(). What about adding a setUp() method where is checked whether the activity type ID exists exists and if not, create an activity type (using APIv4)?

/**
* Disabled campaigns can reduce the suggestion score if configured.
*/
public function testCampaignMatcherAppliesDisabledCampaignPenalty(): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 for the test. A test that checks whether the penalty is NOT applied if the campaign is active would be great.

@dontub dontub added status:needs work There is code, but it needs additional work before it should be reviewed and removed status:needs review Code needs review and testing labels Jul 23, 2026
@dontub dontub self-assigned this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement status:needs work There is code, but it needs additional work before it should be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants