signature_forum.install in Signatures for Forums 6
Same filename and directory in other branches
Installs, updates and uninstalls signature_forum module.
File
signature_forum.installView source
<?php
/**
* @file
* Installs, updates and uninstalls signature_forum module.
*/
/**
* Implementation of hook_schema().
*/
function signature_forum_schema() {
$schema['users_signature'] = array(
'fields' => array(
'uid' => array(
'description' => 'The {users}.uid this signature belongs to.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'signature' => array(
'description' => 'The signature text.',
'type' => 'text',
'not null' => FALSE,
'default' => NULL,
),
'status' => array(
'type' => 'int',
'description' => 'A boolean indicator for whether or not a signature should be displayed by default: 1 means display, 0 means not displayed.',
'size' => 'tiny',
'not null' => FALSE,
'default' => 0,
),
),
'primary key' => array(
'uid',
),
);
$schema['signature_post'] = array(
'fields' => array(
'delta' => array(
'type' => 'int',
'unsigned' => TRUE,
'description' => 'The id of the attached object. nid for nodes and cid for comments.',
'not null' => TRUE,
'disp-width' => '11',
),
'type' => array(
'description' => 'The type of comment to attach settings.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'type' => 'int',
'description' => 'A boolean indicator for whether or not a signature should be displayed: 1 means display, 0 means not displayed.',
'size' => 'tiny',
'not null' => TRUE,
'disp-width' => '11',
),
),
'primary key' => array(
'delta',
'type',
),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function signature_forum_install() {
drupal_install_schema('signature_forum');
db_query("INSERT INTO {users_signature} (uid, signature)\n SELECT uid, signature\n FROM {users}\n WHERE signature<>''");
db_query("UPDATE {users} SET signature=''");
signature_forum_build_signature_status();
}
/**
* Set all existing comments to not have a signature to avoid duplicate signatures.
*/
function signature_forum_build_signature_status() {
// Deal with nodecomments and standard nodes.
db_query("INSERT INTO {signature_post} (delta, type, status)\n SELECT nid, 'node', 1\n FROM {node}");
// Deal with standard Drupal comments.
if (module_exists('comment')) {
db_query("INSERT INTO {signature_post} (delta, type, status)\n SELECT cid, 'comment', 1\n FROM {comments}");
}
}
/**
* Implementation of hook_uninstall().
*/
function signature_forum_uninstall() {
// Copy the signatures back to Drupal core
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("UPDATE {users}, {users_signature}\n SET {users}.signature={users_signature}.signature\n WHERE {users}.uid={users_signature}.uid");
break;
case 'pgsql':
db_query("UPDATE {users} SET signature={users_signature}.signature FROM {users_signature}\n WHERE {users}.uid={users_signature}.uid");
break;
}
drupal_uninstall_schema('signature_forum');
variable_del('signature_forum_settings');
}
/**
* Implementation of hook_update_n().
*/
function signature_forum_update_6100() {
$schema['signature_post'] = array(
'fields' => array(
'delta' => array(
'type' => 'int',
'unsigned' => TRUE,
'description' => 'The id of the attached object. nid for nodes and cid for comments.',
'not null' => TRUE,
'disp-width' => '11',
),
'type' => array(
'description' => 'The type of comment to attach settings.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'type' => 'int',
'description' => 'A boolean indicator for whether or not a signature should be displayed: 1 means display, 0 means not displayed.',
'size' => 'tiny',
'not null' => TRUE,
'disp-width' => '11',
),
),
'primary key' => array(
'delta',
'type',
),
);
$ret = array();
db_add_field($ret, 'users_signature', 'status', array(
'type' => 'int',
'description' => 'A boolean indicator for whether or not a signature should be displayed by default: 1 means display, 0 means not displayed.',
'size' => 'tiny',
'not null' => FALSE,
'initial' => 1,
));
db_create_table($ret, 'signature_post', $schema['signature_post']);
signature_forum_build_signature_status();
return $ret;
}
Functions
Name | Description |
---|---|
signature_forum_build_signature_status | Set all existing comments to not have a signature to avoid duplicate signatures. |
signature_forum_install | Implementation of hook_install(). |
signature_forum_schema | Implementation of hook_schema(). |
signature_forum_uninstall | Implementation of hook_uninstall(). |
signature_forum_update_6100 | Implementation of hook_update_n(). |