function purge_users_not_loggedin_user_ids in Auto Purge Users 8
Same name and namespace in other branches
- 8.3 purge_users.module \purge_users_not_loggedin_user_ids()
- 8.2 purge_users.module \purge_users_not_loggedin_user_ids()
- 7.2 purge_users.module \purge_users_not_loggedin_user_ids()
- 7 purge_users.module \purge_users_not_loggedin_user_ids()
Get users who didn't login at all.
1 call to purge_users_not_loggedin_user_ids()
- purge_users_get_user_ids in ./
purge_users.module - Get user ids to purge.
File
- ./
purge_users.module, line 70 - Purge users module file.
Code
function purge_users_not_loggedin_user_ids($param, $user_roles = array()) {
// Get a time stamp according to the period selected.
$logindate = '';
if (!empty($param['login_value'])) {
$logindate = strtotime('-' . $param['login_value'] . ' ' . $param['login_period']);
}
// Query through db table to get users ids.
$db = \Drupal::database();
$query = $db
->select('users_field_data', 'u')
->distinct();
$query
->leftjoin('user__roles', 'ur', 'ur.entity_id = u.uid');
$query
->fields('u', array(
'uid',
));
$query
->condition('u.uid', 1, '>');
if (!empty($param['login_value'])) {
$query
->condition('u.login', $logindate, '<');
$query
->condition('u.login', 0, '!=');
}
if (in_array(AccountInterface::AUTHENTICATED_ROLE, $user_roles)) {
$db_or = new Condition('OR');
$db_or
->isNull('ur.roles_target_id');
$db_or
->condition('ur.roles_target_id', $user_roles, 'IN');
$query
->condition($db_or);
}
else {
$query
->condition('ur.roles_target_id', $user_roles, 'IN');
}
$uids = $query
->execute()
->fetchCol();
return $uids;
}