class ForcePasswordChangeMapper in Force Password Change 2.0.x
Same name and namespace in other branches
- 8 src/Mapper/ForcePasswordChangeMapper.php \Drupal\force_password_change\Mapper\ForcePasswordChangeMapper
Hierarchy
- class \Drupal\force_password_change\Mapper\ForcePasswordChangeMapper implements ForcePasswordChangeMapperInterface
Expanded class hierarchy of ForcePasswordChangeMapper
1 string reference to 'ForcePasswordChangeMapper'
File
- src/
Mapper/ ForcePasswordChangeMapper.php, line 10
Namespace
Drupal\force_password_change\MapperView source
class ForcePasswordChangeMapper implements ForcePasswordChangeMapperInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a ForcePasswordChangeMapper object.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public function getActiveUserIds() {
return $this->connection
->query('SELECT uid FROM {users_field_data} WHERE status = :one', [
':one' => 1,
])
->fetchCol();
}
/**
* {@inheritdoc}
*/
public function getUserCreatedTime($uid) {
return $this->connection
->select('users_field_data', 'ufd')
->fields('ufd', [
'created',
])
->condition('ufd.uid', $uid)
->execute()
->fetchField();
}
/**
* {@inheritdoc}
*/
public function getExpiryTimeFromRoles(array $rids) {
return $this->connection
->select('force_password_change_expiry', 'fpce')
->fields('fpce', [
'expiry',
])
->condition('fpce.rid', $rids, 'IN')
->orderBy('fpce.weight')
->range(0, 1)
->addTag('force_password_change_expiry_check')
->execute()
->fetchField();
}
/**
* {@inheritdoc}
*/
public function getLastChangeForRole($rid) {
return $this->connection
->query('SELECT last_force FROM {force_password_change_roles} WHERE rid = :rid', [
':rid' => $rid,
])
->fetchField();
}
/**
* {@inheritdoc}
*/
public function updateLastChangeForRoles(array $rids) {
$request_time = \Drupal::time()
->getRequestTime();
$this->connection
->update('force_password_change_roles')
->fields([
'last_force' => $request_time,
])
->condition('rid', $rids, 'IN')
->execute();
}
/**
* {@inheritdoc}
*/
public function insertExpiryForRoles(array $values) {
if (count($values)) {
// Prepare the insert query for new roles that
// have not had their password expiry set.
$query = $this->connection
->insert('force_password_change_expiry')
->fields([
'rid',
'expiry',
'weight',
]);
foreach ($values as $role_values) {
$query
->values($role_values);
}
$query
->execute();
}
}
/**
* {@inheritdoc}
*/
public function updateExpiryForRole($rid, $time_period, $weight) {
$this->connection
->update('force_password_change_expiry')
->fields([
'expiry' => $time_period,
'weight' => $weight,
])
->condition('rid', $rid)
->execute();
}
/**
* {@inheritdoc}
*/
public function getUserCountForRole($rid = FALSE) {
$sql = 'SELECT COUNT(ufd.uid) FROM {users_field_data} AS ufd ';
$values = [];
if ($rid) {
$sql .= 'JOIN {user__roles} AS roles ON roles.entity_id = ufd.uid AND roles.roles_target_id = :rid ';
$values[':rid'] = $rid;
}
$sql .= 'WHERE ufd.status = 1';
return $this->connection
->query($sql, $values)
->fetchField();
}
/**
* {@inheritdoc}
*/
public function getPendingUserIds($rid = FALSE) {
$query = $this->connection
->select('users_data', 'ud')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query
->join('users_field_data', 'ufd', 'ufd.uid = ud.uid AND ufd.status = :one', [
':one' => 1,
]);
$query
->addField('ud', 'uid');
$query
->addTag('force_password_change_pending_users')
->limit(20)
->condition('ud.module', 'force_password_change')
->condition('ud.name', 'pending_force')
->condition('ud.value', 1);
// If the role is anything other than the authenticated
// users role, we need to limit the users to the members of that role.
if ($rid) {
$alias = $query
->join('user__roles', 'ur', 'ur.entity_id = ud.uid');
$query
->condition($alias . '.roles_target_id', $rid);
}
return $query
->execute()
->fetchCol();
}
/**
* {@inheritdoc}
*/
public function getNonPendingUserIds($rid = FALSE) {
$query = $this->connection
->select('users', 'u')
->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender');
$query
->join('users_field_data', 'ufd', 'ufd.uid = u.uid AND ufd.status = :one', [
':one' => 1,
]);
$alias = $query
->leftJoin('users_data', 'ud', 'ud.uid = u.uid AND ud.module = :force_password_change AND ud.name = :pending_force AND ud.value = :one', [
':force_password_change' => 'force_password_change',
':pending_force' => 'pending_force',
':one' => 1,
]);
$query
->addField('u', 'uid');
$query
->addTag('force_password_change_pending_users')
->limit(100)
->condition('u.uid', 0, '!=')
->isNull('ud.uid');
if ($rid) {
$alias2 = $query
->join('user__roles', 'ur', 'ur.entity_id = ud.uid');
$query
->condition($alias2 . '.roles_target_id', $rid);
}
return $query
->execute()
->fetchCol();
}
/**
* {@inheritdoc}
*/
public function getRoleExpiryTimePeriods() {
return $this->connection
->query('SELECT rid, expiry, weight from {force_password_change_expiry} ORDER BY weight, rid')
->fetchAll();
}
/**
* {@inheritdoc}
*/
public function getUserIdsForRole($rid) {
return $this->connection
->query('SELECT entity_id FROM {user__roles} WHERE roles_target_id = :rid', [
':rid' => $rid,
])
->fetchCol();
}
/**
* {@inheritdoc}
*/
public function addFirstTimeLogin($uid) {
$this->connection
->query('INSERT INTO {force_password_change_uids} (category, uid) VALUES (:category, :uid)', [
':category' => 'first_login',
':uid' => $uid,
]);
}
/**
* {@inheritdoc}
*/
public function removeFirstTimeLogin($uid) {
$this->connection
->query('DELETE FROM {force_password_change_uids} WHERE category= :category AND uid = :uid', [
':category' => 'first_login',
':uid' => $uid,
]);
}
/**
* {@inheritdoc}
*/
public function getFirstTimeLoginUids() {
return $this->connection
->query('SELECT uid FROM {force_password_change_uids} WHERE category = :category', [
':category' => 'first_login',
])
->fetchCol();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ForcePasswordChangeMapper:: |
protected | property | The database connection. | |
ForcePasswordChangeMapper:: |
public | function |
Set a user as having been forced to change their password on their first login. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Get a list of User IDs for active user accounts. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve the highest priority expiry time from. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve a list of User IDs for users who have a pending forced
password change on their first login. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve the last timestamp at which all users in a role were
forced to change their password. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve the User IDs of all users in the given role without a pending forced password change. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve the User IDs of all users in the given role with a pending forced password change. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve the expiry time for the given roles. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve the number of users in the given role. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Get the timestamp at which a user account was created. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Retrieve the User ID for all users in a given role. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Insert time periods at which all users in the given roles will be
forced to change their password. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Remove the mark for a user who was forced to change their password on their first login. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Update the time periods at which all users in the given role will be
forced to change their password. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function |
Update the timestamp at which all users in the given roles have been
forced to change their password. Overrides ForcePasswordChangeMapperInterface:: |
|
ForcePasswordChangeMapper:: |
public | function | Constructs a ForcePasswordChangeMapper object. |