-
Notifications
You must be signed in to change notification settings - Fork 11
Facilitate users concurrently editing a snapshot #60
Comments
@westonruter Instead of locking could we add a history of changes that have happened in the snapshot and keep the latest value? Then we could show that a change has been made and let the content editors keep, restore a different version or combine? I am thinking of a ui like this: Both links (red and yellow) would pop-up a history (new panel?) with the option to go back to an older version. The code to capture the history could look like this: (modified from /plugins/customize-snapshots/php/class-customize-snapshot.php) public function set( \WP_Customize_Setting $setting, $value, $deprecated = null ) {
if ( ! is_null( $deprecated ) ) {
_doing_it_wrong( __METHOD__, 'The $dirty argument has been removed.', '0.4.0' );
if ( false === $deprecated ) {
return;
}
}
$history = isset( $this->data[ $setting->id ]['history'] ) ? (array) $this->data[ $setting->id ]['history'] : array();
if ( ! isset( $this->data[ $setting->id ]['value'] ) || $this->data[ $setting->id ]['value'] !== $value ) {
$history[] = array(
'value' => $value,
'user' => get_current_user_id(),
'timestamp' => current_time( 'timestamp', true ),
);
}
$this->data[ $setting->id ] = array(
'value' => $value,
'sanitized' => false,
'history' => $history,
);
} |
@lgedeon yeah, I agree that the user should be able to either accept the other's saved value or override the other's saved value. They should be able to see what the value is. I don't think we need a full history however. We just need to store with each |
@lgedeon sorry for the confusion regarding “if the timestamp is greater than the current time”. What I meant is if the “setting modified timestamp” in the snapshot is greater than the timestamp for when the user's Customizer session was first started. So when a user opens the Customizer, we should capture the time, and then send this time in every snapshot save request. In the request we can then compare the session start timestamp to determine whether there is a conflict. Really this functionality could actually be worked into (or at least integrated with) a revisited Customize Concurrency plugin: https://github.com/xwp/wp-customize-concurrency |
If two users edit the same snapshot, there is currently the real possibility that users will override each other's changes. There needs to be concurrency support for snapshots. When this happens, the snapshot save should be rejected as a validation failure, with a prompt to resolve the conflict, by accepting their changes or overriding the changes with their own.
We need to keep track of the settings that have been changed since the last snapshot save and send it along with the snapshot save request. See approach for keeping track of settings changed: https://github.com/xwp/wordpress-develop/blob/a501d6c8be242dce7bcff0e14b145953057ff7ba/src/wp-admin/js/customize-controls.js#L3685-L3688
Whenever a value is updated in a snapshot, beyond storing the setting
value
we can also store the timestamp for when the setting was updated and also the user ID who actually saved it.Other general notes on concurrency locking in general:
The text was updated successfully, but these errors were encountered: