function ip_login_update_6200 in IP Login 6.2
Drupal 6.x-1x to 2x (Profile field -> IP Login User table) update.
File
- ./
ip_login.install, line 68 - Install file of the IP Login module.
Code
function ip_login_update_6200() {
// this update function needs it's own copy of the schema! http://drupal.org/node/150220
$schema['ip_login_user'] = array(
'description' => t('Stores the IP Login address and range matches for users'),
'fields' => array(
'uid' => array(
'description' => t('ID of user for IP Login'),
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'ip_match' => array(
'description' => t('IP ranges and addresses'),
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
),
);
// add table
$ret = array();
db_create_table($ret, 'ip_login_user', $schema['ip_login_user']);
db_add_index($ret, 'ip_login_user', 'uid', array(
'uid',
));
// import old profile values into new ip_login_user table
$profile_ranges = db_query("SELECT pv.uid, pv.value FROM {profile_values} pv\n INNER JOIN {profile_fields} pf ON pv.fid = pf.fid\n WHERE pf.name = '%s' AND pv.value", variable_get('ip_login_profile_ip_field', 'profile_ip'));
while ($row = db_fetch_object($profile_ranges)) {
_ip_login_set_user_range($row->uid, $row->value);
}
// tell user
$ret[] = array(
'success' => TRUE,
'query' => t('Imported the user IP ranges from Profile field %fieldname. You may remove this field - and also disable the Profile module IF you are not using it for anything else.', array(
'%fieldname' => variable_get('ip_login_profile_ip_field', 'profile_ip'),
)),
);
// remove old IP login 6.x-1.x variables not needed, done
variable_del('ip_login_profile_ip_field');
return $ret;
}