WI: Add revision hash base field to all revisionable entities

Created on 17 May 2016, almost 9 years ago
Updated 27 August 2020, over 4 years ago

This issue is part of: #2721129: Workflow Initiative β†’ and was originally proposed in #1812202-25: Add UUID support for entity revisions β†’ but is now this separate issue.

Problem/Motivation

It should be possible to identify revisions across multiple environments. And the same change to an entity on multiple environments should result in the same ID. For this we need a revision hash field, with a deterministic hash algorithm.

A very important design decision in both Git and CouchDB is that if exactly the same change (time, content etc) is made in two different environments to the same entity it should result in the same revision hash. The point is that this hash should NOT be unique in the case just described. It's better if we can identify exactly the same change in two environments as the same revision hash to avoid having the same change marked as conflicts (once these two changes make it onto the same environment).

Proposed resolution

Add a new base field for all revisionable entities. Stub code for the bit that generates the hash:

  $array = $entity->toArray();
  // Don't include local IDs to keep hash consistent across multiple environments.
  foreach (['id', 'revision_id'] as $key) {
    unset($array[$key]);
  }
  $entity->revision_hash->value = md5(serialize($array));

Remaining tasks

Code.

User interface changes

None.

API changes

Only additions.

Data model changes

One additional base field for all revisionable entities. Needs an update hook to back-fill old revisions.

✨ Feature request
Status

Needs work

Version

11.0 πŸ”₯

Component

entity system

Created by

πŸ‡«πŸ‡·France dixon_ France

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States trigve hagen Washington DC

    What about adding this as a permanent fixture to the database so that the field could be used to check for unauthorized changes to content? I have a use case for this and the idea would be to have a page where an admin could run checks by creating a hash and then comparing it to the entity revision hash that gets saved on creation.

Production build 0.71.5 2024