forward.install in Forward 7
Same filename and directory in other branches
Install, update and uninstall functions for the forward module.
File
forward.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the forward module.
*
*/
/**
* @todo Please document this function.
* @see http://drupal.org/node/1354
*/
function forward_install() {
// TODO The drupal_(un)install_schema functions are called automatically in D7.;
// drupal_install_schema('forward');
variable_set('forward_theme_template', 1);
$mail_systems = variable_get('mail_system', array(
'default-system' => 'DefaultMailSystem',
));
$mail_systems['forward'] = 'ForwardMailSystem';
variable_set('mail_system', $mail_systems);
}
/**
* Implements hook_uninstall().
().
*/
function forward_uninstall() {
// TODO The drupal_(un)install_schema functions are called automatically in D7.;
// drupal_uninstall_schema('forward');
// Get global variable array
global $conf;
foreach (array_keys($conf) as $key) {
// Find variables that have the module prefix
if (strpos($key, 'forward_') === 0) {
variable_del($key);
}
}
$mail_systems = variable_get('mail_system', array(
'default-system' => 'DefaultMailSystem',
));
unset($mail_systems['forward']);
variable_set('mail_system', $mail_systems);
}
/**
* Implements hook_schema().
().
*/
function forward_schema() {
$schema['forward_log'] = array(
'fields' => array(
'path' => array(
'type' => 'varchar',
'not null' => TRUE,
'default' => '<front>',
'length' => 255,
),
'type' => array(
'type' => 'varchar',
'not null' => TRUE,
'length' => 8,
),
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'hostname' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Hostname of the user who triggered the event.',
),
),
'indexes' => array(
'forward_path' => array(
'path',
),
'forward_uid' => array(
'uid',
),
'forward_hostname' => array(
'hostname',
),
),
);
$schema['forward_statistics'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'last_forward_timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'forward_count' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'clickthrough_count' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'forward_timestamp' => array(
'last_forward_timestamp',
),
),
'primary key' => array(
'nid',
),
);
return $schema;
}
/**
* Add statistics table and populate with data from forward_log
*/
function forward_update_1() {
// initialize table
$schema['forward_statistics'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'last_forward_timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'forward_count' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'clickthrough_count' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'index' => array(
'last_forward_timestamp',
),
'primary key' => array(
'nid',
),
);
$ret = array();
db_create_table('forward_statistics', $schema['forward_statistics']);
$id = db_insert('forward_log')
->fields(array(
'nid' => 0,
'last_forward_timestamp' => 0,
'forward_count' => 0,
'clickthrough_count' => 0,
))
->execute();
// Build the SELECT query.
$query = db_select('node', 'n');
// Add the fields we want.
$query
->addField('n', 'nid');
// Perform the insert.
db_insert('mytable')
->from($query)
->execute();
// fill table
$forwards = db_query("SELECT f.nid, f.timestamp, COUNT(f.nid) as forward_count FROM {node} n LEFT JOIN {forward_log} f ON f.nid = n.nid WHERE f.type = :f.type GROUP BY f.nid, f.timestamp", array(
':f.type' => 'SENT',
));
foreach ($forwards as $forward) {
$forward_count = db_query("SELECT COUNT(nid) FROM {forward_log} WHERE nid = :nid AND type = :type", array(
':nid' => $forward->nid,
':type' => 'SENT',
))
->fetchField();
$clickthrough_count = db_query("SELECT COUNT(nid) FROM {forward_log} WHERE nid = :nid AND type = :type", array(
':nid' => $forward->nid,
':type' => 'REF',
))
->fetchField();
db_update('forward_statistics')
->fields(array(
'forward_count' => $forward_count,
'clickthrough_count' => $clickthrough_count,
'last_forward_timestamp' => $forward->timestamp,
))
->condition('nid', $forward->nid)
->execute();
}
return t('Forward statistics updated.');
}
/**
* Update variable strings
*/
function forward_update_2() {
//variable strings changed
variable_set('forward_emailsubject', str_replace(array(
'%name',
'%site',
), array(
'!name',
'!site',
), variable_get('forward_emailsubject', '!name has forwarded a page to you from !site')));
variable_set('forward_emailmessage', str_replace(array(
'%name',
'%site',
), array(
'!name',
'!site',
), variable_get('forward_emailmessage', '!name thought you would like to see this page from the !site web site.')));
variable_set('forward_postcardsubject', str_replace(array(
'%name',
'%site',
), array(
'!name',
'!site',
), variable_get('forward_postcardsubject', '!name has sent you an e-postcard from !site')));
variable_set('forward_postcardmessage', str_replace(array(
'%name',
'%site',
), array(
'!name',
'!site',
), variable_get('forward_postcardmessage', '!name has sent you an e-postcard from the !site web site. Please take a moment to visit our web site.')));
return t('Variables for Forward module updated.');
}
/**
* Changed forward_statistics to handle non-node paths
*/
function forward_update_3() {
$ret = array();
db_add_field('forward_log', 'path', array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '<front>',
));
db_add_index('forward_log', 'forward_path', array(
'path',
));
// TODO update_sql has been removed. Use the database API for any schema or data changes.
$ret[] = array();
// TODO update_sql has been removed. Use the database API for any schema or data changes.
$ret[] = array();
db_drop_index('forward_log', 'forward_nid');
db_drop_field('forward_log', 'nid');
return t('Forward statistics updated for non-node paths.');
}
/**
* Migrate variable strings
*/
function forward_update_4() {
//variable strings changed
variable_set('forward_pagesubject', variable_get('forward_emailsubject', '!name has forwarded a page to you from !site'));
variable_set('forward_pagemessage', variable_get('forward_emailmessage', '!name thought you would like to see this page from the !site web site.'));
return t('Variables for Forward module updated.');
}
/**
* Add uid and hostname to log table
*/
function forward_update_5() {
$ret = array();
db_add_field('forward_log', 'uid', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
db_add_field('forward_log', 'hostname', array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Hostname of the user who triggered the event.',
));
db_add_index('forward_log', 'forward_uid', array(
'uid',
));
db_add_index('forward_log', 'forward_hostname', array(
'hostname',
));
return t('Forward module log table updated.');
}
/**
* Set mail system for forward
*/
function forward_update_6() {
variable_set('mail_system', array(
'default-system' => 'DefaultMailSystem',
'forward' => 'ForwardMailSystem',
));
}
Functions
Name | Description |
---|---|
forward_install | @todo Please document this function. |
forward_schema | Implements hook_schema(). (). |
forward_uninstall | Implements hook_uninstall(). (). |
forward_update_1 | Add statistics table and populate with data from forward_log |
forward_update_2 | Update variable strings |
forward_update_3 | Changed forward_statistics to handle non-node paths |
forward_update_4 | Migrate variable strings |
forward_update_5 | Add uid and hostname to log table |
forward_update_6 | Set mail system for forward |