Skip to content

feat: integrations - rename classes and move can_sync#4451

Open
leogermani wants to merge 14 commits intofeat/integrations-foundationsfrom
integrations-reorg
Open

feat: integrations - rename classes and move can_sync#4451
leogermani wants to merge 14 commits intofeat/integrations-foundationsfrom
integrations-reorg

Conversation

@leogermani
Copy link
Contributor

@leogermani leogermani commented Feb 4, 2026

All Submissions:

Changes proposed in this Pull Request:

I'm glad that github shows a beautiful diff for this one, as most of the changes are just renaming classes.

This is what this PR does, without changing any behavior:

  • Rename classes that refers to "ESP_Sync" to "Contact_Sync"
  • Move the can_esp_sync method to the ESP integration, adding a new method to the abstraction to ask if all the pre-requisites of an integration are in place for it to work
  • Add a new has_one_syncable_integration to the Sync class. The idea here is for us to be able to do an early check to see if there's any possibility to sync. This is used, for example, to hide the "Sync to ESP" (which needs to be renamed in the future) button from the UI, or to not even bother registering handlers for the Data Events. The latter is particularly important, as we want to save resources if there's nowhere to sync data to
  • Remove some unnecessary hierarchy in some classes:

On this last one, we had a few classes (CLI and Admin Sync) that were extending the ESP_Sync class. But all they were doing was reusing the sync method and the $context attribute. I don't think that's a good pattern as they are classes of a complete different nature, and they just use some methods from Sync. No need to extend.

As we will add a lot of things to the parent Sync class, we want to avoid confusion and collisions.

How to test the changes in this Pull Request:

Smoke test sync. Nothing should change.

  1. Sync contact when registering / buying
  2. Sync contact via CLI (need to comment out one of the checks in can_sync manually)
  3. Sync contact via Admin
  4. Sync contact with Woo Teams information
  5. Force class ESP return an error in can_sync and confirm it behaves as expected (alert in the UI, sync doesnt happen, CLI returns the error, Admin link to sync is removed)
image

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?

@leogermani leogermani self-assigned this Feb 4, 2026
@leogermani leogermani added the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 4, 2026
@leogermani leogermani marked this pull request as ready for review February 4, 2026 16:14
@leogermani leogermani requested a review from a team as a code owner February 4, 2026 16:14
@leogermani leogermani requested a review from Copilot February 4, 2026 16:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the contact syncing architecture by renaming classes from "ESP_Sync" to "Contact_Sync" to better reflect support for multiple integrations beyond just ESPs. It extracts ESP-specific validation logic into the ESP integration class and introduces a new method to check if any integration can sync.

Changes:

  • Renamed ESP_Sync to Contact_Sync and related classes (Admin, CLI, Connector) across the codebase
  • Moved can_esp_sync method from Contact_Sync to the ESP integration class as can_sync
  • Added has_one_syncable_integration method to check if at least one active integration can sync
  • Removed inheritance of Admin and CLI classes from the sync class, making them standalone utilities
  • Changed integration registration from immediate to init hook at priority 5

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/unit-tests/reader-activation-sync.php Updated test to use renamed Contact_Sync class and split tests to separately validate ESP integration checks
includes/wizards/audience/class-audience-wizard.php Updated API endpoints to use has_one_syncable_integration instead of can_esp_sync
includes/reader-activation/sync/class-sync.php Added has_one_syncable_integration method to iterate through active integrations
includes/reader-activation/sync/class-contact-sync.php Renamed class from ESP_Sync to Contact_Sync, removed can_esp_sync method, updated method signature for sync_contact
includes/reader-activation/sync/class-contact-sync-admin.php Renamed class and removed inheritance from Contact_Sync
includes/reader-activation/integrations/class-esp.php Added can_sync method with ESP-specific validation logic moved from Contact_Sync
includes/reader-activation/class-integrations.php Changed integration registration from immediate to init hook at priority 5
includes/plugins/woocommerce/my-account/class-woocommerce-my-account.php Updated to use renamed Contact_Sync class and new method names
includes/plugins/class-teams-for-memberships.php Updated imports and class references to use renamed classes
includes/data-events/connectors/class-contact-sync-connector.php Renamed class and removed inheritance, updated to use Contact_Sync directly
includes/cli/class-ras-contact-sync.php Renamed class and removed inheritance, updated to call Contact_Sync methods
includes/cli/class-initializer.php Updated file includes and CLI command registration to use renamed classes
includes/class-newspack.php Updated file includes to reference renamed class files
Comments suppressed due to low confidence (1)

includes/reader-activation/sync/class-contact-sync-admin.php:15

  • Removing the inheritance from Contact_Sync breaks the ActionScheduler callback registered on line 38 of this file. The callback expects a sync_contact method to exist in this class, but it no longer does since the class doesn't extend Contact_Sync anymore. You need to add a wrapper method public static function sync_contact( $args ) that extracts the user_id from the args array and calls Contact_Sync::sync_contact( $args['user_id'], self::$context ).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI commented Feb 4, 2026

@leogermani I've opened a new pull request, #4453, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 2 commits February 4, 2026 16:56
… exist

Co-authored-by: leogermani <971483+leogermani@users.noreply.github.com>
@leogermani
Copy link
Contributor Author

Copilot had this feedback hidden under the "low confidence" section, but it's actually valid!

Removing the inheritance from Contact_Sync breaks the ActionScheduler callback registered on line 38 of this file. The callback expects a sync_contact method to exist in this class, but it no longer does since the class doesn't extend Contact_Sync anymore. You need to add a wrapper method public static function sync_contact( $args ) that extracts the user_id from the args array and calls Contact_Sync::sync_contact( $args['user_id'], self::$context ).

Fixed in 175de34

Fix has_one_syncable_integration returning true when no integrations exist
Copy link

Copilot AI commented Feb 4, 2026

@leogermani I've opened a new pull request, #4454, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI commented Feb 4, 2026

@leogermani I've opened a new pull request, #4455, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 6 commits February 4, 2026 19:42
Co-authored-by: leogermani <971483+leogermani@users.noreply.github.com>
Co-authored-by: leogermani <971483+leogermani@users.noreply.github.com>
Add registration check to has_one_syncable_integration to prevent timing errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants