| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/*
|
| 5 |
* @file
|
| 6 |
* Installation functions for the comms module
|
| 7 |
*
|
| 8 |
* there is some docs on the drupal DB schema here: http://projects.contentment.org/blog/84
|
| 9 |
* when doing database operations in this file try to use the DB API as much as
|
| 10 |
* possible (http://api.drupal.org/api/group/database/5)
|
| 11 |
*
|
| 12 |
* TODO: migrate all auto increment fields to use the drupal's sequences
|
| 13 |
* TODO: put an index on votingapi_cache.function of length 8
|
| 14 |
*/
|
| 15 |
|
| 16 |
function comms_install() {
|
| 17 |
|
| 18 |
switch ($GLOBALS['db_type']) {
|
| 19 |
case 'mysql':
|
| 20 |
case 'mysqli':
|
| 21 |
|
| 22 |
// the {tablename} syntax is so multisite installs can add a
|
| 23 |
// prefix to the table name as set in the settings.php file
|
| 24 |
|
| 25 |
//not to be confused with content_type_comms which will be added if
|
| 26 |
//cck content is added, which we are not using!
|
| 27 |
db_query("CREATE TABLE {comms_additions} (
|
| 28 |
`nid` int(10) unsigned NOT NULL default 0,
|
| 29 |
`sms_message` varchar(140) NOT NULL default '',
|
| 30 |
PRIMARY KEY (`nid`)
|
| 31 |
);");
|
| 32 |
|
| 33 |
db_query("CREATE TABLE {group_twitter_account} (
|
| 34 |
`nid` int(10) unsigned NOT NULL default 0,
|
| 35 |
`username` varchar(32) NOT NULL default '',
|
| 36 |
`password` varchar(32) NOT NULL default '',
|
| 37 |
PRIMARY KEY (`nid`)
|
| 38 |
);");
|
| 39 |
|
| 40 |
db_query("CREATE TABLE {twitter_api_calls} (
|
| 41 |
`tacid` INT NOT NULL AUTO_INCREMENT ,
|
| 42 |
`nid` INT NOT NULL ,
|
| 43 |
`gid` INT NOT NULL ,
|
| 44 |
`function` VARCHAR( 32 ) NOT NULL ,
|
| 45 |
`authenticated` BOOL NOT NULL ,
|
| 46 |
`call_time` timestamp NULL default CURRENT_TIMESTAMP,
|
| 47 |
`success` tinyint(1) default '1',
|
| 48 |
`message` varchar(256) default NULL,
|
| 49 |
PRIMARY KEY ( `tacid` )
|
| 50 |
);");
|
| 51 |
|
| 52 |
db_query("CREATE TABLE {comms_group_dispatch} (
|
| 53 |
`nid` int(11) NOT NULL,
|
| 54 |
`gid` int(11) NOT NULL,
|
| 55 |
`dispatch_time` timestamp NULL default CURRENT_TIMESTAMP,
|
| 56 |
PRIMARY KEY (`nid`,`gid`)
|
| 57 |
);");
|
| 58 |
|
| 59 |
//we will install the default comms variables here
|
| 60 |
variable_set('comms_actionname', "comms");
|
| 61 |
variable_set('comms_dispatchlevel', 5);
|
| 62 |
variable_set('comms_debuglevel', 0);
|
| 63 |
variable_set('comms_twitterdirectmsgmaxid', 0);
|
| 64 |
variable_set('comms_twitterfrommsgmaxid', 0);
|
| 65 |
|
| 66 |
break;
|
| 67 |
|
| 68 |
//we have not implemented this for postgres :(
|
| 69 |
case 'pgsql':
|
| 70 |
// Pgsql requires keys and indexes to be defined separately.
|
| 71 |
// It's important to name the index as {tablename}_fieldname_idx
|
| 72 |
// (the trailing _idx!) so update scripts can be written easily
|
| 73 |
break;
|
| 74 |
}
|
| 75 |
}
|
| 76 |
|
| 77 |
function comms_uninstall() {
|
| 78 |
watchdog("comms", "removing the comms module");
|
| 79 |
|
| 80 |
if (! db_query("DROP TABLE {comms_additions};")) {
|
| 81 |
watchdog("comms", "problem removing table comms_additions", WATCHDOG_ERROR);
|
| 82 |
}
|
| 83 |
|
| 84 |
if (! db_query("DROP TABLE {group_twitter_account};")) {
|
| 85 |
watchdog("comms", "problem removing table group_twitter_account", WATCHDOG_ERROR);
|
| 86 |
}
|
| 87 |
|
| 88 |
if (! db_query("DROP TABLE {twitter_api_calls};")) {
|
| 89 |
watchdog("comms", "problem removing table twitter_api_calls", WATCHDOG_ERROR);
|
| 90 |
}
|
| 91 |
|
| 92 |
if (! db_query("DROP TABLE {comms_group_dispatch};")) {
|
| 93 |
watchdog("comms", "problem removing table twitter_api_calls", WATCHDOG_ERROR);
|
| 94 |
}
|
| 95 |
|
| 96 |
watchdog("comms", "deleting all of the variables used by the comms module");
|
| 97 |
variable_del('comms_actionname');
|
| 98 |
variable_del('comms_dispatchlevel');
|
| 99 |
variable_del('comms_debuglevel');
|
| 100 |
variable_del('comms_twitterdirectmsgmaxid');
|
| 101 |
variable_del('comms_twitterfrommsgmaxid');
|
| 102 |
}
|