View source
<?php
function force_password_change_install() {
drupal_install_schema('force_password_change');
$query1 = 'INSERT INTO {force_password_change_users} (uid) VALUES ';
$query2 = '';
$arguments = array();
$uids = db_query('SELECT uid FROM {users} WHERE uid > 0');
while ($uid = db_fetch_array($uids)) {
if (strlen($query2)) {
$query2 .= ', ';
}
$query2 .= '(%d)';
$arguments[] = $uid['uid'];
}
db_query($query1 . $query2, $arguments);
$query1 = 'INSERT INTO {force_password_change_roles} (rid) VALUES ';
$query2 = '';
$arguments = array();
$rids = db_query('SELECT rid FROM {role} WHERE rid > 1');
while ($rid = db_fetch_array($rids)) {
if (strlen($query2)) {
$query2 .= ', ';
}
$query2 .= '(%d)';
$arguments[] = $rid['rid'];
}
db_query($query1 . $query2, $arguments);
$ret = array();
db_add_field($ret, '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());
return $ret;
}
function force_password_change_uninstall() {
variable_del('force_password_change_installation_date');
$ret = array();
db_drop_index($ret, 'users', 'user_force_password');
db_drop_field($ret, 'users', 'force_password_change');
drupal_uninstall_schema('force_password_change');
return $ret;
}
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_6200() {
variable_set('force_password_change_installation_date', time());
$ret = array();
db_create_table($ret, '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,
),
'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,
),
),
'primary_key' => array(
'uid',
),
));
db_create_table($ret, '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',
),
));
return $ret;
}
function force_password_change_update_6201() {
$query1 = 'INSERT INTO {force_password_change_users} (uid) VALUES ';
$query2 = '';
$arguments = array();
$uids = db_query('SELECT uid FROM {users} WHERE uid > 0');
while ($uid = db_fetch_array($uids)) {
if (strlen($query2)) {
$query2 .= ', ';
}
$query2 .= '(%d)';
$arguments[] = $uid['uid'];
}
db_query($query1 . $query2, $arguments);
$query1 = 'INSERT INTO {force_password_change_roles} (rid) VALUES ';
$query2 = '';
$arguments = array();
$rids = db_query('SELECT rid FROM {role} WHERE rid > 1');
while ($rid = db_fetch_array($rids)) {
if (strlen($query2)) {
$query2 .= ', ';
}
$query2 .= '(%d)';
$arguments[] = $rid['rid'];
}
db_query($query1 . $query2, $arguments);
return array();
}
function force_password_change_update_6300() {
$ret = array();
db_create_table($ret, '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 $ret;
}