| 1 |
<?php
|
| 2 |
// $Id
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Implementation of hook_install().
|
| 6 |
*
|
| 7 |
* Database schema last updated 2007-07 by Benjamin Melanon.
|
| 8 |
*
|
| 9 |
* cmt_vocabulary (I think naming convention is singular)
|
| 10 |
* vid : vocabulary ID
|
| 11 |
* enabled : toggle switch that allows community managing to be turned off, without deleting thresholds
|
| 12 |
* description_th : voting threshold for term description
|
| 13 |
* weight_th : voting threshold for term weight
|
| 14 |
* name_th : voting threshold for term name
|
| 15 |
* hierarchy_th : voting threshold for term placement
|
| 16 |
* merge_th : voting threshold for term
|
| 17 |
* node_th : voting threshold for
|
| 18 |
* thresholds for above will be measured as 0, 1, and 2 (none, low, and high)
|
| 19 |
* related_th : this one is different. It gives the option to have a threshold to interpret votes for merging (cmt_term_merge) as votes for making related terms (negative values turn this feature off). This value must be less than the value of merge_th for anything to happen
|
| 20 |
*
|
| 21 |
* cmt_term_vocab (so we can delete records when deleting a vocab)
|
| 22 |
* vid
|
| 23 |
* tid
|
| 24 |
*
|
| 25 |
* cmt_term_data -- a FAKE table which holds results based on votes on others
|
| 26 |
* tid
|
| 27 |
* name
|
| 28 |
* weight
|
| 29 |
*
|
| 30 |
* cmt_term_description
|
| 31 |
* content_id : (which I called vapi_id) corresponds to votingapi content_id
|
| 32 |
* tid : same as in term_data
|
| 33 |
* description : same as in term_data. Don't see a reason to put a key on description
|
| 34 |
* vote : current vote value for this tid, description combination provided by votingapi
|
| 35 |
*
|
| 36 |
* cmt_term_weight
|
| 37 |
* content_id : (which I called vapi_id) corresponds to votingapi content_id
|
| 38 |
* tid : same as in term_data
|
| 39 |
* weight : same as in term_data
|
| 40 |
* vote : current vote value
|
| 41 |
*
|
| 42 |
* name inserted into synonym-modeled table cmt_term_name, where votes for names/synonyms are tracked
|
| 43 |
*
|
| 44 |
* cmt_term_name (based on term_synonym table)
|
| 45 |
* content_id
|
| 46 |
* tid
|
| 47 |
* name
|
| 48 |
* vote
|
| 49 |
*
|
| 50 |
* cmt_term_hierarchy
|
| 51 |
* content_id : corresponds to votingapi content_id
|
| 52 |
* tid : same as in term_hierarchy
|
| 53 |
* parent : same as in term_hierarchy
|
| 54 |
* vote
|
| 55 |
*
|
| 56 |
* cmt_term_merge
|
| 57 |
* content_id : key for votingapi content_id
|
| 58 |
* tid1 : term, that gets to keep its name and info, to merge onto tid2
|
| 59 |
* tid2 : term, that subsumes its name and info, to merge into tid1
|
| 60 |
* vote
|
| 61 |
* -- I will not be able to resist deriving related terms from this
|
| 62 |
*
|
| 63 |
* cmt_term_node
|
| 64 |
* content_id
|
| 65 |
* nid
|
| 66 |
* tid
|
| 67 |
* vote
|
| 68 |
*
|
| 69 |
*/
|
| 70 |
|
| 71 |
function cmt_install() {
|
| 72 |
switch ($GLOBALS['db_type']) {
|
| 73 |
case 'mysql':
|
| 74 |
case 'mysqli':
|
| 75 |
db_query("CREATE TABLE {cmt_vocabulary} (
|
| 76 |
vid int unsigned NOT NULL DEFAULT '0',
|
| 77 |
cmt_enabled tinyint unsigned NOT NULL DEFAULT '1',
|
| 78 |
cmt_description_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 79 |
cmt_weight_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 80 |
cmt_name_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 81 |
cmt_hierarchy_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 82 |
cmt_merge_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 83 |
cmt_node_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 84 |
cmt_related_th tinyint unsigned NOT NULL DEFAULT '0',
|
| 85 |
KEY (cmt_enabled),
|
| 86 |
PRIMARY KEY (vid)
|
| 87 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */
|
| 88 |
");
|
| 89 |
db_query("CREATE TABLE {cmt_term_vocab} (
|
| 90 |
vid int(10) unsigned NOT NULL DEFAULT '0',
|
| 91 |
tid int(10) unsigned NOT NULL DEFAULT '0',
|
| 92 |
KEY (vid),
|
| 93 |
PRIMARY KEY (tid, vid)
|
| 94 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */
|
| 95 |
");
|
| 96 |
// denormalized table
|
| 97 |
db_query("CREATE TABLE {cmt_term_data} (
|
| 98 |
tid int(10) unsigned NOT NULL auto_increment,
|
| 99 |
name varchar(255) NOT NULL DEFAULT '',
|
| 100 |
weight tinyint NOT NULL DEFAULT '0',
|
| 101 |
PRIMARY KEY (tid)
|
| 102 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */
|
| 103 |
");
|
| 104 |
db_query("CREATE TABLE {cmt_term_description} (
|
| 105 |
content_id int(10) unsigned NOT NULL auto_increment,
|
| 106 |
tid int(10) unsigned NOT NULL,
|
| 107 |
description longtext,
|
| 108 |
vote float(10) default NULL,
|
| 109 |
KEY (tid),
|
| 110 |
KEY (description(25)),
|
| 111 |
KEY (vote),
|
| 112 |
PRIMARY KEY (content_id)
|
| 113 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */
|
| 114 |
"); // # no can do: UNIQUE KEY (tid, description)
|
| 115 |
db_query("CREATE TABLE {cmt_term_weight} (
|
| 116 |
content_id int(10) unsigned NOT NULL auto_increment,
|
| 117 |
tid int(10) unsigned NOT NULL DEFAULT '0',
|
| 118 |
weight tinyint NOT NULL DEFAULT '0',
|
| 119 |
vote float(10) default NULL,
|
| 120 |
KEY (tid),
|
| 121 |
KEY (weight),
|
| 122 |
KEY (vote),
|
| 123 |
UNIQUE KEY (tid, weight),
|
| 124 |
PRIMARY KEY (content_id)
|
| 125 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 126 |
db_query("CREATE TABLE {cmt_term_name} (
|
| 127 |
content_id int(10) unsigned NOT NULL auto_increment,
|
| 128 |
tid int unsigned NOT NULL DEFAULT '0',
|
| 129 |
name varchar(255) NOT NULL DEFAULT '',
|
| 130 |
vote float(10) default NULL,
|
| 131 |
KEY tid (tid),
|
| 132 |
KEY name (name(3)),
|
| 133 |
KEY (vote),
|
| 134 |
PRIMARY KEY (content_id)
|
| 135 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 136 |
db_query("CREATE TABLE {cmt_term_hierarchy} (
|
| 137 |
content_id int(10) unsigned NOT NULL auto_increment,
|
| 138 |
tid int(10) unsigned NOT NULL DEFAULT '0',
|
| 139 |
parent int unsigned NOT NULL DEFAULT '0',
|
| 140 |
vote float(10) default NULL,
|
| 141 |
KEY tid (tid),
|
| 142 |
KEY parent (parent),
|
| 143 |
KEY (vote),
|
| 144 |
UNIQUE KEY (tid, parent),
|
| 145 |
PRIMARY KEY (content_id)
|
| 146 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 147 |
db_query("CREATE TABLE {cmt_term_merge} (
|
| 148 |
content_id int(10) unsigned NOT NULL auto_increment,
|
| 149 |
tid1 int unsigned NOT NULL DEFAULT '0',
|
| 150 |
tid2 int unsigned NOT NULL DEFAULT '0',
|
| 151 |
vote float(10) default NULL,
|
| 152 |
KEY tid1 (tid1),
|
| 153 |
KEY tid2 (tid2),
|
| 154 |
KEY (vote),
|
| 155 |
UNIQUE KEY (tid1, tid2),
|
| 156 |
PRIMARY KEY (content_id)
|
| 157 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 158 |
db_query("CREATE TABLE {cmt_term_node} (
|
| 159 |
content_id int(10) unsigned NOT NULL auto_increment,
|
| 160 |
nid int unsigned NOT NULL DEFAULT '0',
|
| 161 |
tid int unsigned NOT NULL DEFAULT '0',
|
| 162 |
vote float(10) default NULL,
|
| 163 |
KEY nid (nid),
|
| 164 |
KEY tid (tid),
|
| 165 |
KEY (vote),
|
| 166 |
UNIQUE KEY (tid, nid),
|
| 167 |
PRIMARY KEY (content_id)
|
| 168 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 169 |
break;
|
| 170 |
|
| 171 |
case 'pgsql':
|
| 172 |
/* this relies on create unsigned types done in system.install */
|
| 173 |
/* NOTE: PostgreSQL compatibility has not been tested, and it needs a (partial) index on cmt_term_description's description text column */
|
| 174 |
// pgsql IS CURRENTLY OUT OF DATE. Needs vote key for vote column
|
| 175 |
// Missing a few other keys too, I think
|
| 176 |
|
| 177 |
db_query("CREATE TABLE {cmt_vocabulary} (
|
| 178 |
vid int unsigned NOT NULL DEFAULT '0',
|
| 179 |
cmt_enabled tinyint unsigned NOT NULL DEFAULT '1',
|
| 180 |
cmt_description_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 181 |
cmt_weight_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 182 |
cmt_name_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 183 |
cmt_hierarchy_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 184 |
cmt_merge_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 185 |
cmt_node_th tinyint unsigned NOT NULL DEFAULT '1',
|
| 186 |
cmt_related_th tinyint unsigned NOT NULL DEFAULT '0',
|
| 187 |
KEY (cmt_enabled),
|
| 188 |
PRIMARY KEY (vid)
|
| 189 |
)");
|
| 190 |
|
| 191 |
db_query("CREATE TABLE {cmt_term_vocab} (
|
| 192 |
vid int_unsigned NOT NULL DEFAULT '0',
|
| 193 |
tid int_unsigned NOT NULL DEFAULT '0'
|
| 194 |
)");
|
| 195 |
|
| 196 |
db_query("CREATE TABLE {cmt_term_data} (
|
| 197 |
tid serial CHECK (tid >= 0),
|
| 198 |
name varchar(255) NOT NULL DEFAULT '',
|
| 199 |
weight tinyint NOT NULL DEFAULT '0',
|
| 200 |
/*!40100 DEFAULT CHARACTER SET UTF8 */
|
| 201 |
");
|
| 202 |
|
| 203 |
db_query("CREATE TABLE {cmt_term_description} (
|
| 204 |
content_id serial CHECK (content_id >= 0),
|
| 205 |
tid int_unsigned NOT NULL,
|
| 206 |
description text,
|
| 207 |
vote float(10) default NULL,
|
| 208 |
PRIMARY KEY (content_id)
|
| 209 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ "); // @TODO check index on description, prefix needed
|
| 210 |
db_query("CREATE INDEX {cmt_term_description}_content_id_idx ON {cmt_term_description} (content_id)");
|
| 211 |
db_query("CREATE INDEX {cmt_term_description}_content_id_idx ON {cmt_term_description} (content_id)");
|
| 212 |
|
| 213 |
db_query("CREATE TABLE {cmt_term_hierarchy} (
|
| 214 |
content_id serial CHECK (content_id >= 0),
|
| 215 |
tid int_unsigned NOT NULL default '0',
|
| 216 |
parent int_unsigned NOT NULL default '0',
|
| 217 |
vote float(10) default NULL,
|
| 218 |
UNIQUE (tid, parent),
|
| 219 |
PRIMARY KEY (content_id)
|
| 220 |
)");
|
| 221 |
db_query("CREATE INDEX {cmt_term_hierarchy}_tid_idx ON {cmt_term_hierarchy} (tid)");
|
| 222 |
db_query("CREATE INDEX {cmt_term_hierarchy}_parent_idx ON {cmt_term_hierarchy} (parent)");
|
| 223 |
db_query("CREATE INDEX {cmt_term_hierarchy}_content_id_idx ON {cmt_term_hierarchy} (content_id)");
|
| 224 |
|
| 225 |
db_query("CREATE TABLE {cmt_term_merge} (
|
| 226 |
content_id serial CHECK (content_id >= 0),
|
| 227 |
tid1 int_unsigned NOT NULL default '0',
|
| 228 |
tid2 int_unsigned NOT NULL default '0'
|
| 229 |
vote float(10) default NULL,
|
| 230 |
UNIQUE (tid1, tid2),
|
| 231 |
PRIMARY KEY (content_id)
|
| 232 |
)");
|
| 233 |
db_query("CREATE INDEX {cmt_term_merge}_tid1_idx ON {cmt_term_merge} (tid1)");
|
| 234 |
db_query("CREATE INDEX {cmt_term_merge}_tid2_idx ON {cmt_term_merge} (tid2)");
|
| 235 |
|
| 236 |
db_query("CREATE TABLE {cmt_term_node} (
|
| 237 |
content_id serial CHECK (content_id >= 0),
|
| 238 |
nid int_unsigned NOT NULL default '0',
|
| 239 |
tid int_unsigned NOT NULL default '0',
|
| 240 |
vote float(10) default NULL,
|
| 241 |
UNIQUE (nid, tid),
|
| 242 |
PRIMARY KEY (content_id)
|
| 243 |
)");
|
| 244 |
db_query("CREATE INDEX {term_node}_nid_idx ON {term_node} (nid)");
|
| 245 |
db_query("CREATE INDEX {term_node}_tid_idx ON {term_node} (tid)");
|
| 246 |
|
| 247 |
db_query("CREATE TABLE {cmt_term_name} (
|
| 248 |
content_id serial CHECK (content_id >= 0),
|
| 249 |
tid int_unsigned NOT NULL default '0',
|
| 250 |
name varchar(255) NOT NULL default '',
|
| 251 |
vote float(10) default NULL,
|
| 252 |
PRIMARY KEY (content_id)
|
| 253 |
)");
|
| 254 |
db_query("CREATE INDEX {cmt_term_name}_tid_idx ON {cmt_term_name} (tid)");
|
| 255 |
db_query("CREATE INDEX {cmt_term_name}_name_idx ON {cmt_term_name} (substr(name, 1, 3))");
|
| 256 |
break;
|
| 257 |
default:
|
| 258 |
return drupal_set_message(t('Database type @type not supported', array('@type' => $GLOBALS['db_type'])), 'error');
|
| 259 |
}
|
| 260 |
}
|
| 261 |
|
| 262 |
|
| 263 |
/* update example:
|
| 264 |
function cmt_update_20() {
|
| 265 |
$ret = array();
|
| 266 |
|
| 267 |
switch ($GLOBALS['db_type']) {
|
| 268 |
case 'mysql':
|
| 269 |
case 'mysqli':
|
| 270 |
$ret[] = update_sql("UPDATE {node} SET type = 'casetracker_basic_project' WHERE type = 'casetracker_project'");
|
| 271 |
$ret[] = update_sql("UPDATE {node} SET type = 'casetracker_basic_case' WHERE type = 'casetracker_case'");
|
| 272 |
break;
|
| 273 |
}
|
| 274 |
|
| 275 |
return $ret;
|
| 276 |
}
|
| 277 |
*/
|
| 278 |
|
| 279 |
/**
|
| 280 |
* Implementation of hook_uninstall().
|
| 281 |
*/
|
| 282 |
function cmt_uninstall() {
|
| 283 |
db_query('DROP TABLE {cmt_term_description}');
|
| 284 |
db_query('DROP TABLE {cmt_term_weight}');
|
| 285 |
db_query('DROP TABLE {cmt_term_name}');
|
| 286 |
db_query('DROP TABLE {cmt_term_hierarchy}');
|
| 287 |
db_query('DROP TABLE {cmt_term_merge}');
|
| 288 |
db_query('DROP TABLE {cmt_term_node}');
|
| 289 |
db_query('DROP TABLE {cmt_term_data}');
|
| 290 |
db_query('DROP TABLE {cmt_term_vocab}');
|
| 291 |
db_query('DROP TABLE {cmt_vocabulary}');
|
| 292 |
variable_del('cmt_example_variable');
|
| 293 |
}
|