You are here

public function ModuleCommands::resetPostUpdate in Helper 8

Resets a post-update hook for a module.

@command module:post-update:reset @usage drush module:post-update:reset system extra_fields Resets the status of the system_post_update_extra_fields function so that it will run again on the next database update. @aliases mpur @validate-module

Parameters

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

string $hook: The post-update hook name.

Throws

\InvalidArgumentException

\Drush\Exceptions\UserAbortException

\RuntimeException

File

src/Commands/ModuleCommands.php, line 171

Class

ModuleCommands
Drush commands for working with module schemas.

Namespace

Drupal\helper\Commands

Code

public function resetPostUpdate($module, $hook) {
  $key_value = \Drupal::keyValue('post_update');
  $update_list = $key_value
    ->get('existing_updates');
  $post_update_hook = $module . '_post_update_' . $hook;
  if (!in_array($post_update_hook, $update_list)) {
    throw new \InvalidArgumentException(dt("There is no @hook function that has run.", [
      '@hook' => $post_update_hook,
    ]));
  }
  if (!$this
    ->io()
    ->confirm(dt('Do you want to reset the post-update hook for @hook?', [
    '@hook' => $post_update_hook,
  ]))) {
    throw new UserAbortException();
  }
  if (!$this
    ->getConfig()
    ->simulate()) {
    $update_list = array_diff($update_list, [
      $post_update_hook,
    ]);
    $key_value
      ->set('existing_updates', $update_list);
  }
  dt('Reset status of @hook so it will run on the next update.', [
    '@hook' => $post_update_hook,
  ]);
}