1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file contains the functions required to move topics from one board to |
5
|
|
|
* another board. |
6
|
|
|
* |
7
|
|
|
* Simple Machines Forum (SMF) |
8
|
|
|
* |
9
|
|
|
* @package SMF |
10
|
|
|
* @author Simple Machines http://www.simplemachines.org |
11
|
|
|
* @copyright 2019 Simple Machines and individual contributors |
12
|
|
|
* @license http://www.simplemachines.org/about/smf/license.php BSD |
13
|
|
|
* |
14
|
|
|
* @version 2.1 RC2 |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
if (!defined('SMF')) |
18
|
|
|
die('No direct access...'); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* This function allows to move a topic, making sure to ask the moderator |
22
|
|
|
* to give reason for topic move. |
23
|
|
|
* It must be called with a topic specified. (that is, global $topic must |
24
|
|
|
* be set... @todo fix this thing.) |
25
|
|
|
* If the member is the topic starter requires the move_own permission, |
26
|
|
|
* otherwise the move_any permission. |
27
|
|
|
* Accessed via ?action=movetopic. |
28
|
|
|
* |
29
|
|
|
* @uses the MoveTopic template, main sub-template. |
30
|
|
|
*/ |
31
|
|
|
function MoveTopic() |
32
|
|
|
{ |
33
|
|
|
global $txt, $board, $topic, $user_info, $context, $language, $scripturl, $smcFunc, $modSettings, $sourcedir; |
34
|
|
|
|
35
|
|
|
if (empty($topic)) |
36
|
|
|
fatal_lang_error('no_access', false); |
37
|
|
|
|
38
|
|
|
$request = $smcFunc['db_query']('', ' |
39
|
|
|
SELECT t.id_member_started, ms.subject, t.approved |
40
|
|
|
FROM {db_prefix}topics AS t |
41
|
|
|
INNER JOIN {db_prefix}messages AS ms ON (ms.id_msg = t.id_first_msg) |
42
|
|
|
WHERE t.id_topic = {int:current_topic} |
43
|
|
|
LIMIT 1', |
44
|
|
|
array( |
45
|
|
|
'current_topic' => $topic, |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
list ($id_member_started, $context['subject'], $context['is_approved']) = $smcFunc['db_fetch_row']($request); |
49
|
|
|
$smcFunc['db_free_result']($request); |
50
|
|
|
|
51
|
|
|
// Can they see it - if not approved? |
52
|
|
|
if ($modSettings['postmod_active'] && !$context['is_approved']) |
53
|
|
|
isAllowedTo('approve_posts'); |
54
|
|
|
|
55
|
|
|
// Permission check! |
56
|
|
|
// @todo |
57
|
|
|
if (!allowedTo('move_any')) |
58
|
|
|
{ |
59
|
|
|
if ($id_member_started == $user_info['id']) |
60
|
|
|
{ |
61
|
|
|
isAllowedTo('move_own'); |
62
|
|
|
} |
63
|
|
|
else |
64
|
|
|
isAllowedTo('move_any'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$context['move_any'] = $user_info['is_admin'] || $modSettings['topic_move_any']; |
68
|
|
|
$boards = array(); |
69
|
|
|
|
70
|
|
|
if (!$context['move_any']) |
71
|
|
|
{ |
72
|
|
|
$boards = array_diff(boardsAllowedTo('post_new'), array($board)); |
73
|
|
|
if (empty($boards)) |
74
|
|
|
{ |
75
|
|
|
// No boards? Too bad... |
76
|
|
|
fatal_lang_error('moveto_no_boards'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
loadTemplate('MoveTopic'); |
81
|
|
|
|
82
|
|
|
$options = array( |
83
|
|
|
'not_redirection' => true, |
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
if (!empty($_SESSION['move_to_topic']) && $_SESSION['move_to_topic'] != $board) |
87
|
|
|
$options['selected_board'] = $_SESSION['move_to_topic']; |
88
|
|
|
|
89
|
|
|
if (!$context['move_any']) |
90
|
|
|
$options['included_boards'] = $boards; |
91
|
|
|
|
92
|
|
|
require_once($sourcedir . '/Subs-MessageIndex.php'); |
93
|
|
|
$context['categories'] = getBoardList($options); |
94
|
|
|
|
95
|
|
|
$context['page_title'] = $txt['move_topic']; |
96
|
|
|
|
97
|
|
|
$context['linktree'][] = array( |
98
|
|
|
'url' => $scripturl . '?topic=' . $topic . '.0', |
99
|
|
|
'name' => $context['subject'], |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$context['linktree'][] = array( |
103
|
|
|
'name' => $txt['move_topic'], |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
$context['back_to_topic'] = isset($_REQUEST['goback']); |
107
|
|
|
|
108
|
|
|
if ($user_info['language'] != $language) |
109
|
|
|
{ |
110
|
|
|
loadLanguage('index', $language); |
111
|
|
|
$temp = $txt['movetopic_default']; |
112
|
|
|
loadLanguage('index'); |
113
|
|
|
|
114
|
|
|
$txt['movetopic_default'] = $temp; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$context['sub_template'] = 'move'; |
118
|
|
|
|
119
|
|
|
moveTopicConcurrence(); |
120
|
|
|
|
121
|
|
|
// Register this form and get a sequence number in $context. |
122
|
|
|
checkSubmitOnce('register'); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Execute the move of a topic. |
127
|
|
|
* It is called on the submit of MoveTopic. |
128
|
|
|
* This function logs that topics have been moved in the moderation log. |
129
|
|
|
* If the member is the topic starter requires the move_own permission, |
130
|
|
|
* otherwise requires the move_any permission. |
131
|
|
|
* Upon successful completion redirects to message index. |
132
|
|
|
* Accessed via ?action=movetopic2. |
133
|
|
|
* |
134
|
|
|
* @uses Subs-Post.php. |
135
|
|
|
*/ |
136
|
|
|
function MoveTopic2() |
137
|
|
|
{ |
138
|
|
|
global $txt, $topic, $scripturl, $sourcedir, $context; |
139
|
|
|
global $board, $language, $user_info, $smcFunc; |
140
|
|
|
|
141
|
|
|
if (empty($topic)) |
142
|
|
|
fatal_lang_error('no_access', false); |
143
|
|
|
|
144
|
|
|
// You can't choose to have a redirection topic and use an empty reason. |
145
|
|
|
if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == '')) |
146
|
|
|
fatal_lang_error('movetopic_no_reason', false); |
147
|
|
|
|
148
|
|
|
moveTopicConcurrence(); |
149
|
|
|
|
150
|
|
|
// Make sure this form hasn't been submitted before. |
151
|
|
|
checkSubmitOnce('check'); |
152
|
|
|
|
153
|
|
|
$request = $smcFunc['db_query']('', ' |
154
|
|
|
SELECT id_member_started, id_first_msg, approved |
155
|
|
|
FROM {db_prefix}topics |
156
|
|
|
WHERE id_topic = {int:current_topic} |
157
|
|
|
LIMIT 1', |
158
|
|
|
array( |
159
|
|
|
'current_topic' => $topic, |
160
|
|
|
) |
161
|
|
|
); |
162
|
|
|
list ($id_member_started, $id_first_msg, $context['is_approved']) = $smcFunc['db_fetch_row']($request); |
163
|
|
|
$smcFunc['db_free_result']($request); |
164
|
|
|
|
165
|
|
|
// Can they see it? |
166
|
|
|
if (!$context['is_approved']) |
167
|
|
|
isAllowedTo('approve_posts'); |
168
|
|
|
|
169
|
|
|
// Can they move topics on this board? |
170
|
|
|
if (!allowedTo('move_any')) |
171
|
|
|
{ |
172
|
|
|
if ($id_member_started == $user_info['id']) |
173
|
|
|
isAllowedTo('move_own'); |
174
|
|
|
else |
175
|
|
|
isAllowedTo('move_any'); |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
checkSession(); |
179
|
|
|
require_once($sourcedir . '/Subs-Post.php'); |
180
|
|
|
|
181
|
|
|
// The destination board must be numeric. |
182
|
|
|
$_POST['toboard'] = (int) $_POST['toboard']; |
183
|
|
|
|
184
|
|
|
// Make sure they can see the board they are trying to move to (and get whether posts count in the target board). |
185
|
|
|
$request = $smcFunc['db_query']('', ' |
186
|
|
|
SELECT b.count_posts, b.name, m.subject |
187
|
|
|
FROM {db_prefix}boards AS b |
188
|
|
|
INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic}) |
189
|
|
|
INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg) |
190
|
|
|
WHERE {query_see_board} |
191
|
|
|
AND b.id_board = {int:to_board} |
192
|
|
|
AND b.redirect = {string:blank_redirect} |
193
|
|
|
LIMIT 1', |
194
|
|
|
array( |
195
|
|
|
'current_topic' => $topic, |
196
|
|
|
'to_board' => $_POST['toboard'], |
197
|
|
|
'blank_redirect' => '', |
198
|
|
|
) |
199
|
|
|
); |
200
|
|
|
if ($smcFunc['db_num_rows']($request) == 0) |
201
|
|
|
fatal_lang_error('no_board'); |
202
|
|
|
|
203
|
|
|
list ($pcounter, $board_name, $subject) = $smcFunc['db_fetch_row']($request); |
204
|
|
|
$smcFunc['db_free_result']($request); |
205
|
|
|
|
206
|
|
|
// Remember this for later. |
207
|
|
|
$_SESSION['move_to_topic'] = $_POST['toboard']; |
208
|
|
|
|
209
|
|
|
// Rename the topic... |
210
|
|
|
if (isset($_POST['reset_subject'], $_POST['custom_subject']) && $_POST['custom_subject'] != '') |
211
|
|
|
{ |
212
|
|
|
$_POST['custom_subject'] = strtr($smcFunc['htmltrim']($smcFunc['htmlspecialchars']($_POST['custom_subject'])), array("\r" => '', "\n" => '', "\t" => '')); |
213
|
|
|
// Keep checking the length. |
214
|
|
|
if ($smcFunc['strlen']($_POST['custom_subject']) > 100) |
215
|
|
|
$_POST['custom_subject'] = $smcFunc['substr']($_POST['custom_subject'], 0, 100); |
216
|
|
|
|
217
|
|
|
// If it's still valid move onwards and upwards. |
218
|
|
|
if ($_POST['custom_subject'] != '') |
219
|
|
|
{ |
220
|
|
|
if (isset($_POST['enforce_subject'])) |
221
|
|
|
{ |
222
|
|
|
// Get a response prefix, but in the forum's default language. |
223
|
|
|
if (!isset($context['response_prefix']) && !($context['response_prefix'] = cache_get_data('response_prefix'))) |
224
|
|
|
{ |
225
|
|
|
if ($language === $user_info['language']) |
226
|
|
|
$context['response_prefix'] = $txt['response_prefix']; |
227
|
|
|
else |
228
|
|
|
{ |
229
|
|
|
loadLanguage('index', $language, false); |
230
|
|
|
$context['response_prefix'] = $txt['response_prefix']; |
231
|
|
|
loadLanguage('index'); |
232
|
|
|
} |
233
|
|
|
cache_put_data('response_prefix', $context['response_prefix'], 600); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
$smcFunc['db_query']('', ' |
237
|
|
|
UPDATE {db_prefix}messages |
238
|
|
|
SET subject = {string:subject} |
239
|
|
|
WHERE id_topic = {int:current_topic}', |
240
|
|
|
array( |
241
|
|
|
'current_topic' => $topic, |
242
|
|
|
'subject' => $context['response_prefix'] . $_POST['custom_subject'], |
243
|
|
|
) |
244
|
|
|
); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
$smcFunc['db_query']('', ' |
248
|
|
|
UPDATE {db_prefix}messages |
249
|
|
|
SET subject = {string:custom_subject} |
250
|
|
|
WHERE id_msg = {int:id_first_msg}', |
251
|
|
|
array( |
252
|
|
|
'id_first_msg' => $id_first_msg, |
253
|
|
|
'custom_subject' => $_POST['custom_subject'], |
254
|
|
|
) |
255
|
|
|
); |
256
|
|
|
|
257
|
|
|
// Fix the subject cache. |
258
|
|
|
updateStats('subject', $topic, $_POST['custom_subject']); |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
// Create a link to this in the old board. |
263
|
|
|
// @todo Does this make sense if the topic was unapproved before? I'd just about say so. |
264
|
|
|
if (isset($_POST['postRedirect'])) |
265
|
|
|
{ |
266
|
|
|
// Should be in the boardwide language. |
267
|
|
|
if ($user_info['language'] != $language) |
268
|
|
|
loadLanguage('index', $language); |
269
|
|
|
|
270
|
|
|
$_POST['reason'] = $smcFunc['htmlspecialchars']($_POST['reason'], ENT_QUOTES); |
271
|
|
|
preparsecode($_POST['reason']); |
272
|
|
|
|
273
|
|
|
// Add a URL onto the message. |
274
|
|
|
$_POST['reason'] = strtr($_POST['reason'], array( |
275
|
|
|
$txt['movetopic_auto_board'] => '[url=' . $scripturl . '?board=' . $_POST['toboard'] . '.0]' . $board_name . '[/url]', |
276
|
|
|
$txt['movetopic_auto_topic'] => '[iurl]' . $scripturl . '?topic=' . $topic . '.0[/iurl]' |
277
|
|
|
)); |
278
|
|
|
|
279
|
|
|
// auto remove this MOVED redirection topic in the future? |
280
|
|
|
$redirect_expires = !empty($_POST['redirect_expires']) ? ((int) ($_POST['redirect_expires'] * 60) + time()) : 0; |
281
|
|
|
|
282
|
|
|
// redirect to the MOVED topic from topic list? |
283
|
|
|
$redirect_topic = isset($_POST['redirect_topic']) ? $topic : 0; |
284
|
|
|
|
285
|
|
|
$msgOptions = array( |
286
|
|
|
'subject' => $txt['moved'] . ': ' . $subject, |
287
|
|
|
'body' => $_POST['reason'], |
288
|
|
|
'icon' => 'moved', |
289
|
|
|
'smileys_enabled' => 1, |
290
|
|
|
); |
291
|
|
|
$topicOptions = array( |
292
|
|
|
'board' => $board, |
293
|
|
|
'lock_mode' => 1, |
294
|
|
|
'mark_as_read' => true, |
295
|
|
|
'redirect_expires' => $redirect_expires, |
296
|
|
|
'redirect_topic' => $redirect_topic, |
297
|
|
|
); |
298
|
|
|
$posterOptions = array( |
299
|
|
|
'id' => $user_info['id'], |
300
|
|
|
'update_post_count' => empty($pcounter), |
301
|
|
|
); |
302
|
|
|
createPost($msgOptions, $topicOptions, $posterOptions); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
$request = $smcFunc['db_query']('', ' |
306
|
|
|
SELECT count_posts |
307
|
|
|
FROM {db_prefix}boards |
308
|
|
|
WHERE id_board = {int:current_board} |
309
|
|
|
LIMIT 1', |
310
|
|
|
array( |
311
|
|
|
'current_board' => $board, |
312
|
|
|
) |
313
|
|
|
); |
314
|
|
|
list ($pcounter_from) = $smcFunc['db_fetch_row']($request); |
315
|
|
|
$smcFunc['db_free_result']($request); |
316
|
|
|
|
317
|
|
|
if ($pcounter_from != $pcounter) |
318
|
|
|
{ |
319
|
|
|
$request = $smcFunc['db_query']('', ' |
320
|
|
|
SELECT id_member |
321
|
|
|
FROM {db_prefix}messages |
322
|
|
|
WHERE id_topic = {int:current_topic} |
323
|
|
|
AND approved = {int:is_approved}', |
324
|
|
|
array( |
325
|
|
|
'current_topic' => $topic, |
326
|
|
|
'is_approved' => 1, |
327
|
|
|
) |
328
|
|
|
); |
329
|
|
|
$posters = array(); |
330
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
331
|
|
|
{ |
332
|
|
|
if (!isset($posters[$row['id_member']])) |
333
|
|
|
$posters[$row['id_member']] = 0; |
334
|
|
|
|
335
|
|
|
$posters[$row['id_member']]++; |
336
|
|
|
} |
337
|
|
|
$smcFunc['db_free_result']($request); |
338
|
|
|
|
339
|
|
|
foreach ($posters as $id_member => $posts) |
340
|
|
|
{ |
341
|
|
|
// The board we're moving from counted posts, but not to. |
342
|
|
|
if (empty($pcounter_from)) |
343
|
|
|
updateMemberData($id_member, array('posts' => 'posts - ' . $posts)); |
344
|
|
|
// The reverse: from didn't, to did. |
345
|
|
|
else |
346
|
|
|
updateMemberData($id_member, array('posts' => 'posts + ' . $posts)); |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
// Do the move (includes statistics update needed for the redirect topic). |
351
|
|
|
moveTopics($topic, $_POST['toboard']); |
352
|
|
|
|
353
|
|
|
// Log that they moved this topic. |
354
|
|
|
if (!allowedTo('move_own') || $id_member_started != $user_info['id']) |
355
|
|
|
logAction('move', array('topic' => $topic, 'board_from' => $board, 'board_to' => $_POST['toboard'])); |
356
|
|
|
// Notify people that this topic has been moved? |
357
|
|
|
sendNotifications($topic, 'move'); |
358
|
|
|
|
359
|
|
|
call_integration_hook('integrate_movetopic2_end'); |
360
|
|
|
|
361
|
|
|
// Why not go back to the original board in case they want to keep moving? |
362
|
|
|
if (!isset($_REQUEST['goback'])) |
363
|
|
|
redirectexit('board=' . $board . '.0'); |
364
|
|
|
else |
365
|
|
|
redirectexit('topic=' . $topic . '.0'); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** |
369
|
|
|
* Moves one or more topics to a specific board. (doesn't check permissions.) |
370
|
|
|
* Determines the source boards for the supplied topics |
371
|
|
|
* Handles the moving of mark_read data |
372
|
|
|
* Updates the posts count of the affected boards |
373
|
|
|
* |
374
|
|
|
* @param int|int[] $topics The ID of a single topic to move or an array containing the IDs of multiple topics to move |
375
|
|
|
* @param int $toBoard The ID of the board to move the topics to |
376
|
|
|
*/ |
377
|
|
|
function moveTopics($topics, $toBoard) |
378
|
|
|
{ |
379
|
|
|
global $sourcedir, $user_info, $modSettings, $smcFunc, $cache_enable; |
380
|
|
|
|
381
|
|
|
// Empty array? |
382
|
|
|
if (empty($topics)) |
383
|
|
|
return; |
384
|
|
|
|
385
|
|
|
// Only a single topic. |
386
|
|
|
if (is_numeric($topics)) |
387
|
|
|
$topics = array($topics); |
388
|
|
|
|
389
|
|
|
$fromBoards = array(); |
390
|
|
|
|
391
|
|
|
// Destination board empty or equal to 0? |
392
|
|
|
if (empty($toBoard)) |
393
|
|
|
return; |
394
|
|
|
|
395
|
|
|
// Are we moving to the recycle board? |
396
|
|
|
$isRecycleDest = !empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] == $toBoard; |
397
|
|
|
|
398
|
|
|
// Callback for search APIs to do their thing |
399
|
|
|
require_once($sourcedir . '/Search.php'); |
400
|
|
|
$searchAPI = findSearchAPI(); |
401
|
|
|
if ($searchAPI->supportsMethod('topicsMoved')) |
402
|
|
|
$searchAPI->topicsMoved($topics, $toBoard); |
403
|
|
|
|
404
|
|
|
// Determine the source boards... |
405
|
|
|
$request = $smcFunc['db_query']('', ' |
406
|
|
|
SELECT id_board, approved, COUNT(*) AS num_topics, SUM(unapproved_posts) AS unapproved_posts, |
407
|
|
|
SUM(num_replies) AS num_replies |
408
|
|
|
FROM {db_prefix}topics |
409
|
|
|
WHERE id_topic IN ({array_int:topics}) |
410
|
|
|
GROUP BY id_board, approved', |
411
|
|
|
array( |
412
|
|
|
'topics' => $topics, |
413
|
|
|
) |
414
|
|
|
); |
415
|
|
|
// Num of rows = 0 -> no topics found. Num of rows > 1 -> topics are on multiple boards. |
416
|
|
|
if ($smcFunc['db_num_rows']($request) == 0) |
417
|
|
|
return; |
418
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
419
|
|
|
{ |
420
|
|
|
if (!isset($fromBoards[$row['id_board']]['num_posts'])) |
421
|
|
|
{ |
422
|
|
|
$fromBoards[$row['id_board']] = array( |
423
|
|
|
'num_posts' => 0, |
424
|
|
|
'num_topics' => 0, |
425
|
|
|
'unapproved_posts' => 0, |
426
|
|
|
'unapproved_topics' => 0, |
427
|
|
|
'id_board' => $row['id_board'] |
428
|
|
|
); |
429
|
|
|
} |
430
|
|
|
// Posts = (num_replies + 1) for each approved topic. |
431
|
|
|
$fromBoards[$row['id_board']]['num_posts'] += $row['num_replies'] + ($row['approved'] ? $row['num_topics'] : 0); |
432
|
|
|
$fromBoards[$row['id_board']]['unapproved_posts'] += $row['unapproved_posts']; |
433
|
|
|
|
434
|
|
|
// Add the topics to the right type. |
435
|
|
|
if ($row['approved']) |
436
|
|
|
$fromBoards[$row['id_board']]['num_topics'] += $row['num_topics']; |
437
|
|
|
else |
438
|
|
|
$fromBoards[$row['id_board']]['unapproved_topics'] += $row['num_topics']; |
439
|
|
|
} |
440
|
|
|
$smcFunc['db_free_result']($request); |
441
|
|
|
|
442
|
|
|
// Move over the mark_read data. (because it may be read and now not by some!) |
443
|
|
|
$SaveAServer = max(0, $modSettings['maxMsgID'] - 50000); |
444
|
|
|
$request = $smcFunc['db_query']('', ' |
445
|
|
|
SELECT lmr.id_member, lmr.id_msg, t.id_topic, COALESCE(lt.unwatched, 0) AS unwatched |
446
|
|
|
FROM {db_prefix}topics AS t |
447
|
|
|
INNER JOIN {db_prefix}log_mark_read AS lmr ON (lmr.id_board = t.id_board |
448
|
|
|
AND lmr.id_msg > t.id_first_msg AND lmr.id_msg > {int:protect_lmr_msg}) |
449
|
|
|
LEFT JOIN {db_prefix}log_topics AS lt ON (lt.id_topic = t.id_topic AND lt.id_member = lmr.id_member) |
450
|
|
|
WHERE t.id_topic IN ({array_int:topics}) |
451
|
|
|
AND lmr.id_msg > COALESCE(lt.id_msg, 0)', |
452
|
|
|
array( |
453
|
|
|
'protect_lmr_msg' => $SaveAServer, |
454
|
|
|
'topics' => $topics, |
455
|
|
|
) |
456
|
|
|
); |
457
|
|
|
$log_topics = array(); |
458
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
459
|
|
|
{ |
460
|
|
|
$log_topics[] = array($row['id_topic'], $row['id_member'], $row['id_msg'], (is_null($row['unwatched']) ? 0 : $row['unwatched'])); |
461
|
|
|
|
462
|
|
|
// Prevent queries from getting too big. Taking some steam off. |
463
|
|
|
if (count($log_topics) > 500) |
464
|
|
|
{ |
465
|
|
|
$smcFunc['db_insert']('replace', |
466
|
|
|
'{db_prefix}log_topics', |
467
|
|
|
array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'), |
468
|
|
|
$log_topics, |
469
|
|
|
array('id_topic', 'id_member') |
470
|
|
|
); |
471
|
|
|
|
472
|
|
|
$log_topics = array(); |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
$smcFunc['db_free_result']($request); |
476
|
|
|
|
477
|
|
|
// Now that we have all the topics that *should* be marked read, and by which members... |
478
|
|
|
if (!empty($log_topics)) |
479
|
|
|
{ |
480
|
|
|
// Insert that information into the database! |
481
|
|
|
$smcFunc['db_insert']('replace', |
482
|
|
|
'{db_prefix}log_topics', |
483
|
|
|
array('id_topic' => 'int', 'id_member' => 'int', 'id_msg' => 'int', 'unwatched' => 'int'), |
484
|
|
|
$log_topics, |
485
|
|
|
array('id_topic', 'id_member') |
486
|
|
|
); |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
// Update the number of posts on each board. |
490
|
|
|
$totalTopics = 0; |
491
|
|
|
$totalPosts = 0; |
492
|
|
|
$totalUnapprovedTopics = 0; |
493
|
|
|
$totalUnapprovedPosts = 0; |
494
|
|
|
foreach ($fromBoards as $stats) |
495
|
|
|
{ |
496
|
|
|
$smcFunc['db_query']('', ' |
497
|
|
|
UPDATE {db_prefix}boards |
498
|
|
|
SET |
499
|
|
|
num_posts = CASE WHEN {int:num_posts} > num_posts THEN 0 ELSE num_posts - {int:num_posts} END, |
500
|
|
|
num_topics = CASE WHEN {int:num_topics} > num_topics THEN 0 ELSE num_topics - {int:num_topics} END, |
501
|
|
|
unapproved_posts = CASE WHEN {int:unapproved_posts} > unapproved_posts THEN 0 ELSE unapproved_posts - {int:unapproved_posts} END, |
502
|
|
|
unapproved_topics = CASE WHEN {int:unapproved_topics} > unapproved_topics THEN 0 ELSE unapproved_topics - {int:unapproved_topics} END |
503
|
|
|
WHERE id_board = {int:id_board}', |
504
|
|
|
array( |
505
|
|
|
'id_board' => $stats['id_board'], |
506
|
|
|
'num_posts' => $stats['num_posts'], |
507
|
|
|
'num_topics' => $stats['num_topics'], |
508
|
|
|
'unapproved_posts' => $stats['unapproved_posts'], |
509
|
|
|
'unapproved_topics' => $stats['unapproved_topics'], |
510
|
|
|
) |
511
|
|
|
); |
512
|
|
|
$totalTopics += $stats['num_topics']; |
513
|
|
|
$totalPosts += $stats['num_posts']; |
514
|
|
|
$totalUnapprovedTopics += $stats['unapproved_topics']; |
515
|
|
|
$totalUnapprovedPosts += $stats['unapproved_posts']; |
516
|
|
|
} |
517
|
|
|
$smcFunc['db_query']('', ' |
518
|
|
|
UPDATE {db_prefix}boards |
519
|
|
|
SET |
520
|
|
|
num_topics = num_topics + {int:total_topics}, |
521
|
|
|
num_posts = num_posts + {int:total_posts},' . ($isRecycleDest ? ' |
522
|
|
|
unapproved_posts = {int:no_unapproved}, unapproved_topics = {int:no_unapproved}' : ' |
523
|
|
|
unapproved_posts = unapproved_posts + {int:total_unapproved_posts}, |
524
|
|
|
unapproved_topics = unapproved_topics + {int:total_unapproved_topics}') . ' |
525
|
|
|
WHERE id_board = {int:id_board}', |
526
|
|
|
array( |
527
|
|
|
'id_board' => $toBoard, |
528
|
|
|
'total_topics' => $totalTopics, |
529
|
|
|
'total_posts' => $totalPosts, |
530
|
|
|
'total_unapproved_topics' => $totalUnapprovedTopics, |
531
|
|
|
'total_unapproved_posts' => $totalUnapprovedPosts, |
532
|
|
|
'no_unapproved' => 0, |
533
|
|
|
) |
534
|
|
|
); |
535
|
|
|
|
536
|
|
|
// Move the topic. Done. :P |
537
|
|
|
$smcFunc['db_query']('', ' |
538
|
|
|
UPDATE {db_prefix}topics |
539
|
|
|
SET id_board = {int:id_board}' . ($isRecycleDest ? ', |
540
|
|
|
unapproved_posts = {int:no_unapproved}, approved = {int:is_approved}' : '') . ' |
541
|
|
|
WHERE id_topic IN ({array_int:topics})', |
542
|
|
|
array( |
543
|
|
|
'id_board' => $toBoard, |
544
|
|
|
'topics' => $topics, |
545
|
|
|
'is_approved' => 1, |
546
|
|
|
'no_unapproved' => 0, |
547
|
|
|
) |
548
|
|
|
); |
549
|
|
|
|
550
|
|
|
// If this was going to the recycle bin, check what messages are being recycled, and remove them from the queue. |
551
|
|
|
if ($isRecycleDest && ($totalUnapprovedTopics || $totalUnapprovedPosts)) |
552
|
|
|
{ |
553
|
|
|
$request = $smcFunc['db_query']('', ' |
554
|
|
|
SELECT id_msg |
555
|
|
|
FROM {db_prefix}messages |
556
|
|
|
WHERE id_topic IN ({array_int:topics}) |
557
|
|
|
AND approved = {int:not_approved}', |
558
|
|
|
array( |
559
|
|
|
'topics' => $topics, |
560
|
|
|
'not_approved' => 0, |
561
|
|
|
) |
562
|
|
|
); |
563
|
|
|
$approval_msgs = array(); |
564
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
565
|
|
|
$approval_msgs[] = $row['id_msg']; |
566
|
|
|
|
567
|
|
|
$smcFunc['db_free_result']($request); |
568
|
|
|
|
569
|
|
|
// Empty the approval queue for these, as we're going to approve them next. |
570
|
|
|
if (!empty($approval_msgs)) |
571
|
|
|
$smcFunc['db_query']('', ' |
572
|
|
|
DELETE FROM {db_prefix}approval_queue |
573
|
|
|
WHERE id_msg IN ({array_int:message_list}) |
574
|
|
|
AND id_attach = {int:id_attach}', |
575
|
|
|
array( |
576
|
|
|
'message_list' => $approval_msgs, |
577
|
|
|
'id_attach' => 0, |
578
|
|
|
) |
579
|
|
|
); |
580
|
|
|
|
581
|
|
|
// Get all the current max and mins. |
582
|
|
|
$request = $smcFunc['db_query']('', ' |
583
|
|
|
SELECT id_topic, id_first_msg, id_last_msg |
584
|
|
|
FROM {db_prefix}topics |
585
|
|
|
WHERE id_topic IN ({array_int:topics})', |
586
|
|
|
array( |
587
|
|
|
'topics' => $topics, |
588
|
|
|
) |
589
|
|
|
); |
590
|
|
|
$topicMaxMin = array(); |
591
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
592
|
|
|
{ |
593
|
|
|
$topicMaxMin[$row['id_topic']] = array( |
594
|
|
|
'min' => $row['id_first_msg'], |
595
|
|
|
'max' => $row['id_last_msg'], |
596
|
|
|
); |
597
|
|
|
} |
598
|
|
|
$smcFunc['db_free_result']($request); |
599
|
|
|
|
600
|
|
|
// Check the MAX and MIN are correct. |
601
|
|
|
$request = $smcFunc['db_query']('', ' |
602
|
|
|
SELECT id_topic, MIN(id_msg) AS first_msg, MAX(id_msg) AS last_msg |
603
|
|
|
FROM {db_prefix}messages |
604
|
|
|
WHERE id_topic IN ({array_int:topics}) |
605
|
|
|
GROUP BY id_topic', |
606
|
|
|
array( |
607
|
|
|
'topics' => $topics, |
608
|
|
|
) |
609
|
|
|
); |
610
|
|
|
while ($row = $smcFunc['db_fetch_assoc']($request)) |
611
|
|
|
{ |
612
|
|
|
// If not, update. |
613
|
|
|
if ($row['first_msg'] != $topicMaxMin[$row['id_topic']]['min'] || $row['last_msg'] != $topicMaxMin[$row['id_topic']]['max']) |
614
|
|
|
$smcFunc['db_query']('', ' |
615
|
|
|
UPDATE {db_prefix}topics |
616
|
|
|
SET id_first_msg = {int:first_msg}, id_last_msg = {int:last_msg} |
617
|
|
|
WHERE id_topic = {int:selected_topic}', |
618
|
|
|
array( |
619
|
|
|
'first_msg' => $row['first_msg'], |
620
|
|
|
'last_msg' => $row['last_msg'], |
621
|
|
|
'selected_topic' => $row['id_topic'], |
622
|
|
|
) |
623
|
|
|
); |
624
|
|
|
} |
625
|
|
|
$smcFunc['db_free_result']($request); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
$smcFunc['db_query']('', ' |
629
|
|
|
UPDATE {db_prefix}messages |
630
|
|
|
SET id_board = {int:id_board}' . ($isRecycleDest ? ',approved = {int:is_approved}' : '') . ' |
631
|
|
|
WHERE id_topic IN ({array_int:topics})', |
632
|
|
|
array( |
633
|
|
|
'id_board' => $toBoard, |
634
|
|
|
'topics' => $topics, |
635
|
|
|
'is_approved' => 1, |
636
|
|
|
) |
637
|
|
|
); |
638
|
|
|
$smcFunc['db_query']('', ' |
639
|
|
|
UPDATE {db_prefix}log_reported |
640
|
|
|
SET id_board = {int:id_board} |
641
|
|
|
WHERE id_topic IN ({array_int:topics})', |
642
|
|
|
array( |
643
|
|
|
'id_board' => $toBoard, |
644
|
|
|
'topics' => $topics, |
645
|
|
|
) |
646
|
|
|
); |
647
|
|
|
$smcFunc['db_query']('', ' |
648
|
|
|
UPDATE {db_prefix}calendar |
649
|
|
|
SET id_board = {int:id_board} |
650
|
|
|
WHERE id_topic IN ({array_int:topics})', |
651
|
|
|
array( |
652
|
|
|
'id_board' => $toBoard, |
653
|
|
|
'topics' => $topics, |
654
|
|
|
) |
655
|
|
|
); |
656
|
|
|
|
657
|
|
|
// Mark target board as seen, if it was already marked as seen before. |
658
|
|
|
$request = $smcFunc['db_query']('', ' |
659
|
|
|
SELECT (COALESCE(lb.id_msg, 0) >= b.id_msg_updated) AS isSeen |
660
|
|
|
FROM {db_prefix}boards AS b |
661
|
|
|
LEFT JOIN {db_prefix}log_boards AS lb ON (lb.id_board = b.id_board AND lb.id_member = {int:current_member}) |
662
|
|
|
WHERE b.id_board = {int:id_board}', |
663
|
|
|
array( |
664
|
|
|
'current_member' => $user_info['id'], |
665
|
|
|
'id_board' => $toBoard, |
666
|
|
|
) |
667
|
|
|
); |
668
|
|
|
list ($isSeen) = $smcFunc['db_fetch_row']($request); |
669
|
|
|
$smcFunc['db_free_result']($request); |
670
|
|
|
|
671
|
|
|
if (!empty($isSeen) && !$user_info['is_guest']) |
672
|
|
|
{ |
673
|
|
|
$smcFunc['db_insert']('replace', |
674
|
|
|
'{db_prefix}log_boards', |
675
|
|
|
array('id_board' => 'int', 'id_member' => 'int', 'id_msg' => 'int'), |
676
|
|
|
array($toBoard, $user_info['id'], $modSettings['maxMsgID']), |
677
|
|
|
array('id_board', 'id_member') |
678
|
|
|
); |
679
|
|
|
} |
680
|
|
|
|
681
|
|
|
// Update the cache? |
682
|
|
|
if (!empty($cache_enable) && $cache_enable >= 3) |
683
|
|
|
foreach ($topics as $topic_id) |
684
|
|
|
cache_put_data('topic_board-' . $topic_id, null, 120); |
685
|
|
|
|
686
|
|
|
require_once($sourcedir . '/Subs-Post.php'); |
687
|
|
|
|
688
|
|
|
$updates = array_keys($fromBoards); |
689
|
|
|
$updates[] = $toBoard; |
690
|
|
|
|
691
|
|
|
updateLastMessages(array_unique($updates)); |
692
|
|
|
|
693
|
|
|
// Update 'em pesky stats. |
694
|
|
|
updateStats('topic'); |
695
|
|
|
updateStats('message'); |
696
|
|
|
updateSettings(array( |
697
|
|
|
'calendar_updated' => time(), |
698
|
|
|
)); |
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
/** |
702
|
|
|
* Called after a topic is moved to update $board_link and $topic_link to point to new location |
703
|
|
|
*/ |
704
|
|
|
function moveTopicConcurrence() |
705
|
|
|
{ |
706
|
|
|
global $board, $topic, $smcFunc, $scripturl; |
707
|
|
|
|
708
|
|
|
if (isset($_GET['current_board'])) |
709
|
|
|
$move_from = (int) $_GET['current_board']; |
710
|
|
|
|
711
|
|
|
if (empty($move_from) || empty($board) || empty($topic)) |
712
|
|
|
return true; |
713
|
|
|
|
714
|
|
|
if ($move_from == $board) |
|
|
|
|
715
|
|
|
return true; |
716
|
|
|
else |
717
|
|
|
{ |
718
|
|
|
$request = $smcFunc['db_query']('', ' |
719
|
|
|
SELECT m.subject, b.name |
720
|
|
|
FROM {db_prefix}topics as t |
721
|
|
|
LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board) |
722
|
|
|
LEFT JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg) |
723
|
|
|
WHERE t.id_topic = {int:topic_id} |
724
|
|
|
LIMIT 1', |
725
|
|
|
array( |
726
|
|
|
'topic_id' => $topic, |
727
|
|
|
) |
728
|
|
|
); |
729
|
|
|
list($topic_subject, $board_name) = $smcFunc['db_fetch_row']($request); |
730
|
|
|
$smcFunc['db_free_result']($request); |
731
|
|
|
$board_link = '<a href="' . $scripturl . '?board=' . $board . '.0">' . $board_name . '</a>'; |
732
|
|
|
$topic_link = '<a href="' . $scripturl . '?topic=' . $topic . '.0">' . $topic_subject . '</a>'; |
733
|
|
|
fatal_lang_error('topic_already_moved', false, array($topic_link, $board_link)); |
734
|
|
|
} |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
?> |