ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDBUpdate4550.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
9 public static function cleanupOrphanedChatRoomData()
10 {
14 global $ilDB;
15
16 // Delete orphaned rooms
17 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
18 $ilDB->manipulate('
19 DELETE c1
20 FROM chatroom_settings c1
21 INNER JOIN (
22 SELECT chatroom_settings.room_id
23 FROM chatroom_settings
24 LEFT JOIN object_data
25 ON object_data.obj_id = chatroom_settings.object_id
26 WHERE object_data.obj_id IS NULL
27 ) c2
28 ON c2.room_id = c1.room_id');
29 } else {
30 // Oracle and Postgres
31 $ilDB->manipulate(
32 '
33 DELETE FROM chatroom_settings
34 WHERE chatroom_settings.room_id IN (
35 SELECT chatroom_settings.room_id
36 FROM chatroom_settings
37 LEFT JOIN object_data
38 ON object_data.obj_id = chatroom_settings.object_id
39 WHERE object_data.obj_id IS NULL
40 )'
41 );
42 }
43
44 // Delete orphaned private rooms
45 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
46 $ilDB->manipulate('
47 DELETE c1
48 FROM chatroom_prooms c1
49 INNER JOIN (
50 SELECT chatroom_prooms.proom_id
51 FROM chatroom_prooms
52 LEFT JOIN chatroom_settings
53 ON chatroom_settings.room_id = chatroom_prooms.parent_id
54 WHERE chatroom_settings.room_id IS NULL
55 ) c2
56 ON c2.proom_id = c1.proom_id');
57 } elseif ($ilDB->getDBType() == 'postgres') {
58 $ilDB->manipulate(
59 '
60 DELETE FROM chatroom_prooms
61 WHERE chatroom_prooms.proom_id IN (
62 SELECT c1.proom_id
63 FROM chatroom_prooms c1
64 LEFT JOIN chatroom_settings
65 ON chatroom_settings.room_id = CAST(c1.parent_id as INT)
66 WHERE chatroom_settings.room_id IS NULL
67 )'
68 );
69 } else {
70 // Oracle
71 $ilDB->manipulate(
72 '
73 DELETE FROM chatroom_prooms
74 WHERE chatroom_prooms.proom_id IN (
75 SELECT c1.proom_id
76 FROM chatroom_prooms c1
77 LEFT JOIN chatroom_settings
78 ON chatroom_settings.room_id = c1.parent_id
79 WHERE chatroom_settings.room_id IS NULL
80 )'
81 );
82 }
83
84 // Delete orphaned bans
85 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
86 $ilDB->manipulate('
87 DELETE c1
88 FROM chatroom_bans c1
89 INNER JOIN (
90 SELECT chatroom_bans.room_id
91 FROM chatroom_bans
92 LEFT JOIN chatroom_settings
93 ON chatroom_settings.room_id = chatroom_bans.room_id
94 WHERE chatroom_settings.room_id IS NULL
95 ) c2
96 ON c2.room_id = c1.room_id');
97 } else {
98 // Oracle and Postgres
99 $ilDB->manipulate(
100 '
101 DELETE FROM chatroom_bans
102 WHERE chatroom_bans.room_id IN (
103 SELECT chatroom_bans.room_id
104 FROM chatroom_bans
105 LEFT JOIN chatroom_settings
106 ON chatroom_settings.room_id = chatroom_bans.room_id
107 WHERE chatroom_settings.room_id IS NULL
108 )'
109 );
110 }
111
112 // Delete orphaned history entries
113 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
114 $ilDB->manipulate('
115 DELETE c1
116 FROM chatroom_history c1
117 INNER JOIN (
118 SELECT chatroom_history.room_id
119 FROM chatroom_history
120 LEFT JOIN chatroom_settings
121 ON chatroom_settings.room_id = chatroom_history.room_id
122 WHERE chatroom_settings.room_id IS NULL
123 ) c2
124 ON c2.room_id = c1.room_id');
125 } else {
126 // Oracle and Postgres
127 $ilDB->manipulate(
128 '
129 DELETE FROM chatroom_history
130 WHERE chatroom_history.room_id IN (
131 SELECT chatroom_history.room_id
132 FROM chatroom_history
133 LEFT JOIN chatroom_settings
134 ON chatroom_settings.room_id = chatroom_history.room_id
135 WHERE chatroom_settings.room_id IS NULL
136 )'
137 );
138 }
139
140 // Delete orphaned users
141 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
142 $ilDB->manipulate('
143 DELETE c1
144 FROM chatroom_users c1
145 INNER JOIN (
146 SELECT chatroom_users.room_id
147 FROM chatroom_users
148 LEFT JOIN chatroom_settings
149 ON chatroom_settings.room_id = chatroom_users.room_id
150 WHERE chatroom_settings.room_id IS NULL
151 ) c2
152 ON c2.room_id = c1.room_id');
153 } else {
154 // Oracle and Postgres
155 $ilDB->manipulate(
156 '
157 DELETE FROM chatroom_users
158 WHERE chatroom_users.room_id IN (
159 SELECT chatroom_users.room_id
160 FROM chatroom_history
161 LEFT JOIN chatroom_settings
162 ON chatroom_settings.room_id = chatroom_users.room_id
163 WHERE chatroom_settings.room_id IS NULL
164 )'
165 );
166 }
167
168 // Delete orphaned sessions
169 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
170 $ilDB->manipulate('
171 DELETE c1
172 FROM chatroom_sessions c1
173 INNER JOIN (
174 SELECT chatroom_sessions.room_id
175 FROM chatroom_sessions
176 LEFT JOIN chatroom_settings
177 ON chatroom_settings.room_id = chatroom_sessions.room_id
178 WHERE chatroom_settings.room_id IS NULL
179 ) c2
180 ON c2.room_id = c1.room_id');
181 } else {
182 // Oracle and Postgres
183 $ilDB->manipulate(
184 '
185 DELETE FROM chatroom_sessions
186 WHERE chatroom_sessions.room_id IN (
187 SELECT chatroom_sessions.room_id
188 FROM chatroom_history
189 LEFT JOIN chatroom_settings
190 ON chatroom_settings.room_id = chatroom_sessions.room_id
191 WHERE chatroom_settings.room_id IS NULL
192 )'
193 );
194 }
195
196 // Delete orphaned private sessions
197 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
198 $ilDB->manipulate('
199 DELETE c1
200 FROM chatroom_psessions c1
201 INNER JOIN (
202 SELECT chatroom_psessions.proom_id
203 FROM chatroom_psessions
204 LEFT JOIN chatroom_prooms
205 ON chatroom_prooms.proom_id = chatroom_psessions.proom_id
206 WHERE chatroom_prooms.proom_id IS NULL
207 ) c2
208 ON c2.proom_id = c1.proom_id');
209 } else {
210 // Oracle and Postgres
211 $ilDB->manipulate(
212 '
213 DELETE FROM chatroom_psessions
214 WHERE chatroom_psessions.proom_id IN (
215 SELECT chatroom_psessions.proom_id
216 FROM chatroom_history
217 LEFT JOIN chatroom_prooms
218 ON chatroom_prooms.proom_id = chatroom_psessions.proom_id
219 WHERE chatroom_prooms.proom_id IS NULL
220 )'
221 );
222 }
223
224 // Delete orphaned private access
225 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
226 $ilDB->manipulate('
227 DELETE c1
228 FROM chatroom_proomaccess c1
229 INNER JOIN (
230 SELECT chatroom_proomaccess.proom_id
231 FROM chatroom_proomaccess
232 LEFT JOIN chatroom_prooms
233 ON chatroom_prooms.proom_id = chatroom_proomaccess.proom_id
234 WHERE chatroom_prooms.proom_id IS NULL
235 ) c2
236 ON c2.proom_id = c1.proom_id');
237 } else {
238 // Oracle and Postgres
239 $ilDB->manipulate(
240 '
241 DELETE FROM chatroom_proomaccess
242 WHERE chatroom_proomaccess.proom_id IN (
243 SELECT chatroom_proomaccess.proom_id
244 FROM chatroom_history
245 LEFT JOIN chatroom_prooms
246 ON chatroom_prooms.proom_id = chatroom_proomaccess.proom_id
247 WHERE chatroom_prooms.proom_id IS NULL
248 )'
249 );
250 }
251
252 // Delete private room history
253 if ($ilDB->getDBType() == '' || $ilDB->getDBType() == 'mysql' || $ilDB->getDBType() == 'innodb') {
254 $ilDB->manipulate('
255 DELETE c1
256 FROM chatroom_history c1
257 INNER JOIN (
258 SELECT chatroom_history.sub_room
259 FROM chatroom_history
260 LEFT JOIN chatroom_prooms
261 ON chatroom_prooms.proom_id = chatroom_history.sub_room
262 WHERE chatroom_prooms.proom_id IS NULL AND chatroom_history.sub_room > 0
263 ) c2
264 ON c2.sub_room = c1.sub_room');
265 } else {
266 // Oracle and Postgres
267 $ilDB->manipulate(
268 '
269 DELETE FROM chatroom_history
270 WHERE chatroom_history.sub_room IN (
271 SELECT chatroom_history.sub_room
272 FROM chatroom_history
273 LEFT JOIN chatroom_prooms
274 ON chatroom_prooms.proom_id = chatroom_history.sub_room
275 WHERE chatroom_prooms.proom_id IS NULL AND chatroom_history.sub_room > 0
276 )'
277 );
278 }
279 }
280}
An exception for terminatinating execution or to throw for unit testing.
Class ilDBUpdate4550.
global $ilDB