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

Reduce duplication pulling posts #1017

Merged
merged 59 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
84c3f03
Use post abstraction for pulling network posts.
peterwilsoncc Feb 20, 2023
77080f6
Rename get_pull_content to get_pull_content_list.
peterwilsoncc Feb 27, 2023
7ab2dad
Expose Distributor version in REST headers.
peterwilsoncc Mar 15, 2023
af11b17
Include X-Distributor-Version header in requests.
peterwilsoncc Mar 15, 2023
4db4780
Introduce helper function to determine if running a development versi…
peterwilsoncc Mar 16, 2023
df37d77
Ensure compatible version of Distributor is used.
peterwilsoncc Mar 16, 2023
a844ea3
Use post abstraction in pull list endpoint.
peterwilsoncc Mar 16, 2023
12c2831
Add method to include additional data required for external pull scre…
peterwilsoncc Mar 17, 2023
70a894c
Use new method for pull screen lists.
peterwilsoncc Mar 17, 2023
f0f7677
Accept arrays of post types and statuses.
peterwilsoncc Mar 22, 2023
a66607d
Introduce include parameter.
peterwilsoncc Mar 22, 2023
ba34f34
Add original site details to pull formatted content.
peterwilsoncc Mar 22, 2023
d0592a5
Modify method generating WP_Post object.
peterwilsoncc Mar 22, 2023
1d47baa
CS Fix.
peterwilsoncc Mar 22, 2023
7407ebe
Use false for false check.
peterwilsoncc Mar 22, 2023
b354d48
Improve variable names.
peterwilsoncc Mar 22, 2023
b888f41
Add version constant to bootstrap file.
peterwilsoncc Mar 23, 2023
dc30738
Add mocks.
peterwilsoncc Mar 23, 2023
e13c440
Assign post data to post array.
peterwilsoncc Mar 24, 2023
3f4ba02
Include connection map in remote_get.
peterwilsoncc Mar 24, 2023
dd8dd9c
Update post ID and post URL manually.
peterwilsoncc Mar 29, 2023
3c4d187
Update Source Post ID.
peterwilsoncc Mar 29, 2023
76fa01a
Remove mock that uses the general post_meta mock.
peterwilsoncc Mar 29, 2023
97dd3a1
Add mocks required by new code structure.
peterwilsoncc Mar 29, 2023
40d03c6
Add version header to various HTTP request mocks.
peterwilsoncc Mar 29, 2023
a6db663
Always use POST requests on pull screen.
peterwilsoncc Apr 4, 2023
db58d8a
Add order parameter to the get pull content REST endpoint.
peterwilsoncc Apr 6, 2023
929547b
Add orderby parameter to the get pull content REST endpoint.
peterwilsoncc Apr 6, 2023
918af12
Update docblock for new parameters.
peterwilsoncc Apr 6, 2023
0f6df49
Fix misnamed date properties.
peterwilsoncc Apr 13, 2023
9958f8c
Avoid conflicting include and exclude clauses.
peterwilsoncc Apr 13, 2023
ec02077
Use custom endpoint for pulling single post.
peterwilsoncc Apr 13, 2023
1f6de6e
Unset remote site details on one location.
peterwilsoncc Apr 13, 2023
cb79bf7
Use custom endpoint for pulling individual posts. Do in bulk.
peterwilsoncc Apr 13, 2023
8111b78
Use `wp_update_post()` when updating existing posts.
peterwilsoncc Apr 13, 2023
958c8e0
Exit if remote request fails.
peterwilsoncc Apr 13, 2023
3080b9f
Use correct names for original site data.
peterwilsoncc Apr 13, 2023
83ecd7c
Fix pull test.
peterwilsoncc Apr 13, 2023
619d50a
Always use post request for list screen.
peterwilsoncc Apr 18, 2023
a2b95c4
Remove types check, pull no longer uses WP default endpoints.
peterwilsoncc Apr 18, 2023
c8a11e7
Use POST request for pulling single post.
peterwilsoncc Apr 18, 2023
ba2c907
Remove duplicate wp_remote_retrieve_headers mock.
peterwilsoncc Apr 18, 2023
2483490
Add wp_remote_retrieve_headers mock to pull test.
peterwilsoncc Apr 18, 2023
bc5772d
Modify mocks for new flow wrapping post requests.
peterwilsoncc Apr 18, 2023
e0f4d31
Remove unused variable.
peterwilsoncc Apr 18, 2023
0df5b63
Use reset rather than zero as list_filter maintains key.
peterwilsoncc Apr 18, 2023
e7cbbc3
Correct site meta source data.
peterwilsoncc Apr 19, 2023
05dcce6
Merge branch 'develop' into fix/1016-reduce-duplication-pulling-posts
Sidsector9 Apr 24, 2023
fa68246
Sanitize and slash post meta as appropriate.
peterwilsoncc Apr 26, 2023
9dd5746
Replace placeholder versions with 2.0.0.
peterwilsoncc Apr 26, 2023
827d4d6
Fix post status argument sanitization.
peterwilsoncc Apr 26, 2023
e747fb6
Mock sanitize_url() as passthrough function.
peterwilsoncc Apr 26, 2023
27b729c
Use absint for positive integers.
peterwilsoncc Apr 28, 2023
62d165f
Escape `\` in callback.
peterwilsoncc Apr 28, 2023
0efefda
Remove duplicate `validate_callback` entry.
peterwilsoncc Apr 28, 2023
671837f
Add since tag annotation.
peterwilsoncc Apr 28, 2023
18eb1e4
Reproduce absint for test suite.
peterwilsoncc Apr 28, 2023
442113f
Merge branch 'develop' into fix/1016-reduce-duplication-pulling-posts
ravinderk May 23, 2023
c83fde1
Version check external version of Distributor on pull screen.
peterwilsoncc May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/release-pull-request-template.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- [x] Branch: Starting from `develop`, create a release branch named `release/X.Y.Z` for your changes.
- [ ] Version bump: Bump the version number in `distributor.php`, `package.json`, and `readme.txt` if it does not already reflect the version being released. In `distributor.php` update both the plugin "Version:" property and the plugin `DT_VERSION` constant.
- [ ] Version bump: Bump the version number in `distributor.php`, `package.json`, `readme.txt` and `tests/php/bootstrap.php` if it does not already reflect the version being released. In `distributor.php` update both the plugin "Version:" property and the plugin `DT_VERSION` constant.
- [ ] New files: Ensure any new files, especially in the vendor folder, are correctly included in `webpack.config.release.js`.
- [ ] Changelog: Add/update the changelog in `CHANGELOG.md`.
- [ ] Props: Update `CREDITS.md` file with any new contributors, confirm maintainers are accurate.
Expand Down
1 change: 1 addition & 0 deletions includes/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function() {
'rest_post_dispatch',
function( $response ) {
$response->header( 'X-Distributor', 'yes' );
$response->header( 'X-Distributor-Version', DT_VERSION );
Copy link
Contributor

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?

Copy link
Collaborator Author

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.


return $response;
}
Expand Down
10 changes: 10 additions & 0 deletions includes/classes/Authentication.php
Copy link
Collaborator Author

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.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public function __construct( $args ) {
* @return array
*/
public function format_get_args( $args = array(), $context = array() ) {
if ( ! isset( $args['headers'] ) ) {
$args['headers'] = array();
}
$args['headers']['X-Distributor-Version'] = DT_VERSION;
Copy link
Contributor

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.


/**
* Format request args for a GET request so auth occurs.
*
Expand All @@ -71,6 +76,11 @@ public function format_get_args( $args = array(), $context = array() ) {
* @return array
*/
public function format_post_args( $args, $context = array() ) {
if ( ! isset( $args['headers'] ) ) {
$args['headers'] = array();
}
$args['headers']['X-Distributor-Version'] = DT_VERSION;

/**
* Format request args for a POST request so auth occurs
*
Expand Down
33 changes: 33 additions & 0 deletions includes/classes/DistributorPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* @method array get_media()
* @method array post_data()
* @method array to_insert( array $args = [] )
* @method array to_pull_list( array $args = [] )
* @method array to_rest( array $args = [] )
*/
class DistributorPost {
Expand Down Expand Up @@ -816,6 +817,38 @@ protected function to_insert( $args = array() ) {
return $insert;
}

/**
Copy link
Contributor

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've created #1051 to add the annotations as I noticed I missed them for all the methods in the new class. I've added it to this method as it's introduced in this PR, see 671837f

* Get the post data in a format suitable for the pull screen.
*
* This is a wrapper for the ::to_insert() method that includes extra
* data required for the pull screen.
*
* @param mixed $args {
* Optional. Array of push arguments
* @see ::to_insert() for arguments.
* }
* @return array Post data formatted for the pull screen.
*/
protected function to_pull_list( $args = array() ) {
$display_data = $this->to_insert( $args );

// Additional information required for pull screen.
$display_data['ID'] = $this->post->ID;
$display_data['post_date'] = $this->post->post_date;
$display_data['post_date_gmt'] = $this->post->post_date_gmt;
$display_data['post_modified'] = $this->post->post_modified;
$display_data['post_modified_gmt'] = $this->post->post_modified_gmt;
$display_data['post_password'] = $this->post->post_password;
$display_data['guid'] = $this->post->guid;
$display_data['comment_status'] = $this->post->comment_status;
$display_data['ping_status'] = $this->post->ping_status;
$display_data['link'] = $this->get_permalink();
$display_data['distributor_original_site_name'] = $this->source_site['name'];
$display_data['distributor_original_site_url'] = $this->source_site['home_url'];

return $display_data;
}

/**
* Get the post data in a format suitable for the distributor REST API endpoint.
*
Expand Down
Loading