shurly.install in ShURLy 6
Same filename and directory in other branches
Shurly install file
File
shurly.installView source
<?php
/**
* @file Shurly install file
*/
/**
* Implement hook_schema().
*/
function shurly_schema() {
$schema = array();
$schema['shurly'] = array(
'description' => t('URL redirects for the Shurly module'),
'fields' => array(
'rid' => array(
'description' => t('unique redirect id'),
'type' => 'serial',
'not null' => TRUE,
),
'uid' => array(
'description' => t('user id of owner'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'source' => array(
'description' => t('source path'),
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
),
'destination' => array(
'description' => t('redirect URL'),
'type' => 'text',
'not null' => TRUE,
),
'hash' => array(
'description' => t('The hash of the redirect URL'),
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
),
'created' => array(
'description' => t('datestamp of creation'),
'type' => 'int',
'not null' => TRUE,
),
'count' => array(
'description' => t('usage count'),
'type' => 'int',
'not null' => TRUE,
),
'last_used' => array(
'description' => t('datestamp of last use'),
'type' => 'int',
'not null' => TRUE,
),
'custom' => array(
'description' => t('flag for custom path'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'active' => array(
'description' => t('allows links to be deactivated'),
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
),
'primary key' => array(
'rid',
),
'indexes' => array(
'source' => array(
'source',
),
'hash' => array(
'hash',
),
),
);
$schema['shurly_flood'] = array(
'description' => t('Flood controls the threshold of events, such as the number of contact attempts.'),
'fields' => array(
'fid' => array(
'description' => t('Unique flood event ID.'),
'type' => 'serial',
'not null' => TRUE,
),
'event' => array(
'description' => t('Name of event (e.g. contact).'),
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'identifier' => array(
'description' => t('Identifier of the visitor, such as an IP address or hostname.'),
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
),
'timestamp' => array(
'description' => t('Timestamp of the event.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'expiration' => array(
'description' => t('Expiration timestamp. Expired events are purged on cron run.'),
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'fid',
),
'indexes' => array(
'allow' => array(
'event',
'identifier',
'timestamp',
),
),
);
return $schema;
}
/**
* Implement hook_install().
*/
function shurly_install() {
drupal_install_schema('shurly');
// Run manual query to make the source field case sensitive
$ret = array();
db_drop_index($ret, 'shurly', 'source');
$ret[] = update_sql("ALTER TABLE {Shurly} CHANGE `Source` `Source` VARCHAR(255) BINARY NOT NULL");
db_add_index($ret, 'shurly', 'source', array(
'source' => 'source',
));
return $ret;
}
function shurly_update_6100() {
$module = 'shurly';
$schema = drupal_get_schema_unprocessed($module);
_drupal_initialize_schema($module, $schema);
$ret = array();
db_create_table($ret, 'shurly_flood', $schema['shurly_flood']);
return $ret;
}
/**
* Convert destination field to text.
*/
function shurly_update_6101() {
$ret = array();
db_change_field($ret, 'shurly', 'destination', 'destination', array(
'description' => t('redirect URL'),
'type' => 'text',
'not null' => TRUE,
));
return $ret;
}
/**
* Make the source field case-sensitive.
*/
function shurly_update_6102() {
$ret = array();
db_drop_index($ret, 'shurly', 'source');
$ret[] = update_sql("ALTER TABLE {Shurly} CHANGE `Source` `Source` VARCHAR(255) BINARY NOT NULL");
db_add_index($ret, 'shurly', 'source', array(
'source' => 'source',
));
return $ret;
}
/**
* Add hash to destination field for indexing.
*/
function shurly_update_6103() {
db_add_field('shurly', 'hash', array(
'description' => t('The hash of the redirect URL'),
'type' => 'varchar',
'length' => '32',
'not null' => TRUE,
'default' => '',
), array(
'indexes' => array(
'hash' => array(
'hash',
),
),
));
db_query('UPDATE {shurly} SET hash = MD5(destination)');
}
/**
* Implement hook_uninstall().
*/
function shurly_uninstall() {
// Remove tables.
drupal_uninstall_schema('shurly');
// Remove variables.
variable_del('shurly_throttle');
variable_del('shurly_length');
variable_del('shurly_counter');
variable_del('shurly_index');
variable_del('shurly_base');
}
Functions
Name | Description |
---|---|
shurly_install | Implement hook_install(). |
shurly_schema | Implement hook_schema(). |
shurly_uninstall | Implement hook_uninstall(). |
shurly_update_6100 | |
shurly_update_6101 | Convert destination field to text. |
shurly_update_6102 | Make the source field case-sensitive. |
shurly_update_6103 | Add hash to destination field for indexing. |