ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilChatroomInstaller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
11 {
17  public static function install()
18  {
22  global $ilDB;
23 
24  if (!$ilDB->tableExists('chatroom_settings')) {
25  $fields = array(
26  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
27  'object_id' => array('type' => 'integer', 'length' => 4, 'notnull' => false, 'default' => 0),
28  'room_type' => array('type' => 'text', 'length' => 20, 'notnull' => true),
29  'allow_anonymous' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
30  'allow_custom_usernames' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
31  'enable_history' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
32  'restrict_history' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
33  'autogen_usernames' => array('type' => 'text', 'length' => 50, 'notnull' => false, 'default' => 'Anonymous #'),
34  'allow_private_rooms' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
35  );
36 
37  $ilDB->createTable('chatroom_settings', $fields);
38  $ilDB->addPrimaryKey('chatroom_settings', array('room_id'));
39  $ilDB->createSequence('chatroom_settings');
40  }
41 
42  if (!$ilDB->tableExists('chatroom_users')) {
43  $fields = array(
44  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
45  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
46  'userdata' => array('type' => 'text', 'length' => 4000, 'notnull' => true),
47  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
48  );
49  $ilDB->createTable('chatroom_users', $fields);
50  $ilDB->addPrimaryKey('chatroom_users', array('room_id', 'user_id'));
51  }
52 
53  if (!$ilDB->tableExists('chatroom_sessions')) {
54  $fields = array(
55  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
56  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
57  'userdata' => array('type' => 'text', 'length' => 4000, 'notnull' => true),
58  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
59  'disconnected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
60  );
61  $ilDB->createTable('chatroom_sessions', $fields);
62  }
63 
64  if (!$ilDB->tableExists('chatroom_history')) {
65  $fields = array(
66  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
67  'message' => array('type' => 'text', 'length' => 4000, 'notnull' => true),
68  'timestamp' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
69  );
70  $ilDB->createTable('chatroom_history', $fields);
71  }
72 
73  if (!$ilDB->tableExists('chatroom_bans')) {
74  $fields = array(
75  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
76  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
77  'timestamp' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
78  'remark' => array('type' => 'text', 'length' => 1000, 'notnull' => false),
79  );
80  $ilDB->createTable('chatroom_bans', $fields);
81  }
82 
83  if (!$ilDB->tableExists('chatroom_admconfig')) {
84  $fields = array(
85  'instance_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
86  'server_settings' => array('type' => 'text', 'length' => 2000, 'notnull' => true),
87  'default_config' => array('type' => 'integer', 'length' => 1, 'notnull' => true, 'default' => 0),
88  );
89  $ilDB->createTable('chatroom_admconfig', $fields);
90  $ilDB->addPrimaryKey('chatroom_admconfig', array('instance_id'));
91  $ilDB->createSequence('chatroom_admconfig');
92  }
93 
94  if (!$ilDB->tableExists('chatroom_prooms')) {
95  $fields = array(
96  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
97  'parent_id' => array('type' => 'text', 'length' => 2000, 'notnull' => true),
98  'title' => array('type' => 'text', 'length' => 200, 'notnull' => true, 'default' => 0),
99  'owner' => array('type' => 'integer', 'length' => 4, 'notnull' => true, 'default' => 0),
100  'created' => array('type' => 'integer', 'length' => 4, 'notnull' => true, 'default' => 0),
101  'closed' => array('type' => 'integer', 'length' => 4, 'notnull' => false, 'default' => 0),
102  );
103  $ilDB->createTable('chatroom_prooms', $fields);
104  $ilDB->addPrimaryKey('chatroom_prooms', array('proom_id'));
105  $ilDB->createSequence('chatroom_prooms');
106  }
107 
108  if (!$ilDB->tableExists('chatroom_psessions')) {
109  $fields = array(
110  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
111  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
112  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
113  'disconnected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
114  );
115  $ilDB->createTable('chatroom_psessions', $fields);
116  }
117 
118  if (!$ilDB->tableExists('chatroom_uploads')) {
119  $fields = array(
120  'upload_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
121  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
122  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
123  'filename' => array('type' => 'text', 'length' => 200, 'notnull' => true),
124  'filetype' => array('type' => 'text', 'length' => 200, 'notnull' => true),
125  'timestamp' => array('type' => 'integer', 'length' => 4, 'notnull' => true)
126  );
127  $ilDB->createTable('chatroom_uploads', $fields);
128  $ilDB->addPrimaryKey('chatroom_uploads', array('upload_id'));
129  $ilDB->createSequence('chatroom_uploads');
130  }
131 
132  if (!$ilDB->tableColumnExists('chatroom_prooms', 'is_public')) {
133  $ilDB->addTableColumn('chatroom_prooms', 'is_public', array('type' => 'integer', 'default' => 1, 'length' => 1));
134  }
135 
136  if (!$ilDB->tableExists('chatroom_psessions')) {
137  $fields = array(
138  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
139  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
140  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
141  'disconnected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
142  );
143  $ilDB->createTable('chatroom_psessions', $fields);
144  }
145 
146  if (!$ilDB->tableExists('chatroom_proomaccess')) {
147  $fields = array(
148  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
149  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
150  );
151  $ilDB->createTable('chatroom_proomaccess', $fields);
152  }
153 
154  if (!$ilDB->tableColumnExists('chatroom_admconfig', 'client_settings')) {
155  $ilDB->addTableColumn(
156  "chatroom_admconfig",
157  "client_settings",
158  array(
159  "type" => "text",
160  "length" => 1000,
161  "notnull" => true
162  )
163  );
164  }
165 
166  if (!$ilDB->tableExists('chatroom_smilies')) {
167  $fields = array(
168  'smiley_id' => array(
169  'type' => 'integer',
170  'length' => 4,
171  ),
172  'smiley_keywords' => array(
173  'type' => 'text',
174  'length' => 100,
175  ),
176  'smiley_path' => array(
177  'type' => 'text',
178  'length' => 200,
179  )
180  );
181 
182  $ilDB->createTable('chatroom_smilies', $fields);
183  $ilDB->addPrimaryKey('chatroom_smilies', array('smiley_id'));
184  $ilDB->createSequence('chatroom_smilies');
185  }
186 
187  self::registerObject();
188  self::registerAdminObject();
189  self::removeOldChatEntries();
190  self::convertChatObjects();
191 
192  $notificationSettings = new ilSetting('notifications');
193  $notificationSettings->set('enable_osd', true);
194  }
195 
200  public static function registerObject()
201  {
205  global $ilDB;
206 
207  $typ_id = null;
208 
209  $query = 'SELECT obj_id FROM object_data ' .
210  'WHERE type = ' . $ilDB->quote('typ', 'text') . ' ' .
211  'AND title = ' . $ilDB->quote('chtr', 'text');
212  if (!($object_definition_row = $ilDB->fetchAssoc($ilDB->query($query)))) {
213  $typ_id = $ilDB->nextId('object_data');
214  $ilDB->insert(
215  'object_data',
216  array(
217  'obj_id' => array('integer', $typ_id),
218  'type' => array('text', 'typ'),
219  'title' => array('text', 'chtr'),
220  'description' => array('text', 'Chatroom Object'),
221  'owner' => array('integer', -1),
222  'create_date' => array('timestamp', date('Y-m-d H:i:s')),
223  'last_update' => array('timestamp', date('Y-m-d H:i:s'))
224  )
225  );
226 
227  // REGISTER RBAC OPERATIONS FOR OBJECT TYPE
228  // 1: edit_permissions, 2: visible, 3: read, 4:write
229  foreach (array(1, 2, 3, 4) as $ops_id) {
230  $query = "INSERT INTO rbac_ta (typ_id, ops_id) VALUES ( " .
231  $ilDB->quote($typ_id, 'integer') . "," . $ilDB->quote($ops_id, 'integer') .
232  ")";
233  $ilDB->manipulate($query);
234  }
235  }
236 
237  if ($moderatePermissionId = self::getModeratorPermissionId()) {
238  if (!$typ_id) {
239  $typ_id = $object_definition_row['obj_id'];
240  }
241 
242  if ($typ_id) {
243  $ilDB->manipulateF(
244  'DELETE FROM rbac_ta WHERE typ_id = %s AND ops_id = %s',
245  array('integer', 'integer'),
246  array($typ_id, $moderatePermissionId)
247  );
248 
249  $ilDB->insert(
250  'rbac_ta',
251  array(
252  'typ_id' => array('integer', $typ_id),
253  'ops_id' => array('integer', $moderatePermissionId),
254  )
255  );
256  }
257  }
258  }
259 
260  private static function getModeratorPermissionId()
261  {
265  global $ilDB;
266 
267  $rset = $ilDB->queryF(
268  'SELECT ops_id FROM rbac_operations WHERE operation = %s',
269  array('text'),
270  array('moderate')
271  );
272  if ($row = $ilDB->fetchAssoc($rset)) {
273  return $row['ops_id'];
274  }
275  return 0;
276  }
277 
282  public static function registerAdminObject()
283  {
287  global $ilDB;
288 
289  $query = 'SELECT * FROM object_data WHERE type = ' . $ilDB->quote('chta', 'text');
290  if (!$ilDB->fetchAssoc($ilDB->query($query))) {
291  $obj_id = $ilDB->nextId('object_data');
292  $ilDB->insert(
293  'object_data',
294  array(
295  'obj_id' => array('integer', $obj_id),
296  'type' => array('text', 'chta'),
297  'title' => array('text', 'Chatroom Admin'),
298  'description' => array('text', 'Chatroom General Settings'),
299  'owner' => array('integer', -1),
300  'create_date' => array('timestamp', date('Y-m-d H:i:s')),
301  'last_update' => array('timestamp', date('Y-m-d H:i:s'))
302  )
303  );
304 
305  $ref_id = $ilDB->nextId('object_reference');
306  $query = "INSERT INTO object_reference (ref_id, obj_id) VALUES(" . $ilDB->quote($ref_id, 'integer') . ", " . $ilDB->quote($obj_id, 'integer') . ")";
307  $ilDB->manipulate($query);
308 
309  $tree = new ilTree(ROOT_FOLDER_ID);
310  $tree->insertNode($ref_id, SYSTEM_FOLDER_ID);
311  }
312  }
313 
314  public static function removeOldChatEntries()
315  {
319  global $ilDB;
320 
321  $res = $ilDB->queryF(
322  'SELECT object_data.obj_id, ref_id, lft, rgt
323  FROM object_data
324  INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
325  INNER JOIN tree ON child = ref_id
326  WHERE type = %s',
327  array('text'),
328  array('chac')
329  );
330 
331  $data = $ilDB->fetchAssoc($res);
332  if ($data) {
333  $res = $ilDB->queryF('SELECT * FROM tree
334  INNER JOIN object_reference ON ref_id = child
335  INNER JOIN object_data ON object_data.obj_id = object_reference.obj_id
336  WHERE lft BETWEEN %s AND %s', array('integer', 'integer'), array($data['lft'], $data['rgt']));
337  while ($row = $ilDB->fetchAssoc($res)) {
338  $ilDB->manipulate(
339  'DELETE
340  FROM object_data
341  WHERE obj_id = ' . $ilDB->quote($row['obj_id'], 'integer')
342  );
343 
344  $ilDB->manipulate(
345  'DELETE
346  FROM object_reference
347  WHERE ref_id = ' . $ilDB->quote($row['ref_id'], 'integer')
348  );
349 
350  $ilDB->manipulate(
351  'DELETE
352  FROM tree
353  WHERE child = ' . $ilDB->quote($row['ref_id'], 'integer')
354  );
355  }
356  }
357 
358  $ilDB->manipulateF('DELETE FROM object_data WHERE type = %s AND title = %s', array('text', 'text'), array('typ', 'chat'));
359  $ilDB->manipulateF('DELETE FROM object_data WHERE type = %s AND title = %s', array('text', 'text'), array('typ', 'chac'));
360  }
361 
365  public static function convertChatObjects()
366  {
370  global $ilDB;
371 
372  $res = $ilDB->queryF(
373  "SELECT obj_id
374  FROM object_data
375  WHERE type = %s",
376  array('text'),
377  array('chat')
378  );
379 
380  $obj_ids = array();
381 
382  while ($row = $ilDB->fetchAssoc($res)) {
383  $obj_ids[] = $row['obj_id'];
384  }
385 
386  $ilDB->manipulateF(
387  "UPDATE object_data
388  SET type = %s
389  WHERE type = %s",
390  array('text', 'text'),
391  array('chtr', 'chat')
392  );
393 
394  self::setChatroomSettings($obj_ids);
395  }
396 
401  public static function setChatroomSettings($obj_ids)
402  {
403  if (is_array($obj_ids)) {
404  foreach ($obj_ids as $obj_id) {
405  $room = new ilChatroom();
406  $room->saveSettings(array(
407  'object_id' => $obj_id,
408  'autogen_usernames' => 'Autogen #',
409  'room_type' => 'repository'
410  ));
411  }
412  }
413  }
414 
415  public static function createDefaultPublicRoom($force = false)
416  {
420  global $ilDB;
421 
422  if ($force) {
423  $query = 'DELETE FROM chatroom_settings WHERE room_type = ' . $ilDB->quote('default', 'text');
424  $ilDB->manipulate($query);
425  $create = true;
426  } else {
427  $query = 'SELECT * FROM chatroom_settings WHERE room_type = ' . $ilDB->quote('default', 'text');
428  $rset = $ilDB->query($query);
429  $create = !$ilDB->fetchAssoc($rset);
430  }
431  if ($create) {
432  $query = "
433  SELECT object_data.obj_id, object_reference.ref_id
434  FROM object_data
435  INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
436  WHERE type = " . $ilDB->quote('chta', 'text');
437  $rset = $ilDB->query($query);
438  $row = $ilDB->fetchAssoc($rset);
439  $chatfolder_ref_id = $row['ref_id'];
440 
441  require_once 'Modules/Chatroom/classes/class.ilObjChatroom.php';
442  $newObj = new ilObjChatroom();
443 
444  $newObj->setType('chtr');
445  $newObj->setTitle('Public Chat');
446  $newObj->setDescription('');
447  $newObj->create(); // true for upload
448  $newObj->createReference();
449  $newObj->putInTree($chatfolder_ref_id);
450  $newObj->setPermissions($chatfolder_ref_id);
451 
452  $obj_id = $newObj->getId();
453  $ref_id = $newObj->getRefId();
454 
455  $id = $ilDB->nextId('chatroom_settings');
456  $ilDB->insert(
457  'chatroom_settings',
458  array(
459  'room_id' => array('integer', $id),
460  'object_id' => array('integer', $obj_id),
461  'room_type' => array('text', 'default'),
462  'allow_anonymous' => array('integer', 0),
463  'allow_custom_usernames' => array('integer', 0),
464  'enable_history' => array('integer', 0),
465  'restrict_history' => array('integer', 0),
466  'autogen_usernames' => array('text', 'Anonymous #'),
467  'allow_private_rooms' => array('integer', 1),
468  )
469  );
470 
471  $settings = new ilSetting('chatroom');
472  $settings->set('public_room_ref', $ref_id);
473  }
474  }
475 
476  public static function createMissinRoomSettingsForConvertedObjects()
477  {
481  global $ilDB;
482 
483  $res = $ilDB->queryF(
484  "SELECT obj_id FROM object_data
485  LEFT JOIN chatroom_settings ON object_id = obj_id
486  WHERE type = %s
487  AND room_id IS NULL",
488  array('text'),
489  array('chtr')
490  );
491 
492  $roomsToFix = array();
493  while ($row = $ilDB->fetchAssoc($res)) {
494  $roomsToFix[] = $row['obj_id'];
495  }
496 
497  self::setChatroomSettings($roomsToFix);
498  }
499 
503  public static function ensureCorrectPublicChatroomTreeLocation($ref_id)
504  {
510  global $tree, $ilDB, $rbacadmin;
511 
512  $ilDB->setLimit(1);
513  $query = "
514  SELECT object_data.obj_id, object_reference.ref_id
515  FROM object_data
516  INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
517  WHERE type = " . $ilDB->quote('chta', 'text');
518  $rset = $ilDB->query($query);
519  $row = $ilDB->fetchAssoc($rset);
520  $chatfolder_ref_id = $row['ref_id'];
521  $pid = $tree->getParentId($ref_id);
522 
523  if (
524  $chatfolder_ref_id &&
525  $pid != $chatfolder_ref_id &&
526  !$tree->isDeleted($chatfolder_ref_id)
527  ) {
528  $tree->moveTree($ref_id, $chatfolder_ref_id);
529  $rbacadmin->adjustMovedObjectPermissions($ref_id, $pid);
530  include_once('./Services/AccessControl/classes/class.ilConditionHandler.php');
532  }
533  }
534 }
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilObjChatroom.
static setChatroomSettings($obj_ids)
Sets autogen_usernames default option for chatrooms.
foreach($_POST as $key=> $value) $res
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
$query
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
Class ilChatroom.
static _adjustMovedObjectConditions($a_ref_id)
In the moment it is not allowed to create preconditions on objects that are located outside of a cour...
global $ilDB
Class ilChatroomInstaller.