Browse Source

Concurrent move of topics detected and action stopped first half of [Bug 4910]

emanuele 12 years ago
parent
commit
9a1585aae5

+ 3 - 0
Sources/MessageIndex.php

@@ -810,6 +810,9 @@ function QuickModeration()
 			$stickyCache[] = $topic;
 		elseif ($action == 'move')
 		{
+			require_once($sourcedir . '/MoveTopic.php');
+			moveTopicConcurrence();
+
 			// $moveCache[0] is the topic, $moveCache[1] is the board to move to.
 			$moveCache[1][$topic] = (int) (isset($_REQUEST['move_tos'][$topic]) ? $_REQUEST['move_tos'][$topic] : $_REQUEST['move_to']);
 

+ 37 - 0
Sources/MoveTopic.php

@@ -125,6 +125,8 @@ function MoveTopic()
 		$txt['movetopic_default'] = $temp;
 	}
 
+	moveTopicConcurrence();
+
 	// Register this form and get a sequence number in $context.
 	checkSubmitOnce('register');
 }
@@ -152,6 +154,8 @@ function MoveTopic2()
 	if (isset($_POST['postRedirect']) && (!isset($_POST['reason']) || trim($_POST['reason']) == ''))
 		fatal_lang_error('movetopic_no_reason', false);
 
+	moveTopicConcurrence();
+
 	// Make sure this form hasn't been submitted before.
 	checkSubmitOnce('check');
 
@@ -689,4 +693,37 @@ function moveTopics($topics, $toBoard)
 	));
 }
 
+function moveTopicConcurrence()
+{
+	global $board, $topic, $smcFunc, $scripturl;
+
+	if (isset($_GET['current_board']))
+		$move_from = (int) $_GET['current_board'];
+
+	if (empty($move_from) || empty($board) || empty($topic))
+		return true;
+
+	if ($move_from == $board)
+		return true;
+	else
+	{
+		$request = $smcFunc['db_query']('', '
+			SELECT m.subject, b.name
+			FROM {db_prefix}topics as t
+			LEFT JOIN {db_prefix}boards AS b ON (t.id_board = b.id_board)
+			LEFT JOIN {db_prefix}messages AS m ON (t.id_first_msg = m.id_msg)
+			WHERE t.id_topic = {int:topic_id}
+			LIMIT 1',
+			array(
+				'topic_id' => $topic,
+			)
+		);
+		list($topic_subject, $board_name) = $smcFunc['db_fetch_row']($request);
+		$smcFunc['db_free_result']($request);
+		$board_link = '<a href="' . $scripturl . '?board=' . $board . '.0">' . $board_name . '</a>';
+		$topic_link = '<a href="' . $scripturl . '?topic=' . $topic . '.0">' . $topic_subject . '</a>';
+		fatal_lang_error('topic_already_moved', false, array($topic_link, $board_link));
+	}
+
+}
 ?>

+ 1 - 1
Themes/default/Display.template.php

@@ -647,7 +647,7 @@ function template_main()
 	theme_linktree();
 
 	$mod_buttons = array(
-		'move' => array('test' => 'can_move', 'text' => 'move_topic', 'image' => 'admin_move.png', 'lang' => true, 'url' => $scripturl . '?action=movetopic;topic=' . $context['current_topic'] . '.0'),
+		'move' => array('test' => 'can_move', 'text' => 'move_topic', 'image' => 'admin_move.png', 'lang' => true, 'url' => $scripturl . '?action=movetopic;current_board=' . $context['current_board'] . ';topic=' . $context['current_topic'] . '.0'),
 		'delete' => array('test' => 'can_delete', 'text' => 'remove_topic', 'image' => 'admin_rem.png', 'lang' => true, 'custom' => 'onclick="return confirm(\'' . $txt['are_sure_remove_topic'] . '\');"', 'url' => $scripturl . '?action=removetopic2;topic=' . $context['current_topic'] . '.0;' . $context['session_var'] . '=' . $context['session_id']),
 		'lock' => array('test' => 'can_lock', 'text' => empty($context['is_locked']) ? 'set_lock' : 'set_unlock', 'image' => 'admin_lock.png', 'lang' => true, 'url' => $scripturl . '?action=lock;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),
 		'sticky' => array('test' => 'can_sticky', 'text' => empty($context['is_sticky']) ? 'set_sticky' : 'set_nonsticky', 'image' => 'admin_sticky.png', 'lang' => true, 'url' => $scripturl . '?action=sticky;topic=' . $context['current_topic'] . '.' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id']),

+ 1 - 1
Themes/default/MessageIndex.template.php

@@ -303,7 +303,7 @@ function template_main()
 						echo '<a href="', $scripturl, '?action=quickmod;board=', $context['current_board'], '.', $context['start'], ';actions[', $topic['id'], ']=sticky;', $context['session_var'], '=', $context['session_id'], '" onclick="return confirm(\'', $txt['quickmod_confirm'], '\');"><img src="', $settings['images_url'], '/icons/quick_sticky.png" width="16" alt="', $txt['set_sticky'], '" title="', $txt['set_sticky'], '" /></a>';
 
 					if ($topic['quick_mod']['move'])
-						echo '<a href="', $scripturl, '?action=movetopic;board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><img src="', $settings['images_url'], '/icons/quick_move.png" width="16" alt="', $txt['move_topic'], '" title="', $txt['move_topic'], '" /></a>';
+						echo '<a href="', $scripturl, '?action=movetopic;current_board=', $context['current_board'], ';board=', $context['current_board'], '.', $context['start'], ';topic=', $topic['id'], '.0"><img src="', $settings['images_url'], '/icons/quick_move.png" width="16" alt="', $txt['move_topic'], '" title="', $txt['move_topic'], '" /></a>';
 				}
 				echo '
 					</td>';

+ 1 - 1
Themes/default/MoveTopic.template.php

@@ -19,7 +19,7 @@ function template_main()
 
 	echo '
 	<div id="move_topic" class="lower_padding">
-		<form action="', $scripturl, '?action=movetopic2;topic=', $context['current_topic'], '.0" method="post" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">
+		<form action="', $scripturl, '?action=movetopic2;current_board=' . $context['current_board'] . ';topic=', $context['current_topic'], '.0" method="post" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);">
 			<div class="cat_bar">
 				<h3 class="catbg">', $txt['move_topic'], '</h3>
 			</div>

+ 1 - 0
Themes/default/languages/Errors.english.php

@@ -168,6 +168,7 @@ $txt['no_span'] = 'The span feature is currently disabled.';
 $txt['invalid_days_numb'] = 'Invalid number of days to span.';
 
 $txt['moveto_noboards'] = 'There are no boards to move this topic to!';
+$txt['topic_already_moved'] = 'This topic %1$s has been moved to the board %2$s, please check its new location before moving it again.';
 
 $txt['already_activated'] = 'Your account has already been activated.';
 $txt['still_awaiting_approval'] = 'Your account is still awaiting admin approval.';