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

Set post status for Post Object Create mutations late, to allow for side-effects before final status is set #395

Conversation

jasonbahl
Copy link
Collaborator

@jasonbahl jasonbahl commented Feb 13, 2018

  • Make sure you are making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Make sure you are requesting to pull request from a topic/feature/bugfix branch (right side). Don't pull request from your master!

What does this implement/fix? Explain your changes.

During PostObjectMutations, any post_status input will be cached, and the post will be created with the default status (draft, but filterable to accompany plugins like Edit Flow, etc).

Then the side-effects will be triggered via PostObjectMutation::update_additional_post_object_data().

Then, if $should_set_intended_status is true (filterable), the post_status that was input with the mutation (if different than the default) will be set as the status of the post.

This allows for side effects that may take a long time (sideloading images, etc) to happen in a deferred process (like a WPCron or a WP Queue Task - https://github.com/dfmedia/wp-queue-tasks) and those side effects can come back later and set the status when they complete.

Does this close any currently open issues?

closes #394
closes #393

Where has this been tested?

Operating System:
Mac OSX 10.12.6

WordPress Version:
4.9.4

Copy link
Member

@CodeProKid CodeProKid left a comment

Choose a reason for hiding this comment

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

@jasonbahl a few things

'edit_date' => ! empty( $post_args['post_date'] ) ? $post_args['post_date'] : false,
];

$update_args = array_merge( $update_args );
Copy link
Member

Choose a reason for hiding this comment

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

I think you are missing the second array you are trying to merge in here, eh?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, I did have a merge, but changed it.

];

$update_args = array_merge( $update_args );
wp_update_post( $update_args );
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this get moved out of this if statement so it fires even if the filter is set to false?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. The intent is that a plugin, like DFM GraphQL Extensions, that needs to process sideloaded images, can filter this to false, meaning the created post will remain a draft. Then the process that sideloads the images can come back and set the post as Publish or whatever the intended status was.

Otherwise, if the status was set to publish and the deferred (cron / queued tasks, etc) side effects were not complete, then you'd have a published post with incomplete data.

@jasonbahl jasonbahl changed the title no message Set post status for Post Object Create mutations late, to allow for side-effects before final status is set Feb 13, 2018
- Fixes some code review feedback, and provides additional context to some filters and actions to make it easier for plugins to handle mutation side effects.
@jasonbahl
Copy link
Collaborator Author

jasonbahl commented Feb 13, 2018

@CodeProKid pushed an update, cleaning up the unused array_merge, and including some additional context in some of the hooks/filters (requested by @hughdevore for some of the work he's doing to sideload galleries)

@coveralls
Copy link

coveralls commented Feb 13, 2018

Coverage Status

Coverage increased (+0.02%) to 91.54% when pulling 03d4c84 on jasonbahl:feature/#394-set-post-status-late-on-create-mutations into ba9724b on wp-graphql:develop.

- Fixes some code review feedback, and provides additional context to some filters and actions to make it easier for plugins to handle mutation side effects.
@jasonbahl
Copy link
Collaborator Author

@CodeProKid updated to fix the broken tests too.

@jasonbahl jasonbahl merged commit e177979 into wp-graphql:develop Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants