Introduce a dedicated autosaves endpoint for handling autosave behavior#6257
Introduce a dedicated autosaves endpoint for handling autosave behavior#6257danielbachhuber merged 124 commits intomasterfrom
Conversation
…f autosave status
# Conflicts: # editor/store/effects.js
|
I see some tests are failing, I'll get that fixed. |
danielbachhuber
left a comment
There was a problem hiding this comment.
Excited to try this out! Left a few comments to start.
| } | ||
|
|
||
| export function savePost() { | ||
| export function savePost( options ) { |
There was a problem hiding this comment.
Do these options merit a doc block?
| * | ||
| * @see WP_REST_Controller | ||
| */ | ||
| class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller { |
There was a problem hiding this comment.
Does the WP_REST_Autosaves_Controller class need to be named something else to avoid conflict with core?
There was a problem hiding this comment.
changed to GB_REST_Autosaves_Controller
| array( | ||
| 'methods' => WP_REST_Server::READABLE, | ||
| 'callback' => array( $this, 'get_items' ), | ||
| 'permission_callback' => array( $this->revision_controller, 'get_items_permissions_check' ), |
There was a problem hiding this comment.
Why do we need to instantiate a $this->revision_controller instance if we're subclassing the revisions controller?
There was a problem hiding this comment.
instantiating the parent sets it up correctly for the subsequent method calls.
| return new WP_Error( 'rest_post_invalid_id', __( 'Invalid item ID.', 'gutenberg' ), array( 'status' => 404 ) ); | ||
| } | ||
|
|
||
| return $this->parent_controller->update_item_permissions_check( $request ); |
There was a problem hiding this comment.
It's probably better to copy the contents of $this->parent_controller->update_item_permissions_check() into here.
I'd be concerned about a point in the future where $this->parent_controller->update_item_permissions_check() changed and caused an unexpected change in behavior in this controller. If we want to formalize its behavior into an explicit API, we can do so, but we should make sure we're intentional about it.
There was a problem hiding this comment.
the parent controller here is the post this autosave belongs to, and the permissions of the autosave decend directly from the parent post - this is similar to the approach we use on the revisions class.
| define( 'DOING_AUTOSAVE', true ); | ||
| } | ||
|
|
||
| $post = get_post( $request->get_param( 'id' ) ); |
There was a problem hiding this comment.
We should rename id to post. id is typically a read-only value generated by the database.
There was a problem hiding this comment.
We should rename
idtopost.idis typically a read-only value generated by the database.
Was this addressed @danielbachhuber ?
There was a problem hiding this comment.
I think we need to land this and iterate. I don't see my comment as blocking for the PR.
lib/register.php
Outdated
| foreach ( get_post_types( array(), 'objects' ) as $post_type_object ) { | ||
| if ( ! empty( $post_type_object->rest_base ) ) { | ||
| if ( post_type_supports( $post_type_object->name, 'revisions' ) ) { | ||
| $autosaves = new WP_REST_Autosaves_Controller( $post_type_object->name ); |
There was a problem hiding this comment.
Can we include the PHPUnit tests for this controller too?
There was a problem hiding this comment.
sure assuming its straightforward to bring them over from core.
…o avoid conflict with core class
Also eliminate possible race condition on autosave effecting selector prior to resolved evaluation.
UI restriction previously accounted for by fact that `AUTOSAVE` handler had aborted when post not dirty. This will need to be a future iteration on `savePost` effect.
Only those used in isEditedPostAutosaveable implementation
Since already checking isEditedPostSaveable, which returns false if save (including autosave) is in progress
Consolidate to getEditedPostAttribute as canonical source of fields values
Consolidate to getEditedPostAttribute. Unlike content, there is no special behavior for excerpt. Even if there were, getEditedPostAttribute should be the entry point, which like content, would only then defer its implementation to getEditedPostExcerpt.
|
I've pushed several commits in response to my own prior feedback. Most include extended commit descriptions with more explanation. At a high-level, the goals were:
I will dismiss my own review. If all appears well to you, feel free to merge. |
|
@aduth Thanks for all your work here, I will give this a test to verify the autosaves are still working as expected. I see there is a merge conflict now, I'll see if I can resolve that.
in the current core implementation, metabox data is not included in autosaves, however the heartbeat transport mechanism is hookable in a way that enables developers to add meta box data to autosaves on their own if they want. for regular (draft/update) saves, all of the metabox data is sent as part of the <form submission and developers can then store/respond on the PHP side. To match that here, we can probably exclude that triggering for autosaves. |
Fixed in 0bec4ea |
These ended up on the wrong side of the merge conflict 0bec4ea
|
Green means go! @pento said he'd clean up any fallout 😝 |
|
🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 🎉 Thanks @danielbachhuber - I'll also pick up any issues! |
|
@danielbachhuber Can you please direct me to the issue and/or pull request where the following promised iterations are addressed? |
We'll make sure it's polished top to bottom before it lands in core. |
|
@adamsilverstein thanks for driving this one! |
Description
Based on previous work from #4156.
Leverages the final version of the Autosaves controller from @azaozz in Trac, https://core.trac.wordpress.org/ticket/43316#comment:76
See #4112.
Does not implement the autosave alert when an autosave exists and the deletion of stale autosaves on load, these are handled in #4218
How Has This Been Tested?
Local testing, db monitoring. Verified behavior as expected, matches core.
Types of changes
isPostAutosavableseparately fromisEditedPostSaveablewithChangeDetectionto track autosave state (this needs more testing)Checklist: