| 1 |
<?php
|
| 2 |
// $Id: chatroom.install,v 1.25.4.4 2009/10/29 20:43:01 justinrandell Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Install chatroom module
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_schema().
|
| 11 |
*/
|
| 12 |
function chatroom_schema() {
|
| 13 |
$schema['chatroom'] = array(
|
| 14 |
'fields' => array(
|
| 15 |
'nid' => array(
|
| 16 |
'type' => 'int',
|
| 17 |
'not null' => TRUE,
|
| 18 |
'description' => t('Primary key: node ID of the chatroom.'),
|
| 19 |
),
|
| 20 |
'poll_freq' => array(
|
| 21 |
'type' => 'int',
|
| 22 |
'not null' => TRUE,
|
| 23 |
'default' => 1000,
|
| 24 |
'description' => t('Default polling interval, in milliseconds, of all chats in this chatroom.'),
|
| 25 |
),
|
| 26 |
'idle_freq' => array(
|
| 27 |
'type' => 'int',
|
| 28 |
'not null' => TRUE,
|
| 29 |
'default' => 60000,
|
| 30 |
'description' => t('Default idle interval, in milliseconds, of all chats in this chatroom.'),
|
| 31 |
),
|
| 32 |
'kicked_out_message' => array(
|
| 33 |
'type' => 'text',
|
| 34 |
'size' => 'big',
|
| 35 |
'description' => t('Default message sent to users kicked from any chat in this chatroom.'),
|
| 36 |
),
|
| 37 |
'banned_message' => array(
|
| 38 |
'type' => 'text',
|
| 39 |
'size' => 'big',
|
| 40 |
'description' => t('Default message sent to users banned from any chat in this chatroom.'),
|
| 41 |
),
|
| 42 |
'module' => array(
|
| 43 |
'type' => 'varchar',
|
| 44 |
'length' => '255',
|
| 45 |
'default' => 'chatroom',
|
| 46 |
'description' => t('The module that owns this chatroom.'),
|
| 47 |
),
|
| 48 |
'previous_messages_display_count' => array(
|
| 49 |
'type' => 'int',
|
| 50 |
'default' => 20,
|
| 51 |
'description' => t('The number of previous messages to display to a user when they first enter a chat.'),
|
| 52 |
),
|
| 53 |
'popout' => array(
|
| 54 |
'type' => 'int',
|
| 55 |
'default' => 0,
|
| 56 |
'description' => t('Default for whether to load chats in this chatroom in a popout window.'),
|
| 57 |
),
|
| 58 |
'profile_picture' => array(
|
| 59 |
'type' => 'int',
|
| 60 |
'default' => 0,
|
| 61 |
'description' => t('Whether to display user profile pictures in online lists by default for chats in this room.'),
|
| 62 |
),
|
| 63 |
),
|
| 64 |
'primary key' => array('nid'),
|
| 65 |
);
|
| 66 |
$schema['chatroom_ban_list'] = array(
|
| 67 |
'fields' => array(
|
| 68 |
'nid' => array(
|
| 69 |
'type' => 'int',
|
| 70 |
'not null' => TRUE,
|
| 71 |
'description' => t('Chatroom ID.'),
|
| 72 |
),
|
| 73 |
'uid' => array(
|
| 74 |
'type' => 'int',
|
| 75 |
'not null' => TRUE,
|
| 76 |
'description' => t('ID of the banned user.'),
|
| 77 |
),
|
| 78 |
'admin_uid' => array(
|
| 79 |
'type' => 'int',
|
| 80 |
'not null' => TRUE,
|
| 81 |
'description' => t('ID of the chatroom admin who imposed the ban.'),
|
| 82 |
),
|
| 83 |
'modified' => array(
|
| 84 |
'type' => 'int',
|
| 85 |
'not null' => TRUE,
|
| 86 |
'default' => 0,
|
| 87 |
'description' => t('UNIX timestamp of when the ban was imposed.'),
|
| 88 |
),
|
| 89 |
),
|
| 90 |
'primary key' => array('admin_uid', 'uid'),
|
| 91 |
);
|
| 92 |
$schema['chatroom_chat_ban_list'] = array(
|
| 93 |
'fields' => array(
|
| 94 |
'nid' => array(
|
| 95 |
'type' => 'int',
|
| 96 |
'not null' => TRUE,
|
| 97 |
'description' => t('Chat ID.'),
|
| 98 |
),
|
| 99 |
'uid' => array(
|
| 100 |
'type' => 'int',
|
| 101 |
'not null' => TRUE,
|
| 102 |
'description' => t('ID of the banned user.'),
|
| 103 |
),
|
| 104 |
'admin_uid' => array(
|
| 105 |
'type' => 'int',
|
| 106 |
'not null' => TRUE,
|
| 107 |
'description' => t('ID of the chatroom admin who imposed the ban.'),
|
| 108 |
),
|
| 109 |
'modified' => array(
|
| 110 |
'type' => 'int',
|
| 111 |
'not null' => TRUE,
|
| 112 |
'default' => 0,
|
| 113 |
'description' => t('UNIX timestamp of when the ban was imposed.'),
|
| 114 |
),
|
| 115 |
),
|
| 116 |
'primary key' => array('admin_uid', 'uid'),
|
| 117 |
);
|
| 118 |
$schema['chatroom_chat'] = array(
|
| 119 |
'fields' => array(
|
| 120 |
'nid' => array(
|
| 121 |
'type' => 'int',
|
| 122 |
'not null' => TRUE,
|
| 123 |
'description' => t('Primary key: node ID of the chat.'),
|
| 124 |
),
|
| 125 |
'crid' => array(
|
| 126 |
'type' => 'int',
|
| 127 |
'not null' => TRUE,
|
| 128 |
'default' => 0,
|
| 129 |
'description' => t('ID of the chatroom the chat belongs to. 0 signifies this chat does not belong to a room.'),
|
| 130 |
),
|
| 131 |
'poll_freq' => array(
|
| 132 |
'type' => 'int',
|
| 133 |
'not null' => TRUE,
|
| 134 |
'default' => 1000,
|
| 135 |
'description' => t('Polling interval, in milliseconds, of the chat.'),
|
| 136 |
),
|
| 137 |
'idle_freq' => array(
|
| 138 |
'type' => 'int',
|
| 139 |
'not null' => TRUE,
|
| 140 |
'default' => 60000,
|
| 141 |
'description' => t('Idle interval, in milliseconds, of the chat.'),
|
| 142 |
),
|
| 143 |
'kicked_out_message' => array(
|
| 144 |
'type' => 'text',
|
| 145 |
'size' => 'big',
|
| 146 |
'description' => t('Message sent to users kicked from the chat.'),
|
| 147 |
),
|
| 148 |
'banned_message' => array(
|
| 149 |
'type' => 'text',
|
| 150 |
'size' => 'big',
|
| 151 |
'description' => t('Message sent to users banned from the chat.'),
|
| 152 |
),
|
| 153 |
'module' => array(
|
| 154 |
'type' => 'varchar',
|
| 155 |
'length' => '255',
|
| 156 |
'default' => 'chatroom',
|
| 157 |
'description' => t('The module that owns this chat.'),
|
| 158 |
),
|
| 159 |
'previous_messages_display_count' => array(
|
| 160 |
'type' => 'int',
|
| 161 |
'default' => 20,
|
| 162 |
'description' => t('The number of previous messages to display to a user when they first enter a chat.'),
|
| 163 |
),
|
| 164 |
'when_archived' => array(
|
| 165 |
'type' => 'int',
|
| 166 |
'description' => t('UNIX timestamp of when the chat was last archived.'),
|
| 167 |
),
|
| 168 |
'popout' => array(
|
| 169 |
'type' => 'int',
|
| 170 |
'default' => 0,
|
| 171 |
'description' => t('Whether to load this chat in a popout window.'),
|
| 172 |
),
|
| 173 |
'profile_picture' => array(
|
| 174 |
'type' => 'int',
|
| 175 |
'default' => 0,
|
| 176 |
'description' => t('Whether to display user profile pictures in online lists for this chat.'),
|
| 177 |
),
|
| 178 |
),
|
| 179 |
'indexes' => array(
|
| 180 |
'crid' => array('crid'),
|
| 181 |
),
|
| 182 |
'primary key' => array('nid'),
|
| 183 |
);
|
| 184 |
$schema['chatroom_msg'] = array(
|
| 185 |
'fields' => array(
|
| 186 |
'cmid' => array(
|
| 187 |
'type' => 'serial',
|
| 188 |
'not null' => TRUE,
|
| 189 |
),
|
| 190 |
'ccid' => array(
|
| 191 |
'type' => 'int',
|
| 192 |
'not null' => TRUE,
|
| 193 |
'default' => 0,
|
| 194 |
),
|
| 195 |
'uid' => array(
|
| 196 |
'type' => 'int',
|
| 197 |
'not null' => TRUE,
|
| 198 |
'default' => 0,
|
| 199 |
),
|
| 200 |
'msg_type' => array(
|
| 201 |
'type' => 'varchar',
|
| 202 |
'length' => '64',
|
| 203 |
'not null' => TRUE,
|
| 204 |
),
|
| 205 |
'msg' => array(
|
| 206 |
'type' => 'text',
|
| 207 |
'size' => 'big',
|
| 208 |
),
|
| 209 |
'sid' => array(
|
| 210 |
'type' => 'varchar',
|
| 211 |
'length' => '64',
|
| 212 |
'not null' => TRUE,
|
| 213 |
),
|
| 214 |
'recipient_uid' => array(
|
| 215 |
'type' => 'int',
|
| 216 |
'not null' => TRUE,
|
| 217 |
'default' => 0,
|
| 218 |
),
|
| 219 |
'modified' => array(
|
| 220 |
'type' => 'int',
|
| 221 |
'not null' => TRUE,
|
| 222 |
'default' => 0,
|
| 223 |
),
|
| 224 |
),
|
| 225 |
'indexes' => array(
|
| 226 |
'ccid' => array('ccid'),
|
| 227 |
'modified' => array('modified'),
|
| 228 |
'recipient_uid' => array('recipient_uid'),
|
| 229 |
'sid' => array('sid')
|
| 230 |
),
|
| 231 |
'primary key' => array('cmid'),
|
| 232 |
);
|
| 233 |
$schema['chatroom_chat_online_list'] = array(
|
| 234 |
'fields' => array(
|
| 235 |
'ccid' => array(
|
| 236 |
'type' => 'int',
|
| 237 |
'not null' => TRUE,
|
| 238 |
'description' => t('Chat ID.'),
|
| 239 |
),
|
| 240 |
'uid' => array(
|
| 241 |
'type' => 'int',
|
| 242 |
'not null' => TRUE,
|
| 243 |
'default' => 0,
|
| 244 |
),
|
| 245 |
'guest_id' => array(
|
| 246 |
'type' => 'int',
|
| 247 |
'not null' => TRUE,
|
| 248 |
'default' => 0,
|
| 249 |
),
|
| 250 |
'sid' => array(
|
| 251 |
'type' => 'varchar',
|
| 252 |
'length' => '64',
|
| 253 |
'not null' => TRUE,
|
| 254 |
'description' => t('Session ID.'),
|
| 255 |
),
|
| 256 |
'away' => array(
|
| 257 |
'type' => 'int',
|
| 258 |
'default' => 0,
|
| 259 |
'description' => t('Boolean: whether the user is away.'),
|
| 260 |
),
|
| 261 |
'last_seen_time' => array(
|
| 262 |
'type' => 'int',
|
| 263 |
'not null' => TRUE,
|
| 264 |
'default' => 0,
|
| 265 |
'description' => t('UNIX timestamp of when the user was last seen.'),
|
| 266 |
),
|
| 267 |
),
|
| 268 |
'primary key' => array('ccid', 'sid'),
|
| 269 |
'indexes' => array(
|
| 270 |
'uid' => array('uid'),
|
| 271 |
'guest_id' => array('guest_id'),
|
| 272 |
),
|
| 273 |
);
|
| 274 |
$schema['chatroom_chat_invite'] = array(
|
| 275 |
'fields' => array(
|
| 276 |
'ccid' => array(
|
| 277 |
'type' => 'int',
|
| 278 |
'not null' => TRUE,
|
| 279 |
'description' => t('Chat ID.'),
|
| 280 |
),
|
| 281 |
'inviter_uid' => array(
|
| 282 |
'type' => 'int',
|
| 283 |
'not null' => TRUE,
|
| 284 |
'default' => 0,
|
| 285 |
),
|
| 286 |
'invitee_uid' => array(
|
| 287 |
'type' => 'int',
|
| 288 |
'not null' => TRUE,
|
| 289 |
'default' => 0,
|
| 290 |
),
|
| 291 |
),
|
| 292 |
);
|
| 293 |
return $schema;
|
| 294 |
}
|
| 295 |
|
| 296 |
/**
|
| 297 |
* Implementation of hook_requirements().
|
| 298 |
*/
|
| 299 |
function chatroom_requirements($phase) {
|
| 300 |
$requirements = array();
|
| 301 |
if ($GLOBALS['db_type'] == 'mysql' && version_compare(db_version(), '4.1') < 0) {
|
| 302 |
$t = get_t();
|
| 303 |
$requirements['chatroom'] = array(
|
| 304 |
'title' => $t('Chat Room'),
|
| 305 |
'value' => $t('Your MySQL version is too low. Chat Room requires MySQL 4.1 or higher.'),
|
| 306 |
'chatroom' => REQUIREMENT_ERROR,
|
| 307 |
);
|
| 308 |
}
|
| 309 |
return $requirements;
|
| 310 |
}
|
| 311 |
|
| 312 |
/**
|
| 313 |
* Implementation of hook_install().
|
| 314 |
*/
|
| 315 |
function chatroom_install() {
|
| 316 |
drupal_install_schema('chatroom');
|
| 317 |
|
| 318 |
if (function_exists('block_rehash')) {
|
| 319 |
_block_rehash();
|
| 320 |
}
|
| 321 |
|
| 322 |
drupal_set_message(t('Chat room module enabled.'));
|
| 323 |
}
|
| 324 |
|
| 325 |
/**
|
| 326 |
* Implementation of hook_uninstall().
|
| 327 |
*/
|
| 328 |
function chatroom_uninstall() {
|
| 329 |
$t = get_t();
|
| 330 |
$result = db_query("SELECT nid FROM {node} WHERE type = 'chatroom' OR type = 'chat'");
|
| 331 |
while ($chat_room_node = db_fetch_object($result)) {
|
| 332 |
node_delete($chat_room_node->nid);
|
| 333 |
}
|
| 334 |
drupal_set_message($t('Chat room nodes have been deleted from the database.'));
|
| 335 |
|
| 336 |
drupal_uninstall_schema('chatroom');
|
| 337 |
drupal_set_message($t('Chat room tables have been dropped from the database.'));
|
| 338 |
|
| 339 |
db_query("DELETE FROM {blocks} WHERE module = 'chatroom'");
|
| 340 |
$settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'chatroom\_%'");
|
| 341 |
while ($variable = db_fetch_object($settings)) {
|
| 342 |
variable_del($variable->name);
|
| 343 |
}
|
| 344 |
drupal_set_message($t('Chat room settings have been deleted.'));
|
| 345 |
|
| 346 |
$roles = db_query("SELECT * FROM {permission}");
|
| 347 |
require_once dirname(__FILE__) . '/chatroom.module';
|
| 348 |
$chatroom_perms = chatroom_perms();
|
| 349 |
while ($role = db_fetch_object($roles)) {
|
| 350 |
$new_perms = array();
|
| 351 |
foreach (explode(', ', $role->perm) as $perm) {
|
| 352 |
if (!in_array($perm, $chatroom_perms)) {
|
| 353 |
$new_perms[] = $perm;
|
| 354 |
}
|
| 355 |
}
|
| 356 |
db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", implode(', ', $new_perms), $role->rid);
|
| 357 |
}
|
| 358 |
drupal_set_message($t('Chat room permissions have been removed from all roles.'));
|
| 359 |
}
|
| 360 |
|
| 361 |
/**
|
| 362 |
* Implementation of hook_update_N().
|
| 363 |
*
|
| 364 |
* Updating permissions. "chatrooms" has been replaced with "chat rooms" in
|
| 365 |
* permission strings.
|
| 366 |
*/
|
| 367 |
function chatroom_update_1() {
|
| 368 |
$ret = array();
|
| 369 |
$result = db_query('SELECT rid, perm FROM {permission}');
|
| 370 |
while ($role = db_fetch_object($result)) {
|
| 371 |
$role_permissions[$role->rid] = $role->perm;
|
| 372 |
}
|
| 373 |
str_replace('access chatrooms', 'access chat rooms', $role_permissions);
|
| 374 |
str_replace('administer chatrooms', 'administer chat rooms', $role_permissions);
|
| 375 |
str_replace('create chatrooms', 'create chat rooms', $role_permissions);
|
| 376 |
str_replace('edit chatrooms', 'edit chat rooms', $role_permissions);
|
| 377 |
foreach ($role_permissions as $rid => $perm) {
|
| 378 |
$ret[] = update_sql('DELETE FROM {permission} WHERE rid = %d', $rid);
|
| 379 |
$ret[] = update_sql("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $perm);
|
| 380 |
}
|
| 381 |
return $ret;
|
| 382 |
}
|
| 383 |
|
| 384 |
/**
|
| 385 |
* Implementation of hook_update_N().
|
| 386 |
*
|
| 387 |
* Make sure each chat room has an entry in the chatroom table. Remove chats
|
| 388 |
* that are not in chat rooms. Drop the chatroom_chat_invites table.
|
| 389 |
*/
|
| 390 |
function chatroom_update_2() {
|
| 391 |
$nids = db_query("SELECT nid FROM {node} WHERE type = '%s'", 'chatroom');
|
| 392 |
$row = 0;
|
| 393 |
while ($nid = db_result($nids, $row++)) {
|
| 394 |
if (db_result(db_query("SELECT COUNT(*) FROM {chatroom} WHERE nid = %d", $nid)) == 0) {
|
| 395 |
$ret[] = update_sql("INSERT INTO {chatroom} SET nid = %d", $nid);
|
| 396 |
}
|
| 397 |
}
|
| 398 |
$ret[] = update_sql("DELETE FROM {chatroom_chat} WHERE crid = %d", 0);
|
| 399 |
db_drop_table($ret, 'chatroom_chat_invites');
|
| 400 |
return $ret;
|
| 401 |
}
|
| 402 |
|
| 403 |
/**
|
| 404 |
* Implementation of hook_update_N().
|
| 405 |
*
|
| 406 |
* Remove duplicates of rows in the chatroom_msg_archive table from the
|
| 407 |
* chatroom_msg table. Remove the chatroom_list_description variable.
|
| 408 |
*/
|
| 409 |
function chatroom_update_3() {
|
| 410 |
$ret[] = update_sql('DELETE FROM {chatroom_msg} WHERE cmid IN (SELECT cmid FROM {chatroom_msg_archive})');
|
| 411 |
variable_del('chatroom_list_description');
|
| 412 |
return $ret;
|
| 413 |
}
|
| 414 |
|
| 415 |
function chatroom_update_4() {
|
| 416 |
$ret = array();
|
| 417 |
db_change_field($ret, 'chatroom_msg', 'msg', 'msg', array(
|
| 418 |
'type' => 'text', 'size' => 'big',
|
| 419 |
'not null' => TRUE));
|
| 420 |
return $ret;
|
| 421 |
}
|
| 422 |
|
| 423 |
function chatroom_update_5() {
|
| 424 |
$t = get_t();
|
| 425 |
variable_set('chatroom_guest_user_prefix', $t('guest-'));
|
| 426 |
variable_set('comment_chatroom', variable_get('comment_chatroom', COMMENT_NODE_DISABLED));
|
| 427 |
variable_set('chatroom_block_update_interval', variable_get('chatroom_block_poll_freq', 5));
|
| 428 |
variable_del('chatroom_block_poll_freq');
|
| 429 |
variable_set('chatroom_block_chat_rooms', variable_get('chatroom_block_chatrooms', 5));
|
| 430 |
variable_del('chatroom_block_chatrooms');
|
| 431 |
variable_del('chatroom_block_online_chat_users');
|
| 432 |
variable_del('chatroom_block_online_site_users');
|
| 433 |
variable_del('chatroom_block_command_list');
|
| 434 |
return array();
|
| 435 |
}
|
| 436 |
|
| 437 |
function chatroom_update_6200() {
|
| 438 |
// TODO: schema updates from #5
|
| 439 |
return array();
|
| 440 |
}
|