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

Added ability to view all post types when Pulling from an External Connection #1002

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

mehul0810
Copy link

@mehul0810 mehul0810 commented Jan 12, 2023

Description of the Change

Closes #861

How to test the Change

  • Go to Distributor > Pull Content (Make sure you have added an internal as well as external connection)
  • Check and confirm that "View All" filter is available for both internal and external connection
  • Check and confirm that filtering with "View All", displays posts from all the post types for both internal and external connection

Changelog Entry

Fixed - Bug fix

Credits

Props @username, @username2, ...

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@mehul0810 mehul0810 marked this pull request as ready for review January 14, 2023 09:44
@mehul0810 mehul0810 requested a review from a team as a code owner January 14, 2023 09:44
@mehul0810 mehul0810 requested review from cadic and removed request for a team January 14, 2023 09:44
@cadic cadic added this to the 2.0.0 milestone Jan 16, 2023
Copy link
Contributor

@cadic cadic left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @mehul0810

I've left couple non-blocking questions and a suggestion for the $args in get_pull_content()

return;
}
foreach ( $remote_get_args['post_type'] as $type ) {
$remote_get_args['post_type'] = $type;
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if rewriting the source array index 'post_type' (on which we perform the foreach block) with the scalar value is a good option.

While technically it works fine and the code block will execute as expected, this assignment modifies the $remote_get_args['post_type'] from the array to the last element only.

$remote_get = $connection_now->remote_get( $remote_get_args );

if ( is_wp_error( $remote_get ) ) {
$this->pull_error = $remote_get->get_error_messages();
Copy link
Contributor

Choose a reason for hiding this comment

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

After converting the routine from single to multiple remote requests, this $this->pull_error only assigned with the most recent request errors instead of combining errors from all requests.

$args = [
'posts_per_page' => isset( $request['posts_per_page'] ) ? $request['posts_per_page'] : 20,
'paged' => isset( $request['page'] ) ? $request['page'] : 1,
'post_type' => isset( $request['post_type'] ) ? $request['post_type'] : 'post',
'post_type' => array( 'post', 'page' ),
Copy link
Contributor

@cadic cadic Jan 22, 2023

Choose a reason for hiding this comment

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

Shouldn't we use the $post_type variable described a few lines above?

Suggested change
'post_type' => array( 'post', 'page' ),
'post_type' => $post_type,

@@ -437,10 +437,13 @@ function check_post_types_permissions() {
* @return \WP_REST_Response|\WP_Error
*/
function get_pull_content( $request ) {
$post_type = isset( $request['post_type'] ) ? $request['post_type'] : 'all';
$post_type = 'all' === $post_type ? array( 'post', 'page' ) : $post_type;
Copy link
Contributor

Choose a reason for hiding this comment

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

@mehul0810 I think we should not accept all as the value of post_type. We should be specific about which post_type posts we should return in the result. We can update the rest API post_type param to accept string and array to query more than one post type simultaneously.

Let me know if you have any questions.

@peterwilsoncc
Copy link
Collaborator

In #1017 (awaiting merge) I've made a bunch of modifications to the rest api endpoint that should make this more achievable. It will probably cause a lot of conflicts to this PR though.

You'll be able to use post_type => any once that PR is merged as the custom endpoint will modify the value to only include post types the user can read, either because they have permission or the post type is publicly viewable.

@peterwilsoncc peterwilsoncc modified the milestones: 2.0.0, 2.0.1 May 24, 2023
@jeffpaul jeffpaul mentioned this pull request Sep 14, 2023
16 tasks
@peterwilsoncc peterwilsoncc modified the milestones: 2.0.1, 2.1.0 Sep 19, 2023
@github-actions github-actions bot added the needs:refresh This requires a refreshed PR to resolve. label Feb 9, 2024
Copy link

github-actions bot commented Feb 9, 2024

@mehul0810 thanks for the PR! Could you please rebase your PR on top of the latest changes in the base branch?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs:refresh This requires a refreshed PR to resolve. nice-to-have
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to view all post types when Pulling from an External Connection
6 participants