Inconsistent database because of a bug in the Content Moderation module

Created on 18 October 2019, about 5 years ago
Updated 23 February 2023, almost 2 years ago

Creating translations of published nodes results a faulty db state, which makes impossible of the listing of some node content in content revision views. To reproduce this issue the minimum setup:

- Installed a brand new Drupal 8.7.8, with views, moderation and workflow modules enabled
- Added a new language the system (/admin/config/regional/language) - Hungarian
- Created a new translatable content type - testbundle
- Created a new simple workflow, with only the "Draft" and "Published" moderation states, and it was applied to the "testbundle" type
- Created a new view based on the "Content revision", where all node revisions are listed (deleted the Published content filter)

If you create a new node in "Draft"t version, and add a new translation to this node, everything works fine, all node revisions will be listed in the testview, and you can also execute the workflow. However, if you create a new node as "Published", and add the translation to it as "Draft", the view will only list the original language node revisions, and it is because in this case adding the translation do not add a new value to the node_field_data table. If you add translation to the "Draft" version of the node, the node_field_data table will contain 2 items for the same nid (in this case it will be an English and a Hungarian one). If you add translationto the "Published" version, only the English version will be present.

Expected results: listing the node revisions of a translated node will show all revisions in all available languages (as many items as in the node_field_revision table)

Happened instead: depending on the order of publishing/translating, some revisions cannot be listed.

I will attach the config of my test-setup to this bug-report (config.zip).

πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
Content moderationΒ  β†’

Last updated 16 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΊAustralia @Sam152
Created by

πŸ‡­πŸ‡ΊHungary zolt_toth

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.

  • fathima.asmat London, UK

    Patch 6 works for new translations but does not affect existing draft translation that should be treated as default revision when there isn't a published translation. So we may need something like:

          // Check if any of the translation revision has a published version,
          // otherwise set the latest translation to default revision.
          if (!$update_default_revision && $entity instanceof TranslatableInterface && $entity instanceof RevisionableInterface) {
            $update_default_revision = $entity->isNewTranslation();
            if (!$update_default_revision) {
              $update_default_translation_revision = FALSE;
              $published_translation_revision = FALSE;
              $langcode = $this->languageManager->getCurrentLanguage()->getId();
              $storage = $this->entityTypeManager
                ->getStorage($entity->getEntityTypeId());
              $revision_ids = $storage->revisionIds($entity);
              if ($revision_ids) {
                foreach ($revision_ids as $revision_id) {
                  $revision = $storage->loadRevision($revision_id);
                  if ($revision->hasTranslation($langcode) && ($translation = $revision->getTranslation($langcode)) && $translation->isRevisionTranslationAffected()) {
                    if ($workflow->getTypePlugin()
                      ->getState($translation->moderation_state->value)
                      ->isPublishedState()) {
                      $published_translation_revision = TRUE;
                      break;
                    }
                  }
                }
              }
    
              if (!$published_translation_revision && $entity->hasTranslation($langcode) && $translation = $entity->getTranslation($langcode)) {
                $update_default_translation_revision = !($workflow->getTypePlugin()
                  ->getState($translation->moderation_state->value)
                  ->isPublishedState());
              }
    
              $update_default_revision = $update_default_translation_revision;
            }
          }
    

    Patch attached.

  • Status changed to Needs review almost 2 years ago
  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States dabblela

    Agreed with @fathima.asmat, this definitely needs a way to update the default revision of a translation that has never been published. I think it can be done with this code, but I'm a little wary of potentially looping through every revision of a node so I took a different approach.

    I was able to fix the issue here by:
    1) applying the patch from πŸ› New translations for moderated nodes are not created in the initial workflow state Needs work
    2) setting the default moderation state to "Default moderation state" and
    3) creating a new state called "Pre-published" with "Default revision" enabled

    This approach has worked better in testing with modules that use `hasTranslationChanges` (eg, paragraphs), I think because the default revision field is set earlier in the entity save process.

  • πŸ‡­πŸ‡ΊHungary mibfire

    https://www.drupal.org/project/drupal/issues/3088790#comment-14937914 πŸ› Inconsistent database because of a bug in the Content Moderation module Needs work

    This patch doesn't work in the following case:

    • Content moderation with https://www.drupal.org/files/issues/2023-02-23/content-moderation-unpubl... β†’ and moderation/translation enabled on a content type.
    • Enable Croatian language.
    • Create a Draft node in Croatian.
    • Translate this node to English(Draft).
    • Submit the Croatian translation into Published state.
    • Submit the Croatian translation into Unpublished state.
    • Check the node view page of Croatian translation where the "Latest version" tab should be visible(but it is not because the default revision is always the last revision).

    However this scenario works with https://www.drupal.org/files/issues/2020-06-09/3088790-10.patch β†’ and https://www.drupal.org/project/drupal/issues/3329066#comment-14962117 πŸ› Creating a new translation may delete translations with drafts Fixed patches. Plus this works with https://www.drupal.org/project/drupal/issues/3088790#comment-14839675 πŸ› Inconsistent database because of a bug in the Content Moderation module Needs work too.

  • πŸ‡ΊπŸ‡¦Ukraine v.dovhaliuk

    A new patch resolves an issue if Content Moderation is enabled for the Taxonomy, and $revision_ids = $storage->revisionIds($entity); throws an error undefined method <code>revisionIds()

Production build 0.71.5 2024