function restrict_by_ip_update_6300 in Restrict Login or Role Access by IP Address 6.3
Implementation of hook_update_N().
File
- ./
restrict_by_ip.install, line 69
Code
function restrict_by_ip_update_6300() {
// Upgrade path for role settings previously stored in {restrict_by_ip} now stored in variable table.
$results = db_query("SELECT rid, restrict_by_ip_address FROM {restrict_by_ip} WHERE restrict_by_ip_type=1 AND rid IS NOT NULL");
while ($row = db_fetch_object($results)) {
variable_set('restrict_by_ip_role' . $row->rid, $row->restrict_by_ip_address);
}
// Remove old role entries in table
db_query("DELETE FROM {restrict_by_ip} WHERE uid IS NULL OR uid=0");
// Removal of all entries in {restrict_by_ip} with restrict_by_ip_type set to 0 (no longer storing inactive restrictions)
db_query("DELETE FROM {restrict_by_ip} WHERE restrict_by_ip_type=0");
// Database updates
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
// Alteration of table to remove rid and restrict_by_ip_type columns.
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP rid");
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP restrict_by_ip_type");
// Increase size of IP textfield per bug reported @ http://drupal.org/node/1121334
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} MODIFY restrict_by_ip_address varchar(256)");
// Addition of primary key
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} ADD PRIMARY KEY uid (uid) ");
// Flat this module for bootstrap in system table
$ret[] = update_sql("UPDATE {system} SET bootstrap=1 WHERE name='restrict_by_ip'");
break;
case 'pgsql':
// Alteration of table to remove rid and restrict_by_ip_type columns.
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP rid");
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP restrict_by_ip_type");
// Increase size of IP textfield per bug reported @ http://drupal.org/node/1121334
$ret = update_sql("ALTER TABLE {restrict_by_ip} ALTER COLUMN restrict_by_ip_address TYPE VARCHAR(256)");
// Addition of primary key
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} ADD PRIMARY KEY uid (uid) ");
// Flat this module for bootstrap in system table
$ret[] = update_sql("UPDATE {system} SET bootstrap=1 WHERE name='restrict_by_ip'");
break;
}
return $ret;
}