You are here

public function ModuleCommands::interactSchemaVersion in Helper 8

Sets the schema version for module.

@hook interact module:schema-version:set

File

src/Commands/ModuleCommands.php, line 137

Class

ModuleCommands
Drush commands for working with module schemas.

Namespace

Drupal\helper\Commands

Code

public function interactSchemaVersion(InputInterface $input) {
  if ($input
    ->getArgument('module') && $input
    ->getArgument('version') === NULL) {
    $module = $input
      ->getArgument('module');
    $this
      ->validateModuleInstalled($module);
    $versions = $this
      ->getAvailableSchemaVersions($module);
    if (empty($versions)) {
      throw new \RuntimeException(dt('No possible schema versions for !module module.', [
        '!module' => $module,
      ]));
    }
    $current_version = $this
      ->getSchemaVersion($module);
    $this
      ->io()
      ->note(dt('The current schema version for !module module is !version.', [
      '!module' => $module,
      '!version' => $current_version,
    ]));
    $selected = $this
      ->io()
      ->choice(dt('Choose a schema version to set'), $versions);
    $input
      ->setArgument('version', $versions[$selected]);
  }
}