Skip to content

Add campaign id to event contribution#1496

Merged
tarunnjoshi merged 1 commit intodevfrom
add-campaign-to-contribution-event
Nov 17, 2025
Merged

Add campaign id to event contribution#1496
tarunnjoshi merged 1 commit intodevfrom
add-campaign-to-contribution-event

Conversation

@tarunnjoshi
Copy link
Copy Markdown
Member

@tarunnjoshi tarunnjoshi commented Nov 17, 2025

Add campaign id to event contribution

Summary by CodeRabbit

  • New Features
    • Added event-based campaign assignment for contributions when collection source-based assignment is unavailable, ensuring contributions are properly linked to their associated campaign.

@tarunnjoshi tarunnjoshi merged commit f3c4eb5 into dev Nov 17, 2025
1 check was pending
@tarunnjoshi tarunnjoshi deleted the add-campaign-to-contribution-event branch November 17, 2025 10:22
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Nov 17, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The PR extends campaign mapping logic in CollectionCampService.php by adding Event-based fallback campaign assignment. When a Collection_Camp is not found via Contribution_Details.Source, the contribution's campaign_id is now populated from the associated Event's campaign_id if available.

Changes

Cohort / File(s) Summary
Event-based Campaign Mapping
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php
Added Civi\Api4\Event import; extended Contribution query to include Contribution_Details.Events; introduced conditional logic to retrieve Event campaign_id as fallback when Collection_Camp lookup fails

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Service as CollectionCampService
    participant CiviAPI as Civi API4

    Caller->>Service: updateCampaignForCollectionSourceContribution()
    activate Service
    
    Service->>CiviAPI: Query Contributions with<br/>Contribution_Details.Source &<br/>Contribution_Details.Events
    CiviAPI-->>Service: Contribution data
    
    alt Source or Events present
        Service->>Service: Check if Source exists
        
        alt Source found
            Service->>CiviAPI: Fetch Collection_Camp by Source
            CiviAPI-->>Service: Collection_Camp (found)
            Service->>Service: Use Collection_Camp flow
        else Source not found
            Note over Service: Fallback to Event
            Service->>CiviAPI: Fetch Event by ID
            CiviAPI-->>Service: Event with campaign_id
            Service->>Service: Update contribution with<br/>Event's campaign_id
        end
    else No Source & No Events
        Service->>Service: Return early
    end
    
    deactivate Service
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Potential concern: Early return condition (when both Source and Events are empty) should be verified to handle edge cases properly
  • Attention needed: Verify that Event lookup by ID is guaranteed to succeed; consider adding error handling if the Event record may not exist
  • Note: The fallback logic bypasses Collection_Camp matching—confirm this is the intended priority (Event campaign over explicit Collection_Camp source matching)

Possibly related PRs

  • Assign Campaign to Contribution #601: Introduced the foundational updateCampaignForCollectionSourceContribution method; this PR extends it with Event-based campaign mapping as a secondary lookup path.

Suggested labels

status : ready for review

Suggested reviewers

  • pokhiii

Poem

🎯 Events rise when Sources fade,
Campaigns mapped through fallback cascade,
One query expanded, two paths aligned,
Collection wisdom, event-designed! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-campaign-to-contribution-event

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 017acee and 8d9954c.

📒 Files selected for processing (1)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (4 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

This was referenced Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant