public function FloodUnblockManager::get_blocked_user_entries in Flood Unblock 8.2
Same name and namespace in other branches
- 8 src/FloodUnblockManager.php \Drupal\flood_unblock\FloodUnblockManager::get_blocked_user_entries()
Generate rows from the entries in the flood table.
Return value
array User blocked entries in the flood table.
File
- src/
FloodUnblockManager.php, line 107
Class
Namespace
Drupal\flood_unblockCode
public function get_blocked_user_entries() {
$entries = [];
if ($this->database
->schema()
->tableExists('flood')) {
$query = $this->database
->select('flood', 'f');
$query
->addField('f', 'identifier');
$query
->addExpression('count(*)', 'count');
$query
->condition('f.event', '%failed_login_user', 'LIKE');
$query
->groupBy('identifier');
$results = $query
->execute();
foreach ($results as $result) {
$parts = explode('-', $result->identifier);
$result->uid = $parts[0];
$result->ip = $parts[1] ?? NULL;
if (function_exists('smart_ip_get_location') && $result->ip) {
$location = smart_ip_get_location($result->ip);
$location_string = sprintf(" (%s %s %s)", $location['city'], $location['region'], $location['country_code']);
}
else {
$location_string = '';
}
$blocked = !$this->flood
->isAllowed('user.failed_login_user', $this->config
->get('user_limit'), $this->config
->get('user_window'), $result->identifier);
/** @var \Drupal\user\Entity\User $user */
$user = $this->entityTypeManager
->getStorage('user')
->load($result->uid);
if (isset($user)) {
$user_link = $user
->toLink($user
->getAccountName());
}
else {
$user_link = $this
->t('Deleted user: @user', [
'@user' => $result->uid,
]);
}
$entries[$result->identifier] = [
'type' => 'user',
'uid' => $result->uid,
'ip' => $result->ip,
'username' => $user_link,
'count' => $result->count,
'location' => $location_string,
'blocked' => $blocked,
];
}
}
return $entries;
}