| 1 |
<?php
|
| 2 |
// $Id: forward.install,v 1.6 2009/04/21 22:34:45 seanr Exp $
|
| 3 |
function forward_install() {
|
| 4 |
drupal_install_schema('forward');
|
| 5 |
variable_set('forward_theme_template', 1);
|
| 6 |
}
|
| 7 |
|
| 8 |
function forward_uninstall() {
|
| 9 |
drupal_uninstall_schema('forward');
|
| 10 |
}
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_schema().
|
| 14 |
*/
|
| 15 |
function forward_schema() {
|
| 16 |
$schema['forward_log'] = array(
|
| 17 |
'fields' => array(
|
| 18 |
'path' => array('type' => 'varchar', 'not null' => TRUE, 'default' => '<front>', 'length' => 255),
|
| 19 |
'type' => array('type' => 'varchar', 'not null' => TRUE, 'length' => 8),
|
| 20 |
'timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0)
|
| 21 |
),
|
| 22 |
'indexes' => array(
|
| 23 |
'forward_path' => array('path')
|
| 24 |
),
|
| 25 |
);
|
| 26 |
$schema['forward_statistics'] = array(
|
| 27 |
'fields' => array(
|
| 28 |
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 29 |
'last_forward_timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
| 30 |
'forward_count' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 31 |
'clickthrough_count' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 32 |
),
|
| 33 |
'indexes' => array(
|
| 34 |
'forward_timestamp' => array('last_forward_timestamp')
|
| 35 |
),
|
| 36 |
'primary key' => array('nid'),
|
| 37 |
);
|
| 38 |
return $schema;
|
| 39 |
}
|
| 40 |
|
| 41 |
/**
|
| 42 |
* Changed node_comment_statistics to use node->changed to avoid future
|
| 43 |
* timestamps.
|
| 44 |
*/
|
| 45 |
function forward_update_1() {
|
| 46 |
// initialize table
|
| 47 |
$schema['forward_statistics'] = array(
|
| 48 |
'fields' => array(
|
| 49 |
'nid' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 50 |
'last_forward_timestamp' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
|
| 51 |
'forward_count' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 52 |
'clickthrough_count' => array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
|
| 53 |
),
|
| 54 |
'index' => array('last_forward_timestamp'),
|
| 55 |
'primary key' => array('nid'),
|
| 56 |
);
|
| 57 |
$ret = array();
|
| 58 |
db_create_table($ret, 'forward_statistics', $schema['forward_statistics']);
|
| 59 |
db_query("INSERT INTO {forward_statistics} (nid, last_forward_timestamp, forward_count, clickthrough_count) values(0, 0, 0, 0)");
|
| 60 |
db_query("INSERT INTO {forward_statistics} (nid, last_forward_timestamp, forward_count, clickthrough_count) SELECT n.nid, 0, 0, 0 FROM {node} n");
|
| 61 |
|
| 62 |
// fill table
|
| 63 |
$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 = 'SENT' GROUP BY f.nid, f.timestamp");
|
| 64 |
while ($forward = db_fetch_object($forwards)) {
|
| 65 |
$forward_count = db_result(db_query("SELECT COUNT(nid) FROM {forward_log} WHERE nid = %d AND type = '%s'", $forward->nid, 'SENT'));
|
| 66 |
$clickthrough_count = db_result(db_query("SELECT COUNT(nid) FROM {forward_log} WHERE nid = %d AND type = '%s'", $forward->nid, 'REF'));
|
| 67 |
db_query("UPDATE {forward_statistics} SET forward_count = %d, clickthrough_count = %d, last_forward_timestamp = %d WHERE nid = %d", $forward_count, $clickthrough_count, $forward->timestamp, $forward->nid);
|
| 68 |
}
|
| 69 |
return $ret;
|
| 70 |
}
|
| 71 |
|
| 72 |
/**
|
| 73 |
* Changed node_comment_statistics to use node->changed to avoid future
|
| 74 |
* timestamps.
|
| 75 |
*/
|
| 76 |
function forward_update_2() {
|
| 77 |
//variable strings changed
|
| 78 |
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')));
|
| 79 |
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.')));
|
| 80 |
|
| 81 |
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')));
|
| 82 |
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.')));
|
| 83 |
|
| 84 |
return array();
|
| 85 |
}
|
| 86 |
|
| 87 |
/**
|
| 88 |
* Changed forward_statistics to handle non-node paths
|
| 89 |
*/
|
| 90 |
function forward_update_3() {
|
| 91 |
$ret = array();
|
| 92 |
db_add_field($ret, 'forward_log', 'path', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '<front>'));
|
| 93 |
db_add_index($ret, 'forward_log', 'forward_path', array('path'));
|
| 94 |
$ret[] = update_sql("UPDATE {forward_log} SET path = CONCAT('node/',nid) WHERE nid != 0");
|
| 95 |
$ret[] = update_sql("UPDATE {forward_log} SET path = '<front>' WHERE nid = 0");
|
| 96 |
db_drop_index($ret, 'forward_log', 'forward_nid');
|
| 97 |
db_drop_field($ret, 'forward_log', 'nid');
|
| 98 |
|
| 99 |
return $ret;
|
| 100 |
}
|