fix(sync): cast role to array for backwards compatibility #291
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
Casts
$data->roleto an array inclass-user-manually-synced.phpto maintain backwards compatibility with pre-#187 events in the event log.PR #187 changed the
rolefield from a string to an array on the sending side (class-user-manual-sync.php), but the receiving side (class-user-manually-synced.php) wasn't made backwards-compatible with events already in the event log.Nodes that haven't processed past the old-format events get permanently stuck, as
array_diff()is erroring when it receives a string instead of an array.Since this error occurs right before
set_last_processed_id()inprocess_pulled_data(), the last processed ID never advances, and the node re-pulls the same failing batch indefinitely.You can see the mixed types in the
network_manual_sync_userevents here:7218 "role":"subscriber" ← string (pre-#187)
36531 "role":"customer" ← string
...
122559 "role":["subscriber"] ← array (post-#187)
146730 "role":["contributor"] ← array
How to test the changes in this Pull Request:
The (array) cast handles both the old string format and the new array format. With a string value like "subscriber", it becomes ["subscriber"]. With an array value like ["subscriber", "customer"], it passes through unchanged. Both cases produce a valid array for array_diff()
Other information:
I'm not able to test this full loop locally, but I have tested that the (array) cast will work with both a string and an array.