You are here

public function ModuleCommands::interactResetPostUpdate in Helper 8

Interaction hook for the module:post-update:reset command.

@hook interact module:post-update:reset

File

src/Commands/ModuleCommands.php, line 197

Class

ModuleCommands
Drush commands for working with module schemas.

Namespace

Drupal\helper\Commands

Code

public function interactResetPostUpdate(InputInterface $input) {
  if ($input
    ->getArgument('hook') === NULL) {
    $module = $input
      ->getArgument('module');
    if ($module) {
      $this
        ->validateModuleInstalled($module);
    }
    $key_value = \Drupal::keyValue('post_update');
    $update_list = $key_value
      ->get('existing_updates');
    $post_update_options = [];
    foreach ($update_list as $post_update_hook) {
      if (!$module || $module === $this
        ->getModuleFromPostUpdateHookName($post_update_hook)) {
        $post_update_options[] = $post_update_hook;
      }
    }
    if (empty($post_update_options)) {
      if ($module) {
        throw new \RuntimeException(dt('No !module_post_update functions have run yet.', [
          '!module' => $module,
        ]));
      }
      else {
        throw new \RuntimeException(dt('No hook_post_update functions have run yet.'));
      }
    }
    $selected = $this
      ->io()
      ->choice(dt('Choose a post_update hook to reset'), $post_update_options);
    if (!$module) {
      $module = $this
        ->getModuleFromPostUpdateHookName($post_update_options[$selected]);
      $input
        ->setArgument('module', $module);
    }
    $input
      ->setArgument('hook', str_replace($module . '_post_update_', '', $post_update_options[$selected]));
  }
}