You are here

public function FloodUnblockManager::flood_unblock_clear_event in Flood Unblock 8

Same name and namespace in other branches
  1. 8.2 src/FloodUnblockManager.php \Drupal\flood_unblock\FloodUnblockManager::flood_unblock_clear_event()

The function that clear the flood.

File

src/FloodUnblockManager.php, line 160

Class

FloodUnblockManager

Namespace

Drupal\flood_unblock

Code

public function flood_unblock_clear_event($type, $identifier) {
  $txn = $this->database
    ->startTransaction('flood_unblock_clear');
  try {
    $query = $this->database
      ->delete('flood')
      ->condition('event', '%' . $type, 'LIKE');
    if (isset($identifier)) {
      $query
        ->condition('identifier', $identifier);
    }
    $success = $query
      ->execute();
    if ($success) {
      \Drupal::messenger()
        ->addMessage($this
        ->t('Flood entries cleared.'), 'status', FALSE);
    }
  } catch (\Exception $e) {

    // Something went wrong somewhere, so roll back now.
    $txn
      ->rollback();

    // Log the exception to watchdog.
    watchdog_exception('type', $e);
    \Drupal::messenger()
      ->addMessage($this
      ->t('Error: @error', [
      '@error' => (string) $e,
    ]), 'error');
  }
}