anonymous_publishing.install in Anonymous Publishing 7
Same filename and directory in other branches
Install and uninstall hooks.
File
anonymous_publishing.installView source
<?php
/**
* @file
* Install and uninstall hooks.
*/
/**
* Implements hook_schema().
*/
function anonymous_publishing_schema() {
$schema['anonymous_publishing'] = array(
'description' => 'Record of anonymous nodes (only needed for activation).',
'fields' => array(
'apid' => array(
'description' => 'primary key',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => '{node}.nid reference',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'cid' => array(
'description' => '{comment}.cid reference',
'type' => 'int',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
'akey' => array(
'description' => 'activation key',
'type' => 'char',
'length' => 60,
'not null' => FALSE,
'default' => '',
),
'verified' => array(
'description' => '0 = not verified',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'alias' => array(
'description' => 'byline/alias set by user',
'type' => 'varchar',
'length' => EMAIL_MAX_LENGTH,
'not null' => FALSE,
'default' => NULL,
),
'email' => array(
'description' => 'activation email',
'type' => 'varchar',
'length' => EMAIL_MAX_LENGTH,
'not null' => TRUE,
'default' => '',
),
'phone' => array(
'description' => 'phone number for activation link [#2646076]',
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'default' => '',
),
'ip' => array(
'description' => 'IP-address used to post contents.',
'type' => 'varchar',
'length' => 40,
'not null' => TRUE,
'default' => '',
),
),
'unique keys' => array(
'akey' => array(
'akey',
),
),
'primary key' => array(
'apid',
),
'foreign keys' => array(
'fk_node' => array(
'table' => 'node',
'columns' => array(
'nid' => 'nid',
),
),
'fk_comment' => array(
'table' => 'comment',
'columns' => array(
'cid' => 'cid',
),
),
),
);
$schema['anonymous_publishing_realname'] = array(
'description' => 'Record of real user name for nodes published asanon.',
'fields' => array(
'rnid' => array(
'description' => 'primary key',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => '{node}.nid reference',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'cid' => array(
'description' => '{comment}.cid reference',
'type' => 'int',
'unsigned' => FALSE,
'not null' => TRUE,
),
'uid' => array(
'description' => '{users}.uid reference',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array(
'rnid',
),
'foreign keys' => array(
'fk_node2' => array(
'table' => 'node',
'columns' => array(
'nid' => 'nid',
),
),
'fk_comment2' => array(
'table' => 'comment',
'columns' => array(
'cid' => 'cid',
),
),
'fk_user2' => array(
'table' => 'users',
'columns' => array(
'uid' => 'uid',
),
),
),
);
$schema['anonymous_publishing_emails'] = array(
'description' => 'For keeping track of emails used by anonymous publishers.',
'fields' => array(
'auid' => array(
'description' => 'anonymous user id',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'email' => array(
'description' => 'email used to activate',
'type' => 'varchar',
'length' => EMAIL_MAX_LENGTH,
'not null' => TRUE,
'default' => '',
),
'alias' => array(
'description' => 'Alias to be associated with this email (may be used as byline).',
'type' => 'varchar',
'length' => EMAIL_MAX_LENGTH,
'not null' => TRUE,
'default' => '',
),
'ipaddress' => array(
'description' => 'IP-address used to activate',
'type' => 'varchar',
'length' => 40,
'not null' => TRUE,
'default' => '',
),
'firstseen' => array(
'description' => 'First seen as an ISO formatted date',
'type' => 'varchar',
'mysql_type' => 'date',
'pgsql_type' => 'date',
'not null' => TRUE,
'default' => '1970-01-01',
),
'lastseen' => array(
'description' => 'Last seen as an ISO formatted date',
'type' => 'varchar',
'mysql_type' => 'date',
'pgsql_type' => 'date',
'not null' => TRUE,
'default' => '1970-01-01',
),
'blocked' => array(
'description' => '0 = in good standing; 1 = blocked',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'email' => array(
'email',
),
),
'primary key' => array(
'auid',
),
);
$schema['anonymous_publishing_bots'] = array(
'description' => 'Counts visits by bots based upon IP-address.',
'fields' => array(
'id' => array(
'description' => 'primary index',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'ip' => array(
'description' => 'IP-address of bot',
'type' => 'varchar',
'length' => 16,
'not null' => TRUE,
'default' => '',
),
'visits' => array(
'description' => 'Number of visits',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'first' => array(
'description' => 'First seen as a Unix timestamp',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'last' => array(
'description' => 'Last seen as a Unix timestamp',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'ip' => array(
'ip',
),
),
'primary key' => array(
'id',
),
);
return $schema;
}
/**
* Implements hook_requirements().
*/
function anonymous_publishing_requirements($phase) {
$requirements = array();
$t = get_t();
if ($phase == 'runtime') {
$stats = variable_get('anonymous_publishing_cl_stats', NULL);
$value = $stats ? $t('Blocked !smart smart and !stupid stupid spambots since !start.', array(
'!smart' => $stats['smart'],
'!stupid' => $stats['stupid'],
'!start' => format_date($stats['start'], 'short'),
)) : $t('No spambot statistics collected.');
$requirements['anonymous_publishing_cl_stats'] = array(
'title' => $t('Anonymous Publishing'),
'value' => $value,
'severity' => REQUIREMENT_INFO,
);
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function anonymous_publishing_uninstall() {
// Delete my variables.
variable_del('anonymous_publishing_cl_alias');
variable_del('anonymous_publishing_cl_autodelhours');
variable_del('anonymous_publishing_cl_bylineguide');
variable_del('anonymous_publishing_cl_emailaction');
variable_del('anonymous_publishing_cl_emailactivate');
variable_del('anonymous_publishing_cl_emailnbody');
variable_del('anonymous_publishing_cl_emailnsubject');
variable_del('anonymous_publishing_cl_emailsubjectact');
variable_del('anonymous_publishing_cl_emailsubjectver');
variable_del('anonymous_publishing_cl_emailverify');
variable_del('anonymous_publishing_cl_emailweight');
variable_del('anonymous_publishing_cl_flood');
variable_del('anonymous_publishing_cl_moderator');
variable_del('anonymous_publishing_cl_options');
variable_del('anonymous_publishing_cl_period');
variable_del('anonymous_publishing_cl_requiredchar');
variable_del('anonymous_publishing_cl_stats');
variable_del('anonymous_publishing_cl_stats_enable');
variable_del('anonymous_publishing_cl_types');
variable_del('anonymous_publishing_cl_vrfypers');
variable_del('anonymous_publishing_pet_options');
variable_del('anonymous_publishing_pet_period');
variable_del('anonymous_publishing_pet_types');
}
/* Updates. */
/**
* Add table {anonymous_publishing_bots}.
*/
function anonymous_publishing_update_7001() {
$schema['anonymous_publishing_bots'] = array(
'description' => 'Counts visits by bots based upon IP-address.',
'fields' => array(
'id' => array(
'description' => 'primary index',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'ip' => array(
'description' => 'IP-address of bot',
'type' => 'varchar',
'length' => 16,
'not null' => TRUE,
'default' => '',
),
'visits' => array(
'description' => 'Number of visits',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'first' => array(
'description' => 'First seen as a Unix timestamp',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'last' => array(
'description' => 'Last seen as a Unix timestamp',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'unique keys' => array(
'ip' => array(
'ip',
),
),
'primary key' => array(
'id',
),
);
db_create_table('anonymous_publishing_bots', $schema['anonymous_publishing_bots']);
}
/**
* Changes to schemas.
*
* Add field 'apid' to {anonymous_publishing} and make it primary.
* Add field 'cid' to {anonymous_publishing}.
* Add field 'rnid' to {anonymous_publishing_realname} and make it primary.
* Add field 'cid' to {anonymous_publishing_realname}.
* Change {anonymous_publishing_emails}.firstseen to type 'date'.
*/
function anonymous_publishing_update_7002() {
$serial = array(
'description' => 'primary key',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
);
$nid = array(
'description' => '{node}.nid reference',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
$cid = array(
'description' => '{comment}.cid reference',
'type' => 'int',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
);
$firstseen = array(
'description' => 'First seen as an ISO formatted date',
'type' => 'varchar',
'mysql_type' => 'date',
'pgsql_type' => 'date',
'not null' => TRUE,
'default' => '1970-01-01',
);
db_change_field('anonymous_publishing', 'nid', 'nid', $nid);
db_drop_primary_key('anonymous_publishing');
db_add_field('anonymous_publishing', 'apid', $serial, array(
'primary key' => array(
'apid',
),
));
db_add_field('anonymous_publishing', 'cid', $cid);
db_change_field('anonymous_publishing_realname', 'nid', 'nid', $nid);
db_drop_primary_key('anonymous_publishing_realname');
db_add_field('anonymous_publishing_realname', 'rnid', $serial, array(
'primary key' => array(
'rnid',
),
));
db_add_field('anonymous_publishing_realname', 'cid', $cid);
db_change_field('anonymous_publishing_emails', 'firstseen', 'firstseen', $firstseen);
}
/**
* Add field 'ip' to {anonymous_publishing}.
*/
function anonymous_publishing_update_7003() {
$ip = array(
'description' => 'IP-address used to post contents.',
'type' => 'varchar',
'length' => 16,
'not null' => TRUE,
'default' => '',
);
db_add_field('anonymous_publishing', 'ip', $ip);
$options = variable_get('anonymous_publishing_options', array(
'sactivate' => 'sactivate',
'sactstick' => 'sactstick',
'modmail' => 0,
'blockip' => 0,
'aregist' => 0,
));
$types = variable_get('anonymous_publishing_types', array());
$period = variable_get('anonymous_publishing_period', -1);
variable_set('anonymous_publishing_cl_options', $options);
variable_set('anonymous_publishing_cl_types', $types);
variable_set('anonymous_publishing_cl_period', $period);
variable_del('anonymous_publishing_options');
variable_del('anonymous_publishing_types');
variable_del('anonymous_publishing_period');
}
/**
* Add field 'uid' to {anonymous_publishing_realname}.
*/
function anonymous_publishing_update_7004() {
$uid = array(
'description' => '{users}.uid reference',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
db_add_field('anonymous_publishing_realname', 'uid', $uid);
$rows = db_query("SELECT rnid, realname FROM {anonymous_publishing_realname}")
->fetchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
$user = user_load_by_name($row['realname']);
$uid = $user->uid;
db_update('anonymous_publishing_realname')
->fields(array(
'uid' => $uid,
))
->condition('rnid', $row['rnid'])
->execute();
}
db_drop_field('anonymous_publishing_realname', 'realname');
}
/**
* Allocate 40 chars to 'ip' {anonymous_publishing} for IPv6.
*/
function anonymous_publishing_update_7005() {
$ip = array(
'description' => 'IP-address used to post contents.',
'type' => 'varchar',
'length' => 40,
'not null' => TRUE,
'default' => '',
);
db_change_field('anonymous_publishing', 'ip', 'ip', $ip);
}
/**
* Add foreign key constraints.
*/
function anonymous_publishing_update_7006() {
$cid = array(
'description' => '{comment}.cid reference',
'type' => 'int',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
);
db_change_field('anonymous_publishing', 'cid', 'cid', $cid);
db_change_field('anonymous_publishing_realname', 'cid', 'cid', $cid);
}
/**
* Add two fields.
*/
function anonymous_publishing_update_7007() {
$alias = array(
'description' => 'byline/alias set by user',
'type' => 'varchar',
'length' => EMAIL_MAX_LENGTH,
'not null' => TRUE,
'default' => '',
);
$phone = array(
'description' => 'phone number for activation link [issue #2646076]',
'type' => 'varchar',
'length' => 15,
'not null' => TRUE,
'default' => '',
);
db_add_field('anonymous_publishing', 'alias', $alias);
db_add_field('anonymous_publishing', 'phone', $phone);
}
/**
* Make the alias field (added in 7007) accept NULL.
*/
function anonymous_publishing_update_7008() {
$alias = array(
'description' => 'byline/alias set by user',
'type' => 'varchar',
'length' => EMAIL_MAX_LENGTH,
'not null' => FALSE,
'default' => NULL,
);
db_change_field('anonymous_publishing', 'alias', 'alias', $alias);
}
/**
* Convert unlimited flood & autodelhoursd from 99/999 to -1 magic value.
*/
function anonymous_publishing_update_7009() {
$flood = variable_get('anonymous_publishing_flood', 99);
if ($flood == 99) {
variable_set('anonymous_publishing_flood', -1);
}
$adh = variable_get('anonymous_publishing_autodelhours', 999);
if ($adh == 999) {
variable_set('anonymous_publishing_autodelhours', -1);
}
}
/**
* Helper function for anonymous_publishing_update_7010.
*/
function _anonymous_publishing_fixvn($vid) {
$value = variable_get('anonymous_publishing_' . $vid, FALSE);
if ($value) {
variable_set('anonymous_publishing_cl_' . autodelhours, $value);
}
variable_del('anonymous_publishing_' . $vid);
}
/**
* Fix variables name to please DrupalPractice.
*/
function anonymous_publishing_update_7010() {
_anonymous_publishing_fixvn('autodelhours');
_anonymous_publishing_fixvn('bylineguide');
_anonymous_publishing_fixvn('flood');
_anonymous_publishing_fixvn('moderator');
_anonymous_publishing_fixvn('emailaction');
_anonymous_publishing_fixvn('emailactivate');
_anonymous_publishing_fixvn('emailnbody');
_anonymous_publishing_fixvn('emailnsubject');
_anonymous_publishing_fixvn('emailsubjectact');
_anonymous_publishing_fixvn('emailsubjectver');
_anonymous_publishing_fixvn('emailverify');
_anonymous_publishing_fixvn('emailweight');
}
Functions
Name | Description |
---|---|
anonymous_publishing_requirements | Implements hook_requirements(). |
anonymous_publishing_schema | Implements hook_schema(). |
anonymous_publishing_uninstall | Implements hook_uninstall(). |
anonymous_publishing_update_7001 | Add table {anonymous_publishing_bots}. |
anonymous_publishing_update_7002 | Changes to schemas. |
anonymous_publishing_update_7003 | Add field 'ip' to {anonymous_publishing}. |
anonymous_publishing_update_7004 | Add field 'uid' to {anonymous_publishing_realname}. |
anonymous_publishing_update_7005 | Allocate 40 chars to 'ip' {anonymous_publishing} for IPv6. |
anonymous_publishing_update_7006 | Add foreign key constraints. |
anonymous_publishing_update_7007 | Add two fields. |
anonymous_publishing_update_7008 | Make the alias field (added in 7007) accept NULL. |
anonymous_publishing_update_7009 | Convert unlimited flood & autodelhoursd from 99/999 to -1 magic value. |
anonymous_publishing_update_7010 | Fix variables name to please DrupalPractice. |
_anonymous_publishing_fixvn | Helper function for anonymous_publishing_update_7010. |