When I want to deinstall worbench modul I see following message on deinstall page at modul information and so i am unable to check deinstall checkbox:

There is data for the field moderation_state on entity type Content

This is also if I disable workbench moderation on every content type I uses workbench moderation.

Only removing every content i created using the modul helped. This is not really usefull despite I can disable workbench moderation ...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MartinMa created an issue. See original summary.

ArtuDrop’s picture

Neither can I.

timmillwood’s picture

Status: Active » Closed (won't fix)

Sorry, this will never be fixed in the contrib module.

Content Moderation in core has fixed this issue.

ArtuDrop’s picture

Tim, please explain how to fix it (uninstall the module) though anyway.

timmillwood’s picture

Version: 8.x-1.1 » 8.x-1.x-dev

I've not tried, but I expect if you delete all your content you should be able to uninstall it.

MartinMa’s picture

I just have this problem too. Removing all content is not an solution for an existing site. Could be the deploy module a solution to put the content to a clean new installation?

captaindav’s picture

I have this issue too, I would think many others as well will face this as they upgrade to the newer versions of Drupal Core that has Content Moderation. As a work-around, is it possible to install the Drupal Core Content Moderation module and leave Workbench Moderation installed as well?

timmillwood’s picture

This is fixed in 8.5.x

See https://www.drupal.org/node/2907785

captaindav’s picture

I have a Lightning based site on 8.4 site going live next week that has workbench installed. Any idea of a work-around to use the Core Workflow/CM modules until 8.5 is released?

diamondsea’s picture

If you are still pre-8.5+ you can use a script like this to remove data so you can uninstall the module.

You might need to add or remove a few lines depending on the modules you have installed.

#!/usr/bin/env bash
echo 'Altering moderation state fields to NULL and adding necessary tables'

# update nodes
drush sqlq 'UPDATE node_field_revision set moderation_state = null where moderation_state is not NULL'
drush sqlq 'UPDATE node_field_data set moderation_state = null where moderation_state is not NULL'

# update block content
drush sqlq 'UPDATE block_content_field_revision set moderation_state = null where moderation_state is not NULL'
drush sqlq 'UPDATE block_content_field_data set moderation_state = null where moderation_state is not NULL'

# if you have paragraphs installed
drush sqlq 'UPDATE paragraphs_item_field_data set moderation_state = null where moderation_state is not NULL'
drush sqlq 'UPDATE paragraphs_item_revision_field_data set moderation_state = null where moderation_state is not NULL'

# if you have image crop installed
drush sqlq 'UPDATE crop_field_revision set moderation_state = null where moderation_state is not NULL'
drush sqlq 'UPDATE crop_field_data set moderation_state = null where moderation_state is not NULL'

# if content moderation is installed
drush sqlq 'UPDATE content_moderation_state_field_revision set moderation_state = null where moderation_state is not NULL'
drush sqlq 'UPDATE content_moderation_state_field_data set moderation_state = null where moderation_state is not NULL'
drush sqlq 'ALTER TABLE content_moderation_state_field_data ADD revision_translation_affected TINYINT'
drush sqlq 'ALTER TABLE content_moderation_state_field_revision ADD revision_translation_affected TINYINT'

echo 'Finished altering all tables'
echo 'Disabling Workbench Moderation module'
drush pmu -y workbench_moderation
jigarius’s picture

Since many people will want to uninstall this module, it will be great if someone could create a drush command and put it in the module itself? Or maybe implement a hook in the workbench_moderation module to help ease the process? I'll give it a try if I have time.

jigarius’s picture

Title: Cant't deinstall Workbench Modul » Cannot uninstall workbench moderation module
jigarius’s picture

I see that it's been marked as won't fix. Sorry to reopen this issue, but I came up with a patch for this which might be worth taking a look at? I've implemented a hook_uninstall() which clears the moderation_state field, resulting in a clean uninstall of the workbench_moderation module.

Although a kind-of-a-solution has been provided in comment 5, but it is not very practical to delete the entire site's content to be able to uninstall a module. Hence, it will be good to include this patch cause most people will want to uninstall this module and run into this problem.

If you're planning to use this patch, make sure you test it on a dev env. All you have to do is apply the patch and then run drush pmu -y.

jigarius’s picture

Status: Closed (won't fix) » Needs review

Forgot to mark as "needs review". Please see comment 13.

jigarius’s picture

sharif.elshobkshy’s picture

Solved by adding a hook_update that adds the missing fields/columns.

After running the update, I'm able to disable the "Workbench Moderation".

hook_update:

use Drupal\Core\Database\Database;
/**
 * Add missing fields that allows Workbench Moderation to be uninstalled.
 */
function myModule_update_8023() {
  $schema = Database::getConnection()->schema();
  $definition = [
    'type' => 'varchar',
    'length' => 45,
  ];
  $tables = [
    'taxonomy_term_field_data',
    'block_content_field_data',
    'crop_field_data',
    'media_field_data',
    'node_field_data',
    'paragraphs_item_field_data',
  ];
  foreach ($tables as $table) {
    if (!$schema->fieldExists($table, 'moderation_state')) {
      $schema->addField($table, 'moderation_state', $definition);
    }
  }
}

Note: The above tables were blocking me when trying to disable the module. It could happen that you need to add less/more tables in your code.

Hope this helps.
Regards.

yuehua’s picture

Thanks for the suggestion on the #16. I rebuild the patch based on this suggestion.

kiwad’s picture

What a good timing for that patch :)

Taking over a project from which we want to remove workbench

Applied patch and got : workbench_moderation was successfully uninstalled.

jacobbell84’s picture

Thanks for this! This saved me a bunch of time. I added two additional tables the original patch wasn't accounting for (menu_link_content_data which is added by the Menu Item Extras module and paragraphs_library_item_field_data which is added by the Paragraph Library module).