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

fix(ras): add script for fixing duplicate Mailchimp merge fields #3628

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Dec 12, 2024

All Submissions:

Changes proposed in this Pull Request:

This PR adds a CLI script related to but slightly different from the script to delete specific merge fields #3623. The new script identifies duplicate instances of merge fields with the same name in the connected Mailchimp account, then consolidates data in all instances of the field for all members in the audience into the single oldest instance of the field, then deletes all other instances of the field.

How to test the changes in this Pull Request:

  1. Check out this branch.
  2. In your connected Mailchimp account, go to Audience > All contacts > Settings > Audience fields & *MERGE* tags and add at least one new merge field with the same name as an existing Newspack meta field. You could add multiple duplicates of the same field and/or duplicates of different Newspack fields, if your audience has enough available merge fields.
  3. In at least one contact in the audience, manually edit the contact data and add some data to the newer duplicate field(s).
  4. Run wp newspack mailchimp merge-fields fix-duplicates --dry-run and confirm that it reports the duplicate fields but doesn't make any changes to the Mailchimp data or fields:
Fixing duplicate merge fields in audience <audience ID>... (DRY RUN MODE)

Found 1 duplicate merge field(s) for NP_Registration Page

Success: Would consolidate data in duplicate fields for audience <audience ID>
		Deleting merge field MMERGE26 (26) for NP_Registration Page
		DRY RUN: would have deleted merge field MMERGE26 (NP_Registration Page) in audience <audience ID>.

Success: Would delete duplicate fields for audience <audience ID>: NP_Registration Page
  1. Run the command without the --dry-run flag and confirm in your Mailchimp account that it a.) consolidates all of the contact data you added to the duplicate fields into the oldest instance of the field, and b.) deletes all other instances of the field.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo added the [Status] Needs Review The issue or pull request needs to be reviewed label Dec 12, 2024
@dkoo dkoo self-assigned this Dec 12, 2024
@dkoo dkoo requested a review from a team as a code owner December 12, 2024 23:22
@dkoo
Copy link
Contributor Author

dkoo commented Dec 12, 2024

cc @miguelpeixe since this is based on code originally written by you!

Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

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

Working as described!

Non-blocking: this file is almost 1000 lines. Maybe have a separate class-fix-mailchimp-duplicate-fields.php for these?

@github-actions github-actions bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Dec 16, 2024
@dkoo
Copy link
Contributor Author

dkoo commented Dec 16, 2024

@miguelpeixe good call, 982aa27 move all of the Mailchimp-related CLI commands to their own Newspack\CLI\Mailchimp class, and changes the commands to a newspack mailchimp namespace for clarity.

@dkoo dkoo requested a review from miguelpeixe December 16, 2024 20:40
@dkoo dkoo merged commit 07fc1e1 into hotfix/utm-keys-must-have-suffix Dec 16, 2024
7 checks passed
@dkoo dkoo deleted the fix/move-script-for-duplicate-merge-fields branch December 16, 2024 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Approved The pull request has been reviewed and is ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants