You are here

public function ModuleCommands::deleteSchemaVersion in Helper 8

Deletes the schema version for a module.

This is useful for removing leftover schemas of deleted modules.

@command module:schema-version:delete @aliases msvd @validate-module @usage drush module:schema-version:delete system Deletes the system module schema version.

Parameters

string $module: The module name, for example "system".

1 call to ModuleCommands::deleteSchemaVersion()
ModuleCommands::cleanupSchemaVersion in src/Commands/ModuleCommands.php
Cleans up the schema versions for deleted modules.

File

src/Commands/ModuleCommands.php, line 255

Class

ModuleCommands
Drush commands for working with module schemas.

Namespace

Drupal\helper\Commands

Code

public function deleteSchemaVersion($module) {
  module_load_install($module);
  $args = [
    '!module' => $module,
  ];
  if ($this->moduleHandler
    ->moduleExists($module)) {
    $this
      ->io()
      ->caution(dt('You should uninstall the !module module instead of deleting its schema.', $args));
  }
  if (!$this
    ->io()
    ->confirm(dt('Do you want to delete the schema for !module module?', $args))) {
    throw new UserAbortException();
  }
  if (!$this
    ->getConfig()
    ->simulate()) {
    \Drupal::keyValue('system.schema')
      ->delete($module);
    if (drupal_get_installed_schema_version($module, TRUE) !== SCHEMA_UNINSTALLED) {
      throw new \RuntimeException(dt('Unable to delete schema for !module module.', $args));
    }
  }
  return dt('Deleted schema for !module module.', $args);
}