Post Edit Collision Detection
|Reported by:||mdawaffe||Owned by:||anonymous|
When multiple people edit the same post, the last person to save overwrites everyone else's work. It's worse if the post is a draft; autosave stomps all over everyone's work.
This happens with surprising frequency on high traffic, multi author blogs.
Store in postmeta who last edited a post, and when that person edited it. Use that information as a "post lock". Keep the post lock fresh by updating it during autosave. If another person tries to edit a post while the post is locked, display a warning.
- Autosave currently fires every 60 seconds but only if there's some new change in the post to save. Change autosave to fire every 60 seconds no matter what (but only actually write to the DB if there are changes to the post).
- Define that 60 seconds in a new option: get_option( 'autosave_interval' );.
- New function: wp_check_post_lock() checks to see if a post is locked and by whom. A post lock is considered fresh (and the post locked) if the lock is no older than autosave_interval * 2 seconds old.
- New function: wp_set_post_lock() locks or refreshes lock.
- Whenever a person starts editing a post, set lock with wp_set_post_lock().
- During each autosave, refresh lock with wp_set_post_lock().
- When someone else goes to edit that post, if wp_check_post_lock(), display warning with admin_notices and disable autosave.
- When someone else tries to autosave, if wp_check_post_lock(), display warning via ajax and disable autosave.
- Client side of Ajax handled by beefed up wp-ajax-response JS (move to its own file from wp-list.js).
svn add wp-includes/js/wp-ajax-response.js
- Locks can only be kept fresh via the periodic ajax call (autosave). Locks cannot be kept fresh if you don't have JS.
- If the user doesn't have JS, the lock is still set when the post edit page is loaded. Since we know when the post was last modified (post_modified), we could show some kind of message if there's an old (non-fresh) lock that is newer than the post_modified and "somewhat recent". Like 5 or 10 minutes or something. That logic and UI gets complicated and confusing, though.