ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
26  $fields = array(
27  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
28  'object_id' => array('type' => 'integer', 'length' => 4, 'notnull' => false, 'default' => 0),
29  'room_type' => array('type' => 'text', 'length' => 20, 'notnull' => true),
30  'allow_anonymous' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
31  'allow_custom_usernames' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
32  'enable_history' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
33  'restrict_history' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
34  'autogen_usernames' => array('type' => 'text', 'length' => 50, 'notnull' => false, 'default' => 'Anonymous #'),
35  'allow_private_rooms' => array('type' => 'integer', 'length' => 1, 'notnull' => false, 'default' => 0),
36  );
37 
38  $ilDB->createTable('chatroom_settings', $fields);
39  $ilDB->addPrimaryKey('chatroom_settings', array('room_id'));
40  $ilDB->createSequence('chatroom_settings');
41  }
42 
43  if(!$ilDB->tableExists('chatroom_users'))
44  {
45  $fields = array(
46  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
47  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
48  'userdata' => array('type' => 'text', 'length' => 4000, 'notnull' => true),
49  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
50  );
51  $ilDB->createTable('chatroom_users', $fields);
52  $ilDB->addPrimaryKey('chatroom_users', array('room_id', 'user_id'));
53  }
54 
55  if(!$ilDB->tableExists('chatroom_sessions'))
56  {
57  $fields = array(
58  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
59  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
60  'userdata' => array('type' => 'text', 'length' => 4000, 'notnull' => true),
61  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
62  'disconnected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
63  );
64  $ilDB->createTable('chatroom_sessions', $fields);
65  }
66 
67  if(!$ilDB->tableExists('chatroom_history'))
68  {
69  $fields = array(
70  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
71  'message' => array('type' => 'text', 'length' => 4000, 'notnull' => true),
72  'timestamp' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
73  );
74  $ilDB->createTable('chatroom_history', $fields);
75  }
76 
77  if(!$ilDB->tableExists('chatroom_bans'))
78  {
79  $fields = array(
80  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
81  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
82  'timestamp' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
83  'remark' => array('type' => 'text', 'length' => 1000, 'notnull' => false),
84  );
85  $ilDB->createTable('chatroom_bans', $fields);
86  }
87 
88  if(!$ilDB->tableExists('chatroom_admconfig'))
89  {
90  $fields = array(
91  'instance_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
92  'server_settings' => array('type' => 'text', 'length' => 2000, 'notnull' => true),
93  'default_config' => array('type' => 'integer', 'length' => 1, 'notnull' => true, 'default' => 0),
94  );
95  $ilDB->createTable('chatroom_admconfig', $fields);
96  $ilDB->addPrimaryKey('chatroom_admconfig', array('instance_id'));
97  $ilDB->createSequence('chatroom_admconfig');
98  }
99 
100  if(!$ilDB->tableExists('chatroom_prooms'))
101  {
102  $fields = array(
103  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
104  'parent_id' => array('type' => 'text', 'length' => 2000, 'notnull' => true),
105  'title' => array('type' => 'text', 'length' => 200, 'notnull' => true, 'default' => 0),
106  'owner' => array('type' => 'integer', 'length' => 4, 'notnull' => true, 'default' => 0),
107  'created' => array('type' => 'integer', 'length' => 4, 'notnull' => true, 'default' => 0),
108  'closed' => array('type' => 'integer', 'length' => 4, 'notnull' => false, 'default' => 0),
109  );
110  $ilDB->createTable('chatroom_prooms', $fields);
111  $ilDB->addPrimaryKey('chatroom_prooms', array('proom_id'));
112  $ilDB->createSequence('chatroom_prooms');
113  }
114 
115  if(!$ilDB->tableExists('chatroom_psessions'))
116  {
117  $fields = array(
118  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
119  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
120  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
121  'disconnected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
122  );
123  $ilDB->createTable('chatroom_psessions', $fields);
124  }
125 
126  if(!$ilDB->tableExists('chatroom_uploads'))
127  {
128  $fields = array(
129  'upload_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
130  'room_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
131  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
132  'filename' => array('type' => 'text', 'length' => 200, 'notnull' => true),
133  'filetype' => array('type' => 'text', 'length' => 200, 'notnull' => true),
134  'timestamp' => array('type' => 'integer', 'length' => 4, 'notnull' => true)
135  );
136  $ilDB->createTable('chatroom_uploads', $fields);
137  $ilDB->addPrimaryKey('chatroom_uploads', array('upload_id'));
138  $ilDB->createSequence('chatroom_uploads');
139  }
140 
141  if(!$ilDB->tableColumnExists('chatroom_prooms', 'is_public'))
142  {
143  $ilDB->addTableColumn('chatroom_prooms', 'is_public', array('type' => 'integer', 'default' => 1, 'length' => 1));
144  }
145 
146  if(!$ilDB->tableExists('chatroom_psessions'))
147  {
148  $fields = array(
149  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
150  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
151  'connected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
152  'disconnected' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
153  );
154  $ilDB->createTable('chatroom_psessions', $fields);
155  }
156 
157  if(!$ilDB->tableExists('chatroom_proomaccess'))
158  {
159  $fields = array(
160  'proom_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
161  'user_id' => array('type' => 'integer', 'length' => 4, 'notnull' => true),
162  );
163  $ilDB->createTable('chatroom_proomaccess', $fields);
164  }
165 
166  if(!$ilDB->tableColumnExists('chatroom_admconfig', 'client_settings'))
167  {
168  $ilDB->addTableColumn(
169  "chatroom_admconfig", "client_settings",
170  array(
171  "type" => "text",
172  "length" => 1000,
173  "notnull" => true
174  )
175  );
176  }
177 
178  if(!$ilDB->tableExists('chatroom_smilies'))
179  {
180  $fields = array(
181  'smiley_id' => array(
182  'type' => 'integer',
183  'length' => 4,
184  ),
185  'smiley_keywords' => array(
186  'type' => 'text',
187  'length' => 100,
188  ),
189  'smiley_path' => array(
190  'type' => 'text',
191  'length' => 200,
192  )
193  );
194 
195  $ilDB->createTable('chatroom_smilies', $fields);
196  $ilDB->addPrimaryKey('chatroom_smilies', array('smiley_id'));
197  $ilDB->createSequence('chatroom_smilies');
198  }
199 
200  self::registerObject();
201  self::registerAdminObject();
202  self::removeOldChatEntries();
203  self::convertChatObjects();
204 
205  $notificationSettings = new ilSetting('notifications');
206  $notificationSettings->set('enable_osd', true);
207  }
208 
213  public static function registerObject()
214  {
218  global $ilDB;
219 
220  $typ_id = null;
221 
222  $query = 'SELECT obj_id FROM object_data ' .
223  'WHERE type = ' . $ilDB->quote('typ', 'text') . ' ' .
224  'AND title = ' . $ilDB->quote('chtr', 'text');
225  if(!($object_definition_row = $ilDB->fetchAssoc($ilDB->query($query))))
226  {
227  $typ_id = $ilDB->nextId('object_data');
228  $ilDB->insert(
229  'object_data',
230  array(
231  'obj_id' => array('integer', $typ_id),
232  'type' => array('text', 'typ'),
233  'title' => array('text', 'chtr'),
234  'description' => array('text', 'Chatroom Object'),
235  'owner' => array('integer', -1),
236  'create_date' => array('timestamp', date('Y-m-d H:i:s')),
237  'last_update' => array('timestamp', date('Y-m-d H:i:s'))
238  )
239  );
240 
241  // REGISTER RBAC OPERATIONS FOR OBJECT TYPE
242  // 1: edit_permissions, 2: visible, 3: read, 4:write
243  foreach(array(1, 2, 3, 4) as $ops_id)
244  {
245  $query = "INSERT INTO rbac_ta (typ_id, ops_id) VALUES ( " .
246  $ilDB->quote($typ_id, 'integer') . "," . $ilDB->quote($ops_id, 'integer') .
247  ")";
248  $ilDB->manipulate($query);
249  }
250  }
251 
252  if($moderatePermissionId = self::getModeratorPermissionId())
253  {
254  if(!$typ_id)
255  {
256  $typ_id = $object_definition_row['obj_id'];
257  }
258 
259  if($typ_id)
260  {
261  $ilDB->manipulateF(
262  'DELETE FROM rbac_ta WHERE typ_id = %s AND ops_id = %s',
263  array('integer', 'integer'),
264  array($typ_id, $moderatePermissionId)
265  );
266 
267  $ilDB->insert(
268  'rbac_ta',
269  array(
270  'typ_id' => array('integer', $typ_id),
271  'ops_id' => array('integer', $moderatePermissionId),
272  )
273  );
274  }
275  }
276  }
277 
278  private static function getModeratorPermissionId()
279  {
283  global $ilDB;
284 
285  $rset = $ilDB->queryF(
286  'SELECT ops_id FROM rbac_operations WHERE operation = %s',
287  array('text'),
288  array('moderate')
289  );
290  if($row = $ilDB->fetchAssoc($rset))
291  {
292  return $row['ops_id'];
293  }
294  return 0;
295  }
296 
301  public static function registerAdminObject()
302  {
306  global $ilDB;
307 
308  $query = 'SELECT * FROM object_data WHERE type = ' . $ilDB->quote('chta', 'text');
309  if(!$ilDB->fetchAssoc($ilDB->query($query)))
310  {
311  $obj_id = $ilDB->nextId('object_data');
312  $ilDB->insert(
313  'object_data',
314  array(
315  'obj_id' => array('integer', $obj_id),
316  'type' => array('text', 'chta'),
317  'title' => array('text', 'Chatroom Admin'),
318  'description' => array('text', 'Chatroom General Settings'),
319  'owner' => array('integer', -1),
320  'create_date' => array('timestamp', date('Y-m-d H:i:s')),
321  'last_update' => array('timestamp', date('Y-m-d H:i:s'))
322  )
323  );
324 
325  $ref_id = $ilDB->nextId('object_reference');
326  $query = "INSERT INTO object_reference (ref_id, obj_id) VALUES(" . $ilDB->quote($ref_id, 'integer') . ", " . $ilDB->quote($obj_id, 'integer') . ")";
327  $ilDB->manipulate($query);
328 
329  $tree = new ilTree(ROOT_FOLDER_ID);
330  $tree->insertNode($ref_id, SYSTEM_FOLDER_ID);
331  }
332  }
333 
334  public static function removeOldChatEntries()
335  {
339  global $ilDB;
340 
341  $res = $ilDB->queryF(
342  'SELECT object_data.obj_id, ref_id, lft, rgt
343  FROM object_data
344  INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
345  INNER JOIN tree ON child = ref_id
346  WHERE type = %s',
347  array('text'),
348  array('chac')
349  );
350 
351  $data = $ilDB->fetchAssoc($res);
352  if($data)
353  {
354  $res = $ilDB->queryF('SELECT * FROM tree
355  INNER JOIN object_reference ON ref_id = child
356  INNER JOIN object_data ON object_data.obj_id = object_reference.obj_id
357  WHERE lft BETWEEN %s AND %s', array('integer', 'integer'), array($data['lft'], $data['rgt']));
358  while($row = $ilDB->fetchAssoc($res))
359  {
360  $ilDB->manipulate(
361  'DELETE
362  FROM object_data
363  WHERE obj_id = ' . $ilDB->quote($row['obj_id'], 'integer')
364  );
365 
366  $ilDB->manipulate(
367  'DELETE
368  FROM object_reference
369  WHERE ref_id = ' . $ilDB->quote($row['ref_id'], 'integer')
370  );
371 
372  $ilDB->manipulate(
373  'DELETE
374  FROM tree
375  WHERE child = ' . $ilDB->quote($row['ref_id'], 'integer')
376  );
377  }
378  }
379 
380  $ilDB->manipulateF('DELETE FROM object_data WHERE type = %s AND title = %s', array('text', 'text'), array('typ', 'chat'));
381  $ilDB->manipulateF('DELETE FROM object_data WHERE type = %s AND title = %s', array('text', 'text'), array('typ', 'chac'));
382  }
383 
387  public static function convertChatObjects()
388  {
392  global $ilDB;
393 
394  $res = $ilDB->queryF(
395  "SELECT obj_id
396  FROM object_data
397  WHERE type = %s",
398  array('text'),
399  array('chat')
400  );
401 
402  $obj_ids = array();
403 
404  while($row = $ilDB->fetchAssoc($res))
405  {
406  $obj_ids[] = $row['obj_id'];
407  }
408 
409  $ilDB->manipulateF(
410  "UPDATE object_data
411  SET type = %s
412  WHERE type = %s",
413  array('text', 'text'),
414  array('chtr', 'chat')
415  );
416 
417  self::setChatroomSettings($obj_ids);
418  }
419 
424  public static function setChatroomSettings($obj_ids)
425  {
426  if(is_array($obj_ids))
427  {
428  foreach($obj_ids as $obj_id)
429  {
430  $room = new ilChatroom();
431  $room->saveSettings(array(
432  'object_id' => $obj_id,
433  'autogen_usernames' => 'Autogen #',
434  'room_type' => 'repository'
435  ));
436  }
437  }
438  }
439 
440  public static function createDefaultPublicRoom($force = false)
441  {
445  global $ilDB;
446 
447  if($force)
448  {
449  $query = 'DELETE FROM chatroom_settings WHERE room_type = ' . $ilDB->quote('default', 'text');
450  $ilDB->manipulate($query);
451  $create = true;
452  }
453  else
454  {
455  $query = 'SELECT * FROM chatroom_settings WHERE room_type = ' . $ilDB->quote('default', 'text');
456  $rset = $ilDB->query($query);
457  $create = !$ilDB->fetchAssoc($rset);
458  }
459  if($create)
460  {
461  $query = "
462  SELECT object_data.obj_id, object_reference.ref_id
463  FROM object_data
464  INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
465  WHERE type = " . $ilDB->quote('chta', 'text');
466  $rset = $ilDB->query($query);
467  $row = $ilDB->fetchAssoc($rset);
468  $chatfolder_ref_id = $row['ref_id'];
469 
470  require_once 'Modules/Chatroom/classes/class.ilObjChatroom.php';
471  $newObj = new ilObjChatroom();
472 
473  $newObj->setType('chtr');
474  $newObj->setTitle('Public Chat');
475  $newObj->setDescription('');
476  $newObj->create(); // true for upload
477  $newObj->createReference();
478  $newObj->putInTree($chatfolder_ref_id);
479  $newObj->setPermissions($chatfolder_ref_id);
480 
481  $obj_id = $newObj->getId();
482  $ref_id = $newObj->getRefId();
483 
484  $id = $ilDB->nextId('chatroom_settings');
485  $ilDB->insert(
486  'chatroom_settings',
487  array(
488  'room_id' => array('integer', $id),
489  'object_id' => array('integer', $obj_id),
490  'room_type' => array('text', 'default'),
491  'allow_anonymous' => array('integer', 0),
492  'allow_custom_usernames' => array('integer', 0),
493  'enable_history' => array('integer', 0),
494  'restrict_history' => array('integer', 0),
495  'autogen_usernames' => array('text', 'Anonymous #'),
496  'allow_private_rooms' => array('integer', 1),
497  )
498  );
499 
500  $settings = new ilSetting('chatroom');
501  $settings->set('public_room_ref', $ref_id);
502  }
503  }
504 
505  public static function createMissinRoomSettingsForConvertedObjects()
506  {
510  global $ilDB;
511 
512  $res = $ilDB->queryF(
513  "SELECT obj_id FROM object_data
514  LEFT JOIN chatroom_settings ON object_id = obj_id
515  WHERE type = %s
516  AND room_id IS NULL",
517  array('text'),
518  array('chtr')
519  );
520 
521  $roomsToFix = array();
522  while($row = $ilDB->fetchAssoc($res))
523  {
524  $roomsToFix[] = $row['obj_id'];
525  }
526 
527  self::setChatroomSettings($roomsToFix);
528  }
529 
533  public static function ensureCorrectPublicChatroomTreeLocation($ref_id)
534  {
540  global $tree, $ilDB, $rbacadmin;
541 
542  $ilDB->setLimit(1);
543  $query = "
544  SELECT object_data.obj_id, object_reference.ref_id
545  FROM object_data
546  INNER JOIN object_reference ON object_reference.obj_id = object_data.obj_id
547  WHERE type = " . $ilDB->quote('chta', 'text');
548  $rset = $ilDB->query($query);
549  $row = $ilDB->fetchAssoc($rset);
550  $chatfolder_ref_id = $row['ref_id'];
551  $pid = $tree->getParentId($ref_id);
552 
553  if(
554  $chatfolder_ref_id &&
555  $pid != $chatfolder_ref_id &&
556  !$tree->isDeleted($chatfolder_ref_id)
557  )
558  {
559  $tree->moveTree($ref_id, $chatfolder_ref_id);
560  $rbacadmin->adjustMovedObjectPermissions($ref_id, $pid);
561  include_once('./Services/AccessControl/classes/class.ilConditionHandler.php');
563  }
564  }
565 }
ILIAS Setting Class.
Class ilObjChatroom.
static setChatroomSettings($obj_ids)
Sets autogen_usernames default option for chatrooms.
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
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.
$ref_id
Definition: sahs_server.php:39
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.