Field storage optimization added in Drupal 7.79 breaks workbench_moderation - allow opting out single node_save() operation

Created on 10 June 2021, over 3 years ago
Updated 17 April 2024, 6 months ago

Problem/Motivation

The field storage optimization added in Drupal 7.79 breaks the 'workbench_moderation' module as described in #3217490: Field storage optimization breaks content moderation .

Steps to reproduce

Copy-pasting the steps to reproduce from #3217490: Field storage optimization breaks content moderation :

  1. Download Drupal core version 7.79 or later and install using the standard profile.
  2. Note the settings.php will contain this line by default: $conf['field_sql_storage_skip_writing_unchanged_fields'] = TRUE;
  3. If that line is not present in settings.php, add it.
  4. Download and enable Workbench Moderation latest stable release and its dependencies: Drafty, Entity. Leave all of the defaults when installing.
  5. Edit the Article content type to turn on moderation: At admin/structure/types/manage/article, check the boxes Create new revision and Enable moderation of revisions. Save the content type.
  6. Add an article. At node/add/article, enter "New article" in the Title field and "Initial draft of article" in the Body field.
  7. Select the Publishing Options vertical tab and change the Moderation State dropdown to Published.
  8. Save the article.
  9. Note the article is published and contains the correct title and body text.
  10. Click New Draft to create a new draft of the article.
  11. Add another line of text to the Body field.
  12. Save the draft without changing the moderation state in the Publishing Options tab. The new revision should be in Draft status.
  13. You will see the new line of body text on the Draft tab, but not on the View Published tab.
  14. Click the Moderate tab.
  15. In the moderation state dropdown, choose Published and save the settings.
  16. Note that the new line of text is not displayed on the published version.

Proposed resolution

The problem is that workbench_moderation needs to copy all field values from an older, pre-existing revision (ie. the data stored on the field_revisions_body table) to the current field values (ie. to field_data_body). I used the 'body' field as an example, but this has to work any field type. Unfortunately, the Field API only really provides a way to do this by actually saving the node.

So, while the 'workbench_moderation' module could attempt a number of fixes on its own (for example, doing it's own SQL to copy the values, or messing with $node->original to prevent the optimization from happening), they'd all be sort of hacky and probably have some unexpected side-effects or edge cases where they wouldn't work.

Of course, you can just disable the new field storage optimization on sites that use 'workbench_moderation', but that means those sites won't be able to take advantage of this optimization, which should work fine when not moderating content through 'workbench_moderation'.

So, I'd like to propose making it possible to opt out of the optimization for a single node_save() operation by setting a special property on the node, like:

$node->skip_field_sql_storage_optimization = TRUE;
node_save($node);

Remaining tasks

  1. Write patch(es)
  2. Review
  3. Commit!

User interface changes

None.

API changes

A special entity property named 'skip_field_sql_storage_optimization' that will affect how that entity will be saved when using field_sql_storage.

Data model changes

None.

Release notes snippet

TODO

🐛 Bug report
Status

Needs review

Version

7.0 ⚰️

Component
Field 

Last updated about 14 hours ago

Created by

🇺🇸United States dsnopek USA

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

Merge Requests

Comments & Activities

Not all content is available!

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

Production build 0.71.5 2024