18 public static function install()
25 if(!$ilDB->tableExists(
'chatroom_settings'))
28 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
29 'object_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
false,
'default' => 0),
30 'room_type' => array(
'type' =>
'text',
'length' => 20,
'notnull' =>
true),
31 'allow_anonymous' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
32 'allow_custom_usernames' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
33 'enable_history' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
34 'restrict_history' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
35 'autogen_usernames' => array(
'type' =>
'text',
'length' => 50,
'notnull' =>
false,
'default' =>
'Anonymous #'),
36 'allow_private_rooms' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
false,
'default' => 0),
39 $ilDB->createTable(
'chatroom_settings', $fields);
40 $ilDB->addPrimaryKey(
'chatroom_settings', array(
'room_id'));
41 $ilDB->createSequence(
'chatroom_settings');
44 if(!$ilDB->tableExists(
'chatroom_users'))
47 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
48 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
49 'userdata' => array(
'type' =>
'text',
'length' => 4000,
'notnull' =>
true),
50 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
52 $ilDB->createTable(
'chatroom_users', $fields);
53 $ilDB->addPrimaryKey(
'chatroom_users', array(
'room_id',
'user_id'));
56 if(!$ilDB->tableExists(
'chatroom_sessions'))
59 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
60 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
61 'userdata' => array(
'type' =>
'text',
'length' => 4000,
'notnull' =>
true),
62 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
63 'disconnected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
65 $ilDB->createTable(
'chatroom_sessions', $fields);
68 if(!$ilDB->tableExists(
'chatroom_history'))
71 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
72 'message' => array(
'type' =>
'text',
'length' => 4000,
'notnull' =>
true),
73 'timestamp' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
75 $ilDB->createTable(
'chatroom_history', $fields);
78 if(!$ilDB->tableExists(
'chatroom_bans'))
81 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
82 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
83 'timestamp' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
84 'remark' => array(
'type' =>
'text',
'length' => 1000,
'notnull' =>
false),
86 $ilDB->createTable(
'chatroom_bans', $fields);
89 if(!$ilDB->tableExists(
'chatroom_admconfig'))
92 'instance_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
93 'server_settings' => array(
'type' =>
'text',
'length' => 2000,
'notnull' =>
true),
94 'default_config' => array(
'type' =>
'integer',
'length' => 1,
'notnull' =>
true,
'default' => 0),
96 $ilDB->createTable(
'chatroom_admconfig', $fields);
97 $ilDB->addPrimaryKey(
'chatroom_admconfig', array(
'instance_id'));
98 $ilDB->createSequence(
'chatroom_admconfig');
101 if(!$ilDB->tableExists(
'chatroom_prooms'))
104 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
105 'parent_id' => array(
'type' =>
'text',
'length' => 2000,
'notnull' =>
true),
106 'title' => array(
'type' =>
'text',
'length' => 200,
'notnull' =>
true,
'default' => 0),
107 'owner' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true,
'default' => 0),
108 'created' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true,
'default' => 0),
109 'closed' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
false,
'default' => 0),
111 $ilDB->createTable(
'chatroom_prooms', $fields);
112 $ilDB->addPrimaryKey(
'chatroom_prooms', array(
'proom_id'));
113 $ilDB->createSequence(
'chatroom_prooms');
116 if(!$ilDB->tableExists(
'chatroom_psessions'))
119 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
120 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
121 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
122 'disconnected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
124 $ilDB->createTable(
'chatroom_psessions', $fields);
127 if(!$ilDB->tableExists(
'chatroom_uploads'))
130 'upload_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
131 'room_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
132 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
133 'filename' => array(
'type' =>
'text',
'length' => 200,
'notnull' =>
true),
134 'filetype' => array(
'type' =>
'text',
'length' => 200,
'notnull' =>
true),
135 'timestamp' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true)
137 $ilDB->createTable(
'chatroom_uploads', $fields);
138 $ilDB->addPrimaryKey(
'chatroom_uploads', array(
'upload_id'));
139 $ilDB->createSequence(
'chatroom_uploads');
142 if(!$ilDB->tableColumnExists(
'chatroom_prooms',
'is_public'))
144 $ilDB->addTableColumn(
'chatroom_prooms',
'is_public', array(
'type' =>
'integer',
'default' => 1,
'length' => 1));
147 if(!$ilDB->tableExists(
'chatroom_psessions'))
150 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
151 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
152 'connected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
153 'disconnected' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
155 $ilDB->createTable(
'chatroom_psessions', $fields);
158 if(!$ilDB->tableExists(
'chatroom_proomaccess'))
161 'proom_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
162 'user_id' => array(
'type' =>
'integer',
'length' => 4,
'notnull' =>
true),
164 $ilDB->createTable(
'chatroom_proomaccess', $fields);
167 if(!$ilDB->tableColumnExists(
'chatroom_admconfig',
'client_settings'))
169 $ilDB->addTableColumn(
170 "chatroom_admconfig",
"client_settings",
179 if(!$ilDB->tableExists(
'chatroom_smilies'))
182 'smiley_id' => array(
186 'smiley_keywords' => array(
190 'smiley_path' => array(
196 $ilDB->createTable(
'chatroom_smilies', $fields);
197 $ilDB->addPrimaryKey(
'chatroom_smilies', array(
'smiley_id'));
198 $ilDB->createSequence(
'chatroom_smilies');
201 self::registerObject();
202 self::registerAdminObject();
204 self::removeOldChatEntries();
205 self::convertChatObjects();
208 $notificationSettings =
new ilSetting(
'notifications');
209 $notificationSettings->set(
'enable_osd',
true);
212 public static function removeOldChatEntries()
219 $res = $ilDB->queryF(
220 'SELECT object_data.obj_id, ref_id, lft, rgt
222 INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
223 INNER JOIN tree ON child = ref_id
232 $res = $ilDB->queryF(
'SELECT * FROM tree
233 INNER JOIN object_reference ON ref_id = child
234 INNER JOIN object_data ON object_data.obj_id = object_reference.obj_id
235 WHERE lft BETWEEN %s AND %s', array(
'integer',
'integer'), array(
$data[
'lft'],
$data[
'rgt']));
236 while(
$row = $ilDB->fetchAssoc(
$res))
241 WHERE obj_id = ' . $ilDB->quote(
$row[
'obj_id'],
'integer')
246 FROM object_reference
247 WHERE ref_id = ' . $ilDB->quote(
$row[
'ref_id'],
'integer')
253 WHERE child = ' . $ilDB->quote(
$row[
'ref_id'],
'integer')
258 $ilDB->manipulateF(
'DELETE FROM object_data WHERE type = %s AND title = %s', array(
'text',
'text'), array(
'typ',
'chat'));
259 $ilDB->manipulateF(
'DELETE FROM object_data WHERE type = %s AND title = %s', array(
'text',
'text'), array(
'typ',
'chac'));
262 public static function createDefaultPublicRoom($force =
false)
271 $query =
'DELETE FROM chatroom_settings WHERE room_type = ' . $ilDB->quote(
'default',
'text');
272 $ilDB->manipulate(
$query);
277 $query =
'SELECT * FROM chatroom_settings WHERE room_type = ' . $ilDB->quote(
'default',
'text');
278 $rset = $ilDB->query(
$query);
279 $create = !$ilDB->fetchAssoc($rset);
283 require_once
'Modules/Chatroom/classes/class.ilObjChatroom.php';
286 $newObj->setType(
'chtr');
287 $newObj->setTitle(
'Public Chat');
288 $newObj->setDescription(
'');
290 $newObj->createReference();
291 $newObj->putInTree(1);
292 $newObj->setPermissions(1);
294 $obj_id = $newObj->getId();
297 $id = $ilDB->nextId(
'chatroom_settings');
301 'room_id' => array(
'integer', $id),
302 'object_id' => array(
'integer', $obj_id),
303 'room_type' => array(
'text',
'default'),
304 'allow_anonymous' => array(
'integer', 0),
305 'allow_custom_usernames' => array(
'integer', 0),
306 'enable_history' => array(
'integer', 0),
307 'restrict_history' => array(
'integer', 0),
308 'autogen_usernames' => array(
'text',
'Anonymous #'),
309 'allow_private_rooms' => array(
'integer', 1),
314 $settings->set(
'public_room_ref',
$ref_id);
322 public static function registerObject()
331 $query =
'SELECT obj_id FROM object_data ' .
332 'WHERE type = ' . $ilDB->quote(
'typ',
'text') .
' ' .
333 'AND title = ' . $ilDB->quote(
'chtr',
'text');
334 if(!($object_definition_row = $ilDB->fetchAssoc($ilDB->query(
$query))))
336 $typ_id = $ilDB->nextId(
'object_data');
340 'obj_id' => array(
'integer', $typ_id),
341 'type' => array(
'text',
'typ'),
342 'title' => array(
'text',
'chtr'),
343 'description' => array(
'text',
'Chatroom Object'),
344 'owner' => array(
'integer', -1),
345 'create_date' => array(
'timestamp', date(
'Y-m-d H:i:s')),
346 'last_update' => array(
'timestamp', date(
'Y-m-d H:i:s'))
352 foreach(array(1, 2, 3, 4) as $ops_id)
354 $query =
"INSERT INTO rbac_ta (typ_id, ops_id) VALUES ( " .
355 $ilDB->quote($typ_id,
'integer') .
"," . $ilDB->quote($ops_id,
'integer') .
357 $ilDB->manipulate(
$query);
361 if($moderatePermissionId = self::getModeratorPermissionId())
365 $typ_id = $object_definition_row[
'obj_id'];
371 'DELETE FROM rbac_ta WHERE typ_id = %s AND ops_id = %s',
372 array(
'integer',
'integer'),
373 array($typ_id, $moderatePermissionId)
379 'typ_id' => array(
'integer', $typ_id),
380 'ops_id' => array(
'integer', $moderatePermissionId),
387 private static function getModeratorPermissionId()
394 $rset = $ilDB->queryF(
395 'SELECT ops_id FROM rbac_operations WHERE operation = %s',
399 if(
$row = $ilDB->fetchAssoc($rset))
401 return $row[
'ops_id'];
410 public static function registerAdminObject()
417 $query =
'SELECT * FROM object_data WHERE type = ' . $ilDB->quote(
'chta',
'text');
418 if(!$ilDB->fetchAssoc($ilDB->query(
$query)))
420 $obj_id = $ilDB->nextId(
'object_data');
424 'obj_id' => array(
'integer', $obj_id),
425 'type' => array(
'text',
'chta'),
426 'title' => array(
'text',
'Chatroom Admin'),
427 'description' => array(
'text',
'Chatroom General Settings'),
428 'owner' => array(
'integer', -1),
429 'create_date' => array(
'timestamp', date(
'Y-m-d H:i:s')),
430 'last_update' => array(
'timestamp', date(
'Y-m-d H:i:s'))
434 $ref_id = $ilDB->nextId(
'object_reference');
435 $query =
"INSERT INTO object_reference (ref_id, obj_id) VALUES(" . $ilDB->quote(
$ref_id,
'integer') .
", " . $ilDB->quote($obj_id,
'integer') .
")";
436 $ilDB->manipulate(
$query);
438 $tree =
new ilTree(ROOT_FOLDER_ID);
439 $tree->insertNode(
$ref_id, SYSTEM_FOLDER_ID);
449 if(is_array($obj_ids))
451 foreach($obj_ids as $obj_id)
454 $room->saveSettings(array(
455 'object_id' => $obj_id,
456 'autogen_usernames' =>
'Autogen #',
457 'room_type' =>
'repository'
466 public static function convertChatObjects()
473 $res = $ilDB->queryF(
483 while(
$row = $ilDB->fetchAssoc(
$res))
485 $obj_ids[] =
$row[
'obj_id'];
492 array(
'text',
'text'),
493 array(
'chtr',
'chat')
499 public static function createMissinRoomSettingsForConvertedObjects()
506 $res = $ilDB->queryF(
507 "SELECT obj_id FROM object_data
508 LEFT JOIN chatroom_settings ON object_id = obj_id
510 AND room_id IS NULL",
515 $roomsToFix = array();
516 while(
$row = $ilDB->fetchAssoc(
$res))
518 $roomsToFix[] =
$row[
'obj_id'];