View source
<?php
function force_password_change_install() {
$query = db_insert('force_password_change_users')
->fields(array(
'uid',
));
$uids = db_query('SELECT uid FROM {users} WHERE uid > 0');
foreach ($uids as $uid) {
$query
->values(array(
$uid->uid,
));
}
$query
->execute();
$query2 = db_insert('force_password_change_roles')
->fields(array(
'rid',
));
$rids = db_query('SELECT rid FROM {role} WHERE rid > 1');
foreach ($rids as $rid) {
$query2
->values(array(
$rid->rid,
));
}
$query2
->execute();
db_add_field('users', 'force_password_change', array(
'type' => 'int',
'length' => 1,
'default' => 0,
), array(
'indexes' => array(
'user_force_password' => array(
'uid',
'force_password_change',
),
),
));
variable_set('force_password_change_installation_date', time());
}
function force_password_change_uninstall() {
variable_del('force_password_change_installation_date');
variable_del('force_password_change_change_password_url');
variable_del('force_password_change_login_or_init');
variable_del('force_password_change_pending_login_users');
variable_del('force_password_change_expire_password');
variable_del('force_password_change_first_login_change');
variable_del('force_password_change_first_time_uids');
db_drop_index('users', 'user_force_password');
db_drop_field('users', 'force_password_change');
}
function force_password_change_schema() {
$schema['force_password_change_users'] = array(
'description' => t('Holds password change data for users'),
'fields' => array(
'uid' => array(
'description' => t('The UID from the {users} table'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'last_password_change' => array(
'description' => t('A UNIX timestamp referring to the date that the user last changed their password'),
'type' => 'int',
'unsigned' => TRUE,
'length' => 10,
'default' => NULL,
),
'last_force' => array(
'description' => t('A UNIX timestamp referring to the last date on which the user was forced to change their password'),
'type' => 'int',
'unsigned' => TRUE,
'length' => 10,
'default' => NULL,
),
),
'primary key' => array(
'uid',
),
);
$schema['force_password_change_roles'] = array(
'description' => t('Holds the time of the last forced password change by role'),
'fields' => array(
'rid' => array(
'description' => t('The RID from the {role} table'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'last_force' => array(
'description' => t('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' => array(
'rid',
),
);
$schema['force_password_change_expiry'] = array(
'description' => t('Holds information related to the expiry of passwords by role'),
'fields' => array(
'rid' => array(
'description' => t('The RID from the {role} table'),
'type' => 'int',
'unsigned' => TRUE,
'default' => NULL,
),
'expiry' => array(
'description' => t('The number of seconds after which a user will be forced to reset their password'),
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
),
'weight' => array(
'description' => t('Allows for priorities to be applied to password expirations'),
'type' => 'int',
'default' => 0,
),
),
'primary key' => array(
'rid',
),
);
return $schema;
}
function force_password_change_schema_alter(&$schema) {
$schema['users']['fields']['force_password_change'] = array(
'type' => 'int',
'length' => 1,
'default' => 0,
);
$schema['users']['indexes']['user_force_password'] = array(
'uid',
'force_password_change',
);
}
function force_password_change_update_7000() {
$query = db_update('variable')
->fields(array(
'name' => 'force_password_change_change_password_url',
))
->condition('name', 'change_password_url')
->execute();
$query = db_update('variable')
->fields(array(
'name' => 'force_password_change_expire_password',
))
->condition('name', 'expire_password')
->execute();
$query = db_update('variable')
->fields(array(
'name' => 'force_password_change_first_login_change',
))
->condition('name', 'first_time_login_password_change')
->execute();
}