You are here

public function Wbm2cmCommands::migrate in Workbench Moderation to Content Moderation 8.2

Migrates from Workbench Moderation to Content Moderation.

@command wbm2cm:migrate @aliases wbm2cm-migrate

File

src/Commands/Wbm2cmCommands.php, line 44

Class

Wbm2cmCommands

Namespace

Drupal\wbm2cm\Commands

Code

public function migrate() {
  $out = $this
    ->output();
  $this
    ->save();
  $this
    ->clear(FALSE);
  $fields = $this->controller
    ->getOverriddenFields();
  if ($fields) {
    $out
      ->writeln('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());
      $out
        ->writeln($message);
    }
  }
  $out
    ->writeln('Installing Content Moderation...');

  // Module installation or uninstallation modifies the container, and
  // potentially every service in it. We do not want to be holding on to
  // outdated services and their implict dependency trees.
  $this->moduleInstaller
    ->uninstall([
    'workbench_moderation',
  ]);
  if (\Drupal::hasContainer()) {
    $this->controller = $this
      ->reloadService($this->controller);
    $this->moduleInstaller = $this
      ->reloadService($this->moduleInstaller);
  }
  $this->moduleInstaller
    ->install([
    'content_moderation',
  ]);
  $this
    ->restore();
  $out
    ->writeln('Yay! You have been migrated to Content Moderation.');
}