View source
<?php
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
function force_password_change_install() {
$connection = \Drupal::database();
$query = $connection
->insert('force_password_change_roles')
->fields([
'rid',
]);
$roles = Role::loadMultiple();
unset($roles[RoleInterface::ANONYMOUS_ID]);
$rids = array_keys($roles);
foreach ($rids as $rid) {
$query
->values([
$rid,
]);
}
$query
->execute();
\Drupal::configFactory()
->getEditable('force_password_change.settings')
->set('installation_date', REQUEST_TIME)
->save();
}
function force_password_change_schema() {
$schema['force_password_change_roles'] = [
'description' => 'Holds the time of the last forced password change by role',
'fields' => [
'rid' => [
'description' => 'The role ID from table',
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
],
'last_force' => [
'description' => 'A UNIX timestamp referring to the last date on which users in the role were forced to change their password',
'type' => 'int',
'unsigned' => TRUE,
'length' => 10,
],
],
'primary key' => [
'rid',
],
];
$schema['force_password_change_expiry'] = [
'description' => t('Holds information related to the expiry of passwords by role'),
'fields' => [
'rid' => [
'description' => 'The Role ID',
'type' => 'varchar',
'not null' => TRUE,
'length' => 128,
],
'expiry' => [
'description' => 'The number of seconds after which a user will be forced to reset their password',
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
],
'weight' => [
'description' => 'Allows for priorities to be applied to password expirations',
'type' => 'int',
'default' => 0,
],
],
'primary key' => [
'rid',
],
];
$schema['force_password_change_uids'] = [
'description' => 'Stores various lists of UIDs for the Force Password Change module',
'fields' => [
'category' => [
'description' => 'The category to which the UID belongs',
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
],
'uid' => [
'description' => 'The User ID',
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => [
'category',
'uid',
],
];
return $schema;
}
function force_password_change_update_8001() {
\Drupal::database()
->schema()
->dropTable('force_password_change_users');
}
function force_password_change_update_8002() {
\Drupal::database()
->schema()
->createTable('force_password_change_uids', [
'description' => 'Stores various lists of UIDs for the Force Password Change module',
'fields' => [
'category' => [
'description' => 'The category to which the UID belongs',
'type' => 'varchar',
'length' => 20,
'not null' => TRUE,
],
'uid' => [
'description' => 'The User ID',
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => [
'category',
'uid',
],
]);
}