- 🇦🇺Australia b.ravanbakhsh Adelaide
In my case also like comment #3 Web-Beest we had some lingering configuration that added workbench_moderation as third-party settings in DB. so I create a code snippet to drop those fields and let the workbench moderation module uninstalled. also in some cases the uninstall was blocked by the field that was missing, ao this snippet adds the missing too.
$table_names = _add_missing_moderation_state_column(); foreach ($table_names as $table_name) { $schema->dropField($table_name, 'moderation_state'); } ** * Add moderation_state to database entity tables. * * Some tables in database like linky, block_field_data, .. don't have the * moderation_state field, and it makes the uninstallation of * workbench moderation module fails. This function adds the field to tables. */ function _add_missing_moderation_state_column() { /** @var \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager */ $entity_field_manager = \Drupal::service('entity_field.manager'); $entity_type_manager = \Drupal::entityTypeManager(); $schema = \Drupal::database()->schema(); $moderationStateColumnSpec = [ 'type' => 'varchar', 'description' => 'workbench migration', 'length' => 255, 'not null' => FALSE, ]; $table_names = []; foreach ($entity_type_manager->getDefinitions() as $entity_type) { if ($entity_type->entityClassImplements(FieldableEntityInterface::CLASS)) { foreach ($entity_field_manager->getFieldStorageDefinitions($entity_type->id()) as $storage_definition) { if ($storage_definition->getProvider() == 'workbench_moderation') { $table_name = $entity_type->getDataTable() ?? $entity_type->getProvider(); if ($table_name && $schema->fieldExists($table_name, 'moderation_state') === FALSE) { $schema->addField($table_name, 'moderation_state', $moderationStateColumnSpec); $table_names[] = $table_name; } } } } } return $table_names; }
- 🇦🇺Australia b.ravanbakhsh Adelaide
reply to #4 @karenann comment to where put these codes and the sequence. I have a hook_post_update and run the migration like this sequence.
function ua_post_update_wbm2cm_migrate() { $module_installer = \Drupal::service('module_installer'); $module_installer->install(['wbm2cm']); _ua_wbm2cm_save(); // Clear work bench moderation can be skipped, as drupal uninstall workbench moderation will do the job. // _ua_wbm2cm_clear(FALSE); $fields = \Drupal::service('wbm2cm.migration_controller')->getOverriddenFields(); if ($fields) { \Drupal::logger('ua')->info('It looks like you have overridden the moderation_state base field. These overrides will be reverted because they are incompatible with Content Moderation. You will also need to delete these from your exported config.'); /** @var \Drupal\Core\Field\Entity\BaseFieldOverride $field */ foreach ($fields as $field) { $field->delete(); $message = sprintf('Reverted %s. Delete %s.yml from your exported config.', $field->id(), $field->getConfigDependencyName()); _ua_logger($message); \Drupal::logger('ua')->info($message); } } $table_names = _add_missing_moderation_state_column(); \Drupal::logger('ua')->info('Uninstalling Workbench Moderation...'); $module_installer->uninstall(['workbench_moderation']); foreach ($table_names as $table_name) { $schema->dropField($table_name, 'moderation_state'); } $module_installer->install(['workflows']); $splitFile = 'workflows.workflow.editorial'; $config_path = realpath('../config-export'); $source = new FileStorage($config_path); $config_storage->write($splitFile, $source->read($splitFile)); \Drupal::logger('ua')->info('Installing Content Moderation...'); $module_installer->install(['content_moderation']); _ua_wbm2cm_restore(); $module_installer->uninstall(['wbm2cm']); }