Browse Source

+ Add more options for the move topics maintenance task (per #853)

Signed-off-by: Michael Eshom <oldiesmann@oldiesmann.us>
Michael Eshom 11 years ago
parent
commit
22f5e73e82

+ 59 - 14
Sources/ManageMaintenance.php

@@ -1881,23 +1881,61 @@ function MaintainMassMoveTopics()
 	$context['start_time'] = time();
 
 	// First time we do this?
-	$id_board_from = isset($_POST['id_board_from']) ? (int) $_POST['id_board_from'] : (int) $_REQUEST['id_board_from'];
-	$id_board_to = isset($_POST['id_board_to']) ? (int) $_POST['id_board_to'] : (int) $_REQUEST['id_board_to'];
+	$id_board_from = isset($_REQUEST['id_board_from']) ? (int) $_REQUEST['id_board_from'] : 0;
+	$id_board_to = isset($_REQUEST['id_board_to']) ? (int) $_REQUEST['id_board_to'] : 0;
+	$max_days = isset($_REQUEST['maxdays']) ? (int) $_REQUEST['maxdays'] : 0;
+	$locked = isset($_POST['move_type_locked']) || isset($_GET['locked']);
+	$sticky = isset($_POST['move_type_sticky']) || isset($_GET['sticky']);
+	$join = '';
 
 	// No boards then this is your stop.
 	if (empty($id_board_from) || empty($id_board_to))
 		return;
 
+	// The big WHERE clause
+	$condition = 'WHERE t.id_board = {int:id_board_from}
+		AND t.id_redirect_topic = {int:not_redirect}';
+
+	// DB parameters
+	$params = array(
+		'id_board_from' => $id_board_from,
+		'not_redirect' => 0,
+	);
+
+	// Only moving topics not posted in for x days?
+	if (!empty($max_days))
+	{
+		$join = '	INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_last_msg)';
+		$condition .= '
+			AND m.poster_time < {int:poster_time}';
+		$params['poster_time'] = time() - 3600 * 24 * $max_days;
+	}
+
+	// Moving locked topics?
+	if ($locked)
+	{
+		$condition .= '
+			AND t.locked = {int:locked}';
+		$params['locked'] = 1;	
+	}
+
+	// What about sticky topics?
+	if ($sticky)
+	{
+		$condition .= '
+			AND t.sticky = {int:sticky}';
+		$params['sticky'] = 1;
+	}
+
 	// How many topics are we converting?
 	if (!isset($_REQUEST['totaltopics']))
 	{
 		$request = $smcFunc['db_query']('', '
 			SELECT COUNT(*)
-			FROM {db_prefix}topics
-			WHERE id_board = {int:id_board_from}',
-			array(
-				'id_board_from' => $id_board_from,
-			)
+			FROM {db_prefix}topics AS t
+			' . $join .
+			$conditions,
+			$params
 		);
 		list ($total_topics) = $smcFunc['db_fetch_row']($request);
 		$smcFunc['db_free_result']($request);
@@ -1906,7 +1944,15 @@ function MaintainMassMoveTopics()
 		$total_topics = (int) $_REQUEST['totaltopics'];
 
 	// Seems like we need this here.
-	$context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
+	$context['continue_get_data'] = '?action=admin;area=maintain;sa=topics;activity=massmove;id_board_from=' . $id_board_from . ';id_board_to=' . $id_board_to . ';totaltopics=' . $total_topics . ';max_days=' . $max_days;
+
+	if ($locked)
+		$context['continue_get_data'] .= ';locked';
+
+	if ($sticky)
+		$context['continue_get_data'] .= ';sticky';
+
+	$context['continue_get_data'] .= ';start=' . $context['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
 
 	// We have topics to move so start the process.
 	if (!empty($total_topics))
@@ -1915,13 +1961,12 @@ function MaintainMassMoveTopics()
 		{
 			// Lets get the topics.
 			$request = $smcFunc['db_query']('', '
-				SELECT id_topic
-				FROM {db_prefix}topics
-				WHERE id_board = {int:id_board_from}
+				SELECT t.id_topic
+				FROM {db_prefix}topics AS t
+				' . $join
+				. $conditions . '
 				LIMIT 10',
-				array(
-					'id_board_from' => $id_board_from,
-				)
+				$params
 			);
 
 			// Get the ids.

+ 7 - 0
Themes/default/ManageMaintenance.template.php

@@ -516,6 +516,13 @@ function template_maintain_topics()
 	}
 	echo '
 					</select></p>
+					<p>
+						', $txt['move_topics_older_than'], '<input type="text" name="maxdays" value="30" size="3" />', $txt['manageposts_days'], '&nbsp;(', $txt['move_zero_all'], ')
+					</p>
+					<p>
+						<label for="move_type_locked"><input type="checkbox" name="move_type_locked" id="move_type_locked" class="input_check" checked="checked" /> ', $txt['move_type_locked'], '</label><br />
+						<label for="move_type_sticky"><input type="checkbox" name="move_type_sticky" id="move_type_sticky" class="input_check" /> ', $txt['move_type_sticky'], '</label><br />
+					</p>
 					<input type="submit" value="', $txt['move_topics_now'], '" onclick="if (document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_from\').selectedIndex].disabled || document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_to\').selectedIndex].disabled) return false; var confirmText = \'', $txt['move_topics_confirm'] . '\'; return confirm(confirmText.replace(/%board_from%/, document.getElementById(\'id_board_from\').options[document.getElementById(\'id_board_from\').selectedIndex].text.replace(/^=+&gt;&nbsp;/, \'\')).replace(/%board_to%/, document.getElementById(\'id_board_to\').options[document.getElementById(\'id_board_to\').selectedIndex].text.replace(/^=+&gt;&nbsp;/, \'\')));" class="button_submit" />
 					<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
 					<input type="hidden" name="', $context['admin-maint_token_var'], '" value="', $context['admin-maint_token'], '" />

+ 4 - 0
Themes/default/languages/ManageMaintenance.english.php

@@ -215,6 +215,10 @@ $txt['move_topics_from'] = 'Move topics from';
 $txt['move_topics_to'] = 'to';
 $txt['move_topics_now'] = 'Move now';
 $txt['move_topics_confirm'] = 'Are you sure you want to move ALL the topics from &quot;%board_from%&quot; to &quot;%board_to%&quot;?';
+$txt['move_topics_older_than'] = 'Move topics not posted in for ';
+$txt['move_type_sticky'] = 'Sticky topics';
+$txt['move_type_locked'] = 'Locked topics';
+$txt['move_zero_all'] = 'Enter 0 to move all topics';
 
 $txt['maintain_reattribute_posts'] = 'Reattribute User Posts';
 $txt['reattribute_guest_posts'] = 'Attribute guest posts made with';