-
Notifications
You must be signed in to change notification settings - Fork 156
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
Reduce duplication pulling posts #1017
Reduce duplication pulling posts #1017
Conversation
$formatted_post = Utils\prepare_post( $post ); | ||
$dt_post = new DistributorPost( $post ); | ||
$formatted_post = $dt_post->to_insert( $new_post_args ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes a BC change on this line below.
return apply_filters( 'dt_remote_get', $formatted_post, $args, $this ); |
The $formatted_post
was passed as an object in the past but is now passed as an array.
However, the filter is conflicted anyways as demonstrated by this code, it can sometimes be an object, sometimes an array.
aea7570
to
a26027a
Compare
3c71b50
to
5c4f891
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Todo: Make sure this doesn't affect the wp.com oauth flow.
d568542
to
a9ce06e
Compare
So it seems network pulls are broken. For some reason, it appears the posts are going straight to the skipped column on network connections but I am unable to figure out why at the moment. While testing, I suspect it is intermittent too. The return type of |
d3d5e75
to
65cd23f
Compare
'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_original_post_id', 2 ], | ||
'args' => [ \WP_Mock\Functions::type( 'int' ), 'dt_original_post_id', 111 ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not figure out why this was passing. The get_post()
mock above is using 111
so that's what should have been passed.
051325c
to
2484a94
Compare
337a70c
to
c4f49f1
Compare
…on of the plugin.
This is Big. Changes:
Testing notes These are the situations I cna think of:
Feel free to add anything to this list you think of for testing
|
Thanks for the review @dkotter, I've addressed each of your suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc I left minor suggestions. Let me know if you have questions.
@@ -54,6 +54,7 @@ function() { | |||
'rest_post_dispatch', | |||
function( $response ) { | |||
$response->header( 'X-Distributor', 'yes' ); | |||
$response->header( 'X-Distributor-Version', DT_VERSION ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc I am not aware why we add distributor-related information to all API requests. Is it required? Can we limit it to distributor-specific rest API requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not aware why we add distributor-related information to all API requests.
Not sure of the design decision here, let's open a ticket as a maybe later.
if ( ! isset( $args['headers'] ) ) { | ||
$args['headers'] = array(); | ||
} | ||
$args['headers']['X-Distributor-Version'] = DT_VERSION; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc I see we are repeating this multiple times in the code base. I am okay with explicitly adding this in the header, but I want to check if we can add this header automatically with a filter hook to any distributor-related call.
@@ -816,6 +817,38 @@ protected function to_insert( $args = array() ) { | |||
return $insert; | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc Can we add since
tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_filter( 'wp_insert_post_data', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'maybe_set_modified_date' ), 10, 2 ); | ||
|
||
// Filter documented in includes/classes/ExternalConnections/WordPressExternalConnection.php | ||
$new_post_args = Utils\post_args_allow_list( apply_filters( 'dt_pull_post_args', $post_array, $item_array['remote_post_id'], $post, $this ) ); | ||
$new_post_id = wp_insert_post( wp_slash( $new_post_args ) ); | ||
|
||
if ( $update ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterwilsoncc wp_insert_post
handles post update and insert. Can we use it? instead of if...else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wp_insert_post
handles post update and insert. Can we use it? instead ofif...else
wp_update_post
includes a number of date, status and taxonomy checks that the previous code was either missing or doubling up, so I wanted to switch to the function to avoid the need to duplicate it.
@peterwilsoncc I am facing a weird issue when using this pull request. Check the screencast and let me know if You have questions. Screen.Recording.2023-04-27.at.6.42.35.PM.mov |
I'm unable to reproduce the issue, but will continue testing. A few questions:
If I continue to have problems reproducing, I'll reach our via slack |
@peterwilsoncc I was able to reproduce the issue ☝️ with the following steps 👇 Step to reproduce the issue
As I understand it, we are changing the data format without backward compatibility. There is the possibility that two connected websites can have two different versions of the distributor plugin. Any new change should be compatible with the following scenario. Feel free to ask any questions. |
@ravinderk that's covered by these lines distributor/includes/rest-api.php Lines 367 to 391 in 0efefda
As the version on |
Sorry, I had this reversed. Taking a look. |
@ravinderk In c83fde1 I've pushed an additional check for the external version of Distributor to the pull screen. As we bump However, removing I can jump on a call if you want me to clarify over a screen share. |
Description of the Change
Closes #1016
How to test the Change
Changelog Entry
Credits
Props @peterwilsoncc
Checklist: