feat: integrations - rename classes and move can_sync#4451
feat: integrations - rename classes and move can_sync#4451leogermani wants to merge 14 commits intofeat/integrations-foundationsfrom
Conversation
There was a problem hiding this comment.
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_SynctoContact_Syncand related classes (Admin, CLI, Connector) across the codebase - Moved
can_esp_syncmethod fromContact_Syncto theESPintegration class ascan_sync - Added
has_one_syncable_integrationmethod 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
inithook 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_contactmethod 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 methodpublic static function sync_contact( $args )that extracts the user_id from the args array and callsContact_Sync::sync_contact( $args['user_id'], self::$context ).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@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. |
… exist Co-authored-by: leogermani <971483+leogermani@users.noreply.github.com>
|
Copilot had this feedback hidden under the "low confidence" section, but it's actually valid!
Fixed in 175de34 |
Fix has_one_syncable_integration returning true when no integrations exist
|
@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. |
|
@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. |
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
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:
can_esp_syncmethod 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 workhas_one_syncable_integrationto 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 toOn this last one, we had a few classes (CLI and Admin Sync) that were extending the
ESP_Syncclass. But all they were doing was reusing thesyncmethod and the$contextattribute. 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.
can_syncmanually)can_syncand confirm it behaves as expected (alert in the UI, sync doesnt happen, CLI returns the error, Admin link to sync is removed)Other information: