| 1 |
<?php
|
| 2 |
// $Id: trackback.install,v 1.7 2007/11/05 19:14:24 zorac Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*/
|
| 7 |
function trackback_install() {
|
| 8 |
// Create tables.
|
| 9 |
drupal_install_schema('trackback');
|
| 10 |
}
|
| 11 |
|
| 12 |
/**
|
| 13 |
* Implementation of hook_uninstall().
|
| 14 |
*/
|
| 15 |
function trackback_uninstall() {
|
| 16 |
// Remove tables.
|
| 17 |
drupal_uninstall_schema('trackback');
|
| 18 |
if (module_exists('spam')) {
|
| 19 |
db_query("DELETE FROM {spam_tracker} WHERE source='trackback'");
|
| 20 |
}
|
| 21 |
variable_del('trackback_moderation');
|
| 22 |
variable_del('trackback_auto_detection_enabled');
|
| 23 |
variable_del('trackback_display_number');
|
| 24 |
variable_del('trackback_spam_filter');
|
| 25 |
variable_del('trackback_reject_oneway');
|
| 26 |
variable_del('trackback_link_only');
|
| 27 |
variable_del('trackback_view');
|
| 28 |
foreach (array_keys(node_get_types()) as $type) {
|
| 29 |
variable_del('trackback_'. $type);
|
| 30 |
}
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Implementation of hook_schema().
|
| 35 |
*/
|
| 36 |
function trackback_schema() {
|
| 37 |
$schema['trackback_received'] = array(
|
| 38 |
'description' => t('Stores the received trackbacks.'),
|
| 39 |
'fields' => array(
|
| 40 |
'trid' => array(
|
| 41 |
'type' => 'serial',
|
| 42 |
'unsigned' => TRUE,
|
| 43 |
'not null' => TRUE,
|
| 44 |
'description' => t('Primary Key: Unique trackback ID.')
|
| 45 |
),
|
| 46 |
'nid' => array(
|
| 47 |
'type' => 'int',
|
| 48 |
'unsigned' => TRUE,
|
| 49 |
'not null' => TRUE,
|
| 50 |
'description' => t('The {node}.nid by which this trackback was received.')
|
| 51 |
),
|
| 52 |
'created' => array(
|
| 53 |
'type' => 'int',
|
| 54 |
'not null' => TRUE,
|
| 55 |
'description' => t('The Unix timestamp when this trackback was received.')
|
| 56 |
),
|
| 57 |
'site' => array(
|
| 58 |
'type' => 'varchar',
|
| 59 |
'length' => 255,
|
| 60 |
'not null' => TRUE,
|
| 61 |
'description' => t('The IP address that sent this trackback.')
|
| 62 |
),
|
| 63 |
'name' => array(
|
| 64 |
'type' => 'varchar',
|
| 65 |
'length' => 60,
|
| 66 |
'not null' => TRUE,
|
| 67 |
'description' => t('The sender site name of this trackback.')
|
| 68 |
),
|
| 69 |
'subject' => array(
|
| 70 |
'type' => 'varchar',
|
| 71 |
'length' => 64,
|
| 72 |
'not null' => TRUE,
|
| 73 |
'description' => t('The title of the trackbacking post.')
|
| 74 |
),
|
| 75 |
'url' => array(
|
| 76 |
'type' => 'varchar',
|
| 77 |
'length' => 255,
|
| 78 |
'not null' => TRUE,
|
| 79 |
'description' => t('The URL of the trackbacking post.')
|
| 80 |
),
|
| 81 |
'excerpt' => array(
|
| 82 |
'type' => 'varchar',
|
| 83 |
'length' => 255,
|
| 84 |
'not null' => TRUE,
|
| 85 |
'description' => t('The excerpt of the trackbacking post.')
|
| 86 |
),
|
| 87 |
'status' => array(
|
| 88 |
'type' => 'int',
|
| 89 |
'unsigned' => TRUE,
|
| 90 |
'default' => 0,
|
| 91 |
'size' => 'tiny',
|
| 92 |
'description' => t('Boolean indicating whether the trackback is published.')
|
| 93 |
)
|
| 94 |
),
|
| 95 |
'indexes' => array('nid' => array('nid')),
|
| 96 |
'primary key' => array('trid')
|
| 97 |
);
|
| 98 |
|
| 99 |
$schema['trackback_sent'] = array(
|
| 100 |
'description' => t('Stores the sent trackbacks.'),
|
| 101 |
'fields' => array(
|
| 102 |
'nid' => array(
|
| 103 |
'type' => 'int',
|
| 104 |
'unsigned' => TRUE,
|
| 105 |
'not null' => TRUE,
|
| 106 |
'description' => t('The {node}.nid that sent the trackback.')
|
| 107 |
),
|
| 108 |
'url' => array(
|
| 109 |
'type' => 'varchar',
|
| 110 |
'length' => 255,
|
| 111 |
'not null' => TRUE,
|
| 112 |
'default' => '',
|
| 113 |
'description' => t('The trackback URL.')
|
| 114 |
),
|
| 115 |
'successful' => array(
|
| 116 |
'type' => 'int',
|
| 117 |
'not null' => TRUE,
|
| 118 |
'size' => 'tiny',
|
| 119 |
'description' => t('Boolean indicating whether the trackback has been successful.')
|
| 120 |
)
|
| 121 |
),
|
| 122 |
'primary key' => array('nid', 'url')
|
| 123 |
);
|
| 124 |
|
| 125 |
$schema['trackback_node'] = array(
|
| 126 |
'description' => t('Stores information about trackback for {node}s.'),
|
| 127 |
'fields' => array(
|
| 128 |
'nid' => array(
|
| 129 |
'type' => 'int',
|
| 130 |
'unsigned' => TRUE,
|
| 131 |
'not null' => TRUE,
|
| 132 |
'description' => t('The {node}.nid of the node.')
|
| 133 |
),
|
| 134 |
'awaiting_cron' => array(
|
| 135 |
'type' => 'int',
|
| 136 |
'not null' => TRUE,
|
| 137 |
'default' => 0,
|
| 138 |
'size' => 'tiny',
|
| 139 |
'description' => t('Boolean indicating whether the auto-detection should be run on cron.')
|
| 140 |
),
|
| 141 |
'can_receive' => array(
|
| 142 |
'type' => 'int',
|
| 143 |
'not null' => TRUE,
|
| 144 |
'default' => 0,
|
| 145 |
'size' => 'tiny',
|
| 146 |
'description' => t('Boolean indicating whether the node can receive trackbacks.')
|
| 147 |
)
|
| 148 |
),
|
| 149 |
'primary key' => array('nid')
|
| 150 |
);
|
| 151 |
|
| 152 |
return $schema;
|
| 153 |
}
|
| 154 |
|
| 155 |
function trackback_update_1() {
|
| 156 |
return _system_update_utf8(array('trackback_received', 'trackback_sent', 'trackback_node'));
|
| 157 |
}
|
| 158 |
|
| 159 |
function trackback_update_2() {
|
| 160 |
$n = variable_get('trackbacks_display_number', 10);
|
| 161 |
if ($n != 10) {
|
| 162 |
variable_set('trackback_display_number', $n);
|
| 163 |
}
|
| 164 |
variable_del('trackbacks_display_number');
|
| 165 |
$ret = array();
|
| 166 |
if ($GLOBALS['db_type'] == 'pgsql') {
|
| 167 |
$ret[] = update_sql("CREATE SEQUENCE {trackback_received}_trid_seq");
|
| 168 |
}
|
| 169 |
return $ret;
|
| 170 |
}
|
| 171 |
|
| 172 |
function trackback_update_3() {
|
| 173 |
$ret = _system_update_utf8(array('trackback_received', 'trackback_sent', 'trackback_node'));
|
| 174 |
if ($GLOBALS['db_type'] == 'pgsql') {
|
| 175 |
$ret[] = update_sql("CREATE INDEX {trackback_received}_nid_idx ON {trackback_received}(nid)");
|
| 176 |
}
|
| 177 |
return $ret;
|
| 178 |
}
|
| 179 |
|
| 180 |
function trackback_update_4() {
|
| 181 |
$decode = array(
|
| 182 |
'&' => '&',
|
| 183 |
'<' => '<',
|
| 184 |
'>' => '>',
|
| 185 |
'"' => '"',
|
| 186 |
''' => "'"
|
| 187 |
);
|
| 188 |
$r = array();
|
| 189 |
$result = db_query('SELECT trid, url FROM {trackback_received}');
|
| 190 |
while ($tb = db_fetch_object($result)) {
|
| 191 |
if (strpos($tb->url, '&') !== FALSE) {
|
| 192 |
$r[$tb->trid] = strtr($tb->url, $decode);
|
| 193 |
}
|
| 194 |
}
|
| 195 |
$ret = array();
|
| 196 |
foreach ($r as $trid => $url) {
|
| 197 |
$ret[] = update_sql("UPDATE {trackback_received} SET url='". db_escape_string($url) ."' WHERE trid=". $trid);
|
| 198 |
}
|
| 199 |
return $ret;
|
| 200 |
}
|
| 201 |
|
| 202 |
function trackback_update_5() {
|
| 203 |
$ret = array();
|
| 204 |
switch ($GLOBALS['db_type']) {
|
| 205 |
case 'mysql':
|
| 206 |
case 'mysqli':
|
| 207 |
db_drop_primary_key($ret, 'trackback_received');
|
| 208 |
db_change_field($ret, 'trackback_received', 'trid', 'trid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('trid')));
|
| 209 |
$trid = db_result(db_query('SELECT MAX(trid) FROM {trackback_received}'));
|
| 210 |
$ret[] = update_sql('ALTER TABLE {trackback_received} AUTO_INCREMENT='. ($trid + 1));
|
| 211 |
db_change_field($ret, 'trackback_received', 'name', 'name', array('type' => 'varchar', 'length' => 60, 'not null' => TRUE));
|
| 212 |
db_drop_primary_key($ret, 'trackback_node');
|
| 213 |
db_change_field($ret, 'trackback_node', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('nid')));
|
| 214 |
break;
|
| 215 |
|
| 216 |
case 'pgsql':
|
| 217 |
db_drop_primary_key($ret, 'trackback_received');
|
| 218 |
$ret[] = update_sql('DROP SEQUENCE {trackback_received}_trid_seq');
|
| 219 |
db_change_field($ret, 'trackback_received', 'trid', 'trid', array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('trid')));
|
| 220 |
$ret[] = update_sql('SELECT SETVAL({trackback_received}_trid_seq, (SELECT MAX(trid) FROM {trackback_received}))');
|
| 221 |
db_drop_index($ret, 'trackback_received', 'nid');
|
| 222 |
db_change_field($ret, 'trackback_received', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), array('indexes' => array('nid' => array('nid'))));
|
| 223 |
db_change_field($ret, 'trackback_received', 'status', 'status', array('type' => 'int', 'unsigned' => TRUE, 'default' => 0, 'size' => 'tiny'));
|
| 224 |
db_drop_primary_key($ret, 'trackback_sent');
|
| 225 |
db_change_field($ret, 'trackback_sent', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('nid', 'url')));
|
| 226 |
db_drop_primary_key($ret, 'trackback_node');
|
| 227 |
db_change_field($ret, 'trackback_node', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE), array('primary key' => array('nid')));
|
| 228 |
db_change_field($ret, 'trackback_node', 'awaiting_cron', 'awaiting_cron', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
|
| 229 |
db_change_field($ret, 'trackback_node', 'can_receive', 'can_receive', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
|
| 230 |
break;
|
| 231 |
}
|
| 232 |
return $ret;
|
| 233 |
}
|