| 1 |
<?php
|
| 2 |
// $Id: gotcha.install,v 1.6 2009/06/08 12:03:49 hutch Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Install, update and uninstall functions for the gotcha module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_install().
|
| 11 |
*/
|
| 12 |
function gotcha_install() {
|
| 13 |
switch ($GLOBALS['db_type']) {
|
| 14 |
case 'mysql':
|
| 15 |
case 'mysqli':
|
| 16 |
$result = db_query("CREATE TABLE IF NOT EXISTS {gotcha} (
|
| 17 |
mid int NOT NULL auto_increment,
|
| 18 |
datestamp varchar(20) NOT NULL,
|
| 19 |
suspect tinyint NOT NULL default '0',
|
| 20 |
recipients longtext NOT NULL,
|
| 21 |
subject varchar(255) NOT NULL,
|
| 22 |
body longtext NOT NULL,
|
| 23 |
sendername varchar(255) NOT NULL,
|
| 24 |
sendermail varchar(255) NOT NULL,
|
| 25 |
userip varchar(20),
|
| 26 |
sitename varchar(255),
|
| 27 |
datesent varchar(20),
|
| 28 |
type varchar(4),
|
| 29 |
PRIMARY KEY (mid),
|
| 30 |
INDEX userip (userip)
|
| 31 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 32 |
break;
|
| 33 |
|
| 34 |
case 'pgsql':
|
| 35 |
$result = db_query("CREATE TABLE {gotcha} (
|
| 36 |
mid serial,
|
| 37 |
datestamp varchar(20) NOT NULL,
|
| 38 |
suspect smallint NOT NULL default '0',
|
| 39 |
recipients text NOT NULL,
|
| 40 |
subject varchar(255) NOT NULL,
|
| 41 |
body text NOT NULL,
|
| 42 |
sendername varchar(255) NOT NULL,
|
| 43 |
sendermail varchar(255) NOT NULL,
|
| 44 |
userip varchar(20),
|
| 45 |
sitename varchar(255),
|
| 46 |
datesent varchar(20),
|
| 47 |
type varchar(4),
|
| 48 |
PRIMARY KEY (mid)
|
| 49 |
)");
|
| 50 |
db_query("CREATE INDEX {gotcha}_userip ON {gotcha} (userip)");
|
| 51 |
break;
|
| 52 |
}
|
| 53 |
// Set the module weight so it loads after Contact.
|
| 54 |
db_query("UPDATE {system} SET weight=10 WHERE name='gotcha'");
|
| 55 |
|
| 56 |
if ($result) {
|
| 57 |
drupal_set_message(t('Gotcha module installed.'));
|
| 58 |
}
|
| 59 |
else {
|
| 60 |
drupal_set_message(t('Gotcha table creation failed. Please "uninstall" the module and retry.'));
|
| 61 |
}
|
| 62 |
}
|
| 63 |
|
| 64 |
/**
|
| 65 |
* Implementation of hook_update_N().
|
| 66 |
* This is required by the addition of the password change intercept - now removed.
|
| 67 |
*/
|
| 68 |
function gotcha_update_5100() {
|
| 69 |
$ret = array();
|
| 70 |
$ret[] = update_sql("UPDATE {system} SET weight=10 WHERE name='gotcha'");
|
| 71 |
return $ret;
|
| 72 |
}
|
| 73 |
|
| 74 |
/**
|
| 75 |
* Implementation of hook_update_N().
|
| 76 |
* This is required by changes to the fields.
|
| 77 |
*/
|
| 78 |
function gotcha_update_5101() {
|
| 79 |
$ret = array();
|
| 80 |
|
| 81 |
$ret[] = update_sql("ALTER TABLE {gotcha} DROP servername");
|
| 82 |
$ret[] = update_sql("ALTER TABLE {gotcha} DROP serveraddr");
|
| 83 |
$ret[] = update_sql("ALTER TABLE {gotcha} DROP serverport");
|
| 84 |
db_add_column($ret, 'gotcha', 'datesent', 'varchar(20)');
|
| 85 |
|
| 86 |
switch ($GLOBALS['db_type']) {
|
| 87 |
case 'mysql':
|
| 88 |
case 'mysqli':
|
| 89 |
$ret[] = update_sql("ALTER TABLE {gotcha} ADD INDEX (userip)");
|
| 90 |
break;
|
| 91 |
|
| 92 |
case 'pgsql':
|
| 93 |
$ret[] = update_sql("CREATE INDEX {gotcha}_userip ON {gotcha} (userip)");
|
| 94 |
|
| 95 |
break;
|
| 96 |
}
|
| 97 |
return $ret;
|
| 98 |
}
|
| 99 |
|
| 100 |
/**
|
| 101 |
* Implementation of hook_update_N().
|
| 102 |
* Issue #174863
|
| 103 |
*/
|
| 104 |
function gotcha_update_5102() {
|
| 105 |
$ret = array();
|
| 106 |
$ret[] = update_sql("ALTER TABLE {gotcha} DROP PRIMARY KEY");
|
| 107 |
$ret[] = update_sql("ALTER TABLE {gotcha} DROP INDEX mid, ADD PRIMARY KEY (mid) ");
|
| 108 |
return $ret;
|
| 109 |
}
|
| 110 |
|
| 111 |
/**
|
| 112 |
* Implementation of hook_update_N().
|
| 113 |
* This adds the type field to intercept user contacts.
|
| 114 |
*/
|
| 115 |
function gotcha_update_5103() {
|
| 116 |
$ret = array();
|
| 117 |
|
| 118 |
db_add_column($ret, 'gotcha', 'type', 'varchar(4)');
|
| 119 |
// Previously we only intercepted site contacts.
|
| 120 |
$ret[] = update_sql("UPDATE {gotcha} SET type='site' WHERE type IS NULL");
|
| 121 |
|
| 122 |
return $ret;
|
| 123 |
}
|
| 124 |
|
| 125 |
/**
|
| 126 |
* Implementation of hook_uninstall().
|
| 127 |
*/
|
| 128 |
function gotcha_uninstall() {
|
| 129 |
db_query('DROP TABLE {gotcha}');
|
| 130 |
db_query("DELETE FROM {variable} WHERE name LIKE 'gotcha_%';");
|
| 131 |
drupal_set_message(t('Gotcha module uninstalled.'));
|
| 132 |
}
|