/[drupal]/contributions/modules/chatroom/chatroom.install
ViewVC logotype

Contents of /contributions/modules/chatroom/chatroom.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.27 - (show annotations) (download) (as text)
Fri Nov 6 16:56:18 2009 UTC (2 weeks, 4 days ago) by justinrandell
Branch: MAIN
Changes since 1.26: +111 -5 lines
File MIME type: text/x-php
sync up HEAD with 6.x-2 BETA 1
1 <?php
2 // $Id: chatroom.install,v 1.25.4.7 2009/11/04 20:16:56 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 'crbid' => array(
69 'type' => 'serial',
70 'unsigned' => TRUE,
71 'not null' => TRUE,
72 ),
73 'nid' => array(
74 'type' => 'int',
75 'not null' => TRUE,
76 'description' => t('Chatroom ID.'),
77 ),
78 'uid' => array(
79 'type' => 'int',
80 'not null' => TRUE,
81 'description' => t('ID of the banned user.'),
82 ),
83 'admin_uid' => array(
84 'type' => 'int',
85 'not null' => TRUE,
86 'description' => t('ID of the chatroom admin who imposed the ban.'),
87 ),
88 'modified' => array(
89 'type' => 'int',
90 'not null' => TRUE,
91 'default' => 0,
92 'description' => t('UNIX timestamp of when the ban was imposed.'),
93 ),
94 ),
95 'primary key' => array('crbid'),
96 'indexes' => array(
97 'admin_uid' => array('admin_uid'),
98 'nid' => array('nid'),
99 'uid' => array('uid'),
100 ),
101 );
102 $schema['chatroom_chat_ban_list'] = array(
103 'fields' => array(
104 'ccbid' => array(
105 'type' => 'serial',
106 'unsigned' => TRUE,
107 'not null' => TRUE,
108 ),
109 'nid' => array(
110 'type' => 'int',
111 'not null' => TRUE,
112 'description' => t('Chat ID.'),
113 ),
114 'uid' => array(
115 'type' => 'int',
116 'not null' => TRUE,
117 'description' => t('ID of the banned user.'),
118 ),
119 'admin_uid' => array(
120 'type' => 'int',
121 'not null' => TRUE,
122 'description' => t('ID of the chatroom admin who imposed the ban.'),
123 ),
124 'modified' => array(
125 'type' => 'int',
126 'not null' => TRUE,
127 'default' => 0,
128 'description' => t('UNIX timestamp of when the ban was imposed.'),
129 ),
130 ),
131 'primary key' => array('ccbid'),
132 'indexes' => array(
133 'admin_uid' => array('admin_uid'),
134 'nid' => array('nid'),
135 'uid' => array('uid'),
136 ),
137 );
138 $schema['chatroom_chat_kicked_list'] = array(
139 'fields' => array(
140 'cckid' => array(
141 'type' => 'serial',
142 'unsigned' => TRUE,
143 'not null' => TRUE,
144 ),
145 'nid' => array(
146 'type' => 'int',
147 'not null' => TRUE,
148 'description' => t('Chat ID.'),
149 ),
150 'uid' => array(
151 'type' => 'int',
152 'not null' => TRUE,
153 'description' => t('ID of the kicked out user.'),
154 ),
155 'admin_uid' => array(
156 'type' => 'int',
157 'not null' => TRUE,
158 'description' => t('ID of the chatroom admin who kicked the user out.'),
159 ),
160 'modified' => array(
161 'type' => 'int',
162 'not null' => TRUE,
163 'default' => 0,
164 'description' => t('UNIX timestamp of when the kick happened.'),
165 ),
166 ),
167 'primary key' => array('cckid'),
168 'indexes' => array(
169 'admin_uid' => array('admin_uid'),
170 'nid' => array('nid'),
171 'uid' => array('uid'),
172 ),
173 );
174 $schema['chatroom_chat'] = array(
175 'fields' => array(
176 'nid' => array(
177 'type' => 'int',
178 'not null' => TRUE,
179 'description' => t('Primary key: node ID of the chat.'),
180 ),
181 'crid' => array(
182 'type' => 'int',
183 'not null' => TRUE,
184 'default' => 0,
185 'description' => t('ID of the chatroom the chat belongs to. 0 signifies this chat does not belong to a room.'),
186 ),
187 'poll_freq' => array(
188 'type' => 'int',
189 'not null' => TRUE,
190 'default' => 1000,
191 'description' => t('Polling interval, in milliseconds, of the chat.'),
192 ),
193 'idle_freq' => array(
194 'type' => 'int',
195 'not null' => TRUE,
196 'default' => 60000,
197 'description' => t('Idle interval, in milliseconds, of the chat.'),
198 ),
199 'kicked_out_message' => array(
200 'type' => 'text',
201 'size' => 'big',
202 'description' => t('Message sent to users kicked from the chat.'),
203 ),
204 'banned_message' => array(
205 'type' => 'text',
206 'size' => 'big',
207 'description' => t('Message sent to users banned from the chat.'),
208 ),
209 'module' => array(
210 'type' => 'varchar',
211 'length' => '255',
212 'default' => 'chatroom',
213 'description' => t('The module that owns this chat.'),
214 ),
215 'previous_messages_display_count' => array(
216 'type' => 'int',
217 'default' => 20,
218 'description' => t('The number of previous messages to display to a user when they first enter a chat.'),
219 ),
220 'when_archived' => array(
221 'type' => 'int',
222 'description' => t('UNIX timestamp of when the chat was last archived.'),
223 ),
224 'popout' => array(
225 'type' => 'int',
226 'default' => 0,
227 'description' => t('Whether to load this chat in a popout window.'),
228 ),
229 'profile_picture' => array(
230 'type' => 'int',
231 'default' => 0,
232 'description' => t('Whether to display user profile pictures in online lists for this chat.'),
233 ),
234 'private' => array(
235 'type' => 'int',
236 'default' => 0,
237 'description' => t('Whether this is a private chat.'),
238 ),
239 ),
240 'indexes' => array(
241 'crid' => array('crid'),
242 ),
243 'primary key' => array('nid'),
244 );
245 $schema['chatroom_chat_user'] = array(
246 'fields' => array(
247 'nid' => array(
248 'type' => 'int',
249 'not null' => TRUE,
250 'description' => t('Primary key: node ID of the chat.'),
251 ),
252 'uid' => array(
253 'type' => 'int',
254 'not null' => TRUE,
255 'description' => t('ID of the user allowed in this chat.'),
256 ),
257 ),
258 'indexes' => array(
259 'nid' => array('nid'),
260 'uid' => array('uid'),
261 ),
262 );
263 $schema['chatroom_msg'] = array(
264 'fields' => array(
265 'cmid' => array(
266 'type' => 'serial',
267 'unsigned' => TRUE,
268 'not null' => TRUE,
269 ),
270 'ccid' => array(
271 'type' => 'int',
272 'not null' => TRUE,
273 'default' => 0,
274 ),
275 'uid' => array(
276 'type' => 'int',
277 'not null' => TRUE,
278 'default' => 0,
279 ),
280 'msg_type' => array(
281 'type' => 'varchar',
282 'length' => '64',
283 'not null' => TRUE,
284 ),
285 'msg' => array(
286 'type' => 'text',
287 'size' => 'big',
288 ),
289 'sid' => array(
290 'type' => 'varchar',
291 'length' => '64',
292 'not null' => TRUE,
293 ),
294 'recipient_uid' => array(
295 'type' => 'int',
296 'not null' => TRUE,
297 'default' => 0,
298 ),
299 'modified' => array(
300 'type' => 'int',
301 'not null' => TRUE,
302 'default' => 0,
303 ),
304 ),
305 'indexes' => array(
306 'ccid' => array('ccid'),
307 'modified' => array('modified'),
308 'recipient_uid' => array('recipient_uid'),
309 'sid' => array('sid')
310 ),
311 'primary key' => array('cmid'),
312 );
313 $schema['chatroom_chat_online_list'] = array(
314 'fields' => array(
315 'ccid' => array(
316 'type' => 'int',
317 'not null' => TRUE,
318 'description' => t('Chat ID.'),
319 ),
320 'uid' => array(
321 'type' => 'int',
322 'not null' => TRUE,
323 'default' => 0,
324 ),
325 'guest_id' => array(
326 'type' => 'int',
327 'not null' => TRUE,
328 'default' => 0,
329 ),
330 'sid' => array(
331 'type' => 'varchar',
332 'length' => '64',
333 'not null' => TRUE,
334 'description' => t('Session ID.'),
335 ),
336 'away' => array(
337 'type' => 'int',
338 'default' => 0,
339 'description' => t('Boolean: whether the user is away.'),
340 ),
341 'last_seen_time' => array(
342 'type' => 'int',
343 'not null' => TRUE,
344 'default' => 0,
345 'description' => t('UNIX timestamp of when the user was last seen.'),
346 ),
347 ),
348 'primary key' => array('ccid', 'sid'),
349 'indexes' => array(
350 'uid' => array('uid'),
351 'guest_id' => array('guest_id'),
352 ),
353 );
354 $schema['chatroom_chat_invite'] = array(
355 'fields' => array(
356 'cciid' => array(
357 'type' => 'serial',
358 'unsigned' => TRUE,
359 'not null' => TRUE,
360 ),
361 'nid' => array(
362 'type' => 'int',
363 'not null' => TRUE,
364 'description' => t('Chat ID.'),
365 ),
366 'inviter_uid' => array(
367 'type' => 'int',
368 'not null' => TRUE,
369 'default' => 0,
370 ),
371 'invitee_uid' => array(
372 'type' => 'int',
373 'not null' => TRUE,
374 'default' => 0,
375 ),
376 'notified' => array(
377 'type' => 'int',
378 'not null' => TRUE,
379 'default' => 0,
380 ),
381 'accepted' => array(
382 'type' => 'int',
383 'not null' => TRUE,
384 'default' => 0,
385 ),
386 ),
387 'primary key' => array('cciid'),
388 'indexes' => array(
389 'inviter_uid' => array('inviter_uid'),
390 'invitee_uid' => array('invitee_uid'),
391 'nid' => array('nid'),
392 'notified' => array('notified'),
393 'accepted' => array('accepted'),
394 ),
395 );
396 return $schema;
397 }
398
399 /**
400 * Implementation of hook_requirements().
401 */
402 function chatroom_requirements($phase) {
403 $requirements = array();
404 if ($GLOBALS['db_type'] == 'mysql' && version_compare(db_version(), '4.1') < 0) {
405 $t = get_t();
406 $requirements['chatroom'] = array(
407 'title' => $t('Chat Room'),
408 'value' => $t('Your MySQL version is too low. Chat Room requires MySQL 4.1 or higher.'),
409 'chatroom' => REQUIREMENT_ERROR,
410 );
411 }
412 return $requirements;
413 }
414
415 /**
416 * Implementation of hook_install().
417 */
418 function chatroom_install() {
419 drupal_install_schema('chatroom');
420
421 if (function_exists('block_rehash')) {
422 _block_rehash();
423 }
424
425 drupal_set_message(t('Chat room module enabled.'));
426 }
427
428 /**
429 * Implementation of hook_uninstall().
430 */
431 function chatroom_uninstall() {
432 $t = get_t();
433 $result = db_query("SELECT nid FROM {node} WHERE type = 'chatroom' OR type = 'chat'");
434 while ($chat_room_node = db_fetch_object($result)) {
435 node_delete($chat_room_node->nid);
436 }
437 drupal_set_message($t('Chat room nodes have been deleted from the database.'));
438
439 drupal_uninstall_schema('chatroom');
440 drupal_set_message($t('Chat room tables have been dropped from the database.'));
441
442 db_query("DELETE FROM {blocks} WHERE module = 'chatroom'");
443 $settings = db_query("SELECT name FROM {variable} WHERE name LIKE 'chatroom\_%'");
444 while ($variable = db_fetch_object($settings)) {
445 variable_del($variable->name);
446 }
447 drupal_set_message($t('Chat room settings have been deleted.'));
448
449 $roles = db_query("SELECT * FROM {permission}");
450 require_once dirname(__FILE__) . '/chatroom.module';
451 $chatroom_perms = chatroom_perms();
452 while ($role = db_fetch_object($roles)) {
453 $new_perms = array();
454 foreach (explode(', ', $role->perm) as $perm) {
455 if (!in_array($perm, $chatroom_perms)) {
456 $new_perms[] = $perm;
457 }
458 }
459 db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", implode(', ', $new_perms), $role->rid);
460 }
461 drupal_set_message($t('Chat room permissions have been removed from all roles.'));
462 }
463
464 /**
465 * Implementation of hook_update_N().
466 *
467 * Updating permissions. "chatrooms" has been replaced with "chat rooms" in
468 * permission strings.
469 */
470 function chatroom_update_1() {
471 $ret = array();
472 $result = db_query('SELECT rid, perm FROM {permission}');
473 while ($role = db_fetch_object($result)) {
474 $role_permissions[$role->rid] = $role->perm;
475 }
476 str_replace('access chatrooms', 'access chat rooms', $role_permissions);
477 str_replace('administer chatrooms', 'administer chat rooms', $role_permissions);
478 str_replace('create chatrooms', 'create chat rooms', $role_permissions);
479 str_replace('edit chatrooms', 'edit chat rooms', $role_permissions);
480 foreach ($role_permissions as $rid => $perm) {
481 $ret[] = update_sql('DELETE FROM {permission} WHERE rid = %d', $rid);
482 $ret[] = update_sql("INSERT INTO {permission} (rid, perm) VALUES (%d, '%s')", $rid, $perm);
483 }
484 return $ret;
485 }
486
487 /**
488 * Implementation of hook_update_N().
489 *
490 * Make sure each chat room has an entry in the chatroom table. Remove chats
491 * that are not in chat rooms. Drop the chatroom_chat_invites table.
492 */
493 function chatroom_update_2() {
494 $nids = db_query("SELECT nid FROM {node} WHERE type = '%s'", 'chatroom');
495 $row = 0;
496 while ($nid = db_result($nids, $row++)) {
497 if (db_result(db_query("SELECT COUNT(*) FROM {chatroom} WHERE nid = %d", $nid)) == 0) {
498 $ret[] = update_sql("INSERT INTO {chatroom} SET nid = %d", $nid);
499 }
500 }
501 $ret[] = update_sql("DELETE FROM {chatroom_chat} WHERE crid = %d", 0);
502 db_drop_table($ret, 'chatroom_chat_invites');
503 return $ret;
504 }
505
506 /**
507 * Implementation of hook_update_N().
508 *
509 * Remove duplicates of rows in the chatroom_msg_archive table from the
510 * chatroom_msg table. Remove the chatroom_list_description variable.
511 */
512 function chatroom_update_3() {
513 $ret[] = update_sql('DELETE FROM {chatroom_msg} WHERE cmid IN (SELECT cmid FROM {chatroom_msg_archive})');
514 variable_del('chatroom_list_description');
515 return $ret;
516 }
517
518 function chatroom_update_4() {
519 $ret = array();
520 db_change_field($ret, 'chatroom_msg', 'msg', 'msg', array(
521 'type' => 'text', 'size' => 'big',
522 'not null' => TRUE));
523 return $ret;
524 }
525
526 function chatroom_update_5() {
527 $t = get_t();
528 variable_set('chatroom_guest_user_prefix', $t('guest-'));
529 variable_set('comment_chatroom', variable_get('comment_chatroom', COMMENT_NODE_DISABLED));
530 variable_set('chatroom_block_update_interval', variable_get('chatroom_block_poll_freq', 5));
531 variable_del('chatroom_block_poll_freq');
532 variable_set('chatroom_block_chat_rooms', variable_get('chatroom_block_chatrooms', 5));
533 variable_del('chatroom_block_chatrooms');
534 variable_del('chatroom_block_online_chat_users');
535 variable_del('chatroom_block_online_site_users');
536 variable_del('chatroom_block_command_list');
537 return array();
538 }
539
540 /**
541 * Run the update from the 6.x-1 branch to 6.x-2.
542 */
543 function chatroom_update_6200() {
544 return array();
545 }
546

  ViewVC Help
Powered by ViewVC 1.1.2