restrict_by_ip.install in Restrict Login or Role Access by IP Address 6.3
File
restrict_by_ip.install
View source
<?php
function restrict_by_ip_install() {
$ret = drupal_install_schema('restrict_by_ip');
$failed = array();
foreach ($ret as $query) {
if (!$query['success']) {
$failed[] = $query['query'];
}
}
if (empty($failed)) {
drupal_set_message(t('Restrict Logon By IP module installed successfully.'));
}
else {
drupal_set_message(t('Table installation for the Restrict Logon By IP module was unsuccessful. The following queries failed: !queries', array(
'!queries' => theme('item_list', $failed),
)), 'error');
}
}
function restrict_by_ip_schema() {
$schema['restrict_by_ip'] = array(
'description' => t('The Restrict By IP Table'),
'fields' => array(
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
),
'restrict_by_ip_address' => array(
'type' => 'varchar',
'length' => 256,
),
),
'primary key' => array(
'uid',
),
);
return $schema;
}
function restrict_by_ip_uninstall() {
drupal_uninstall_schema('restrict_by_ip');
$variables = array(
'restrict_by_ip_user_registration',
'restrict_by_ip_error_page',
'restrict_by_ip_login_range',
'restrict_by_ip_header',
);
foreach ($variables as $variable) {
variable_del($variable);
}
db_query("DELETE FROM {variable} WHERE name LIKE 'restrict_by_ip_role%'");
drupal_set_message(t('Restrict Logon By IP module uninstalled successfully.'));
}
function restrict_by_ip_update_6300() {
$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);
}
db_query("DELETE FROM {restrict_by_ip} WHERE uid IS NULL OR uid=0");
db_query("DELETE FROM {restrict_by_ip} WHERE restrict_by_ip_type=0");
$ret = array();
switch ($GLOBALS['db_type']) {
case 'mysqli':
case 'mysql':
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP rid");
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP restrict_by_ip_type");
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} MODIFY restrict_by_ip_address varchar(256)");
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} ADD PRIMARY KEY uid (uid) ");
$ret[] = update_sql("UPDATE {system} SET bootstrap=1 WHERE name='restrict_by_ip'");
break;
case 'pgsql':
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP rid");
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} DROP restrict_by_ip_type");
$ret = update_sql("ALTER TABLE {restrict_by_ip} ALTER COLUMN restrict_by_ip_address TYPE VARCHAR(256)");
$ret[] = update_sql("ALTER TABLE {restrict_by_ip} ADD PRIMARY KEY uid (uid) ");
$ret[] = update_sql("UPDATE {system} SET bootstrap=1 WHERE name='restrict_by_ip'");
break;
}
return $ret;
}