Code Duplication    Length = 54-56 lines in 4 locations

Sources/ManageMaintenance.php 4 locations

@@ 912-967 (lines=56) @@
909
	}
910
911
	// Update the post count of each board.
912
	if ($_REQUEST['step'] <= 1)
913
	{
914
		if (empty($_REQUEST['start']))
915
			$smcFunc['db_query']('', '
916
				UPDATE {db_prefix}boards
917
				SET num_posts = {int:num_posts}
918
				WHERE redirect = {string:redirect}',
919
				array(
920
					'num_posts' => 0,
921
					'redirect' => '',
922
				)
923
			);
924
925
		while ($_REQUEST['start'] < $max_topics)
926
		{
927
			$request = $smcFunc['db_query']('', '
928
				SELECT /*!40001 SQL_NO_CACHE */ m.id_board, COUNT(*) AS real_num_posts
929
				FROM {db_prefix}messages AS m
930
				WHERE m.id_topic > {int:id_topic_min}
931
					AND m.id_topic <= {int:id_topic_max}
932
					AND m.approved = {int:is_approved}
933
				GROUP BY m.id_board',
934
				array(
935
					'id_topic_min' => $_REQUEST['start'],
936
					'id_topic_max' => $_REQUEST['start'] + $increment,
937
					'is_approved' => 1,
938
				)
939
			);
940
			while ($row = $smcFunc['db_fetch_assoc']($request))
941
				$smcFunc['db_query']('', '
942
					UPDATE {db_prefix}boards
943
					SET num_posts = num_posts + {int:real_num_posts}
944
					WHERE id_board = {int:id_board}',
945
					array(
946
						'id_board' => $row['id_board'],
947
						'real_num_posts' => $row['real_num_posts'],
948
					)
949
				);
950
			$smcFunc['db_free_result']($request);
951
952
			$_REQUEST['start'] += $increment;
953
954
			if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3)
955
			{
956
				createToken('admin-boardrecount');
957
				$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '">';
958
959
				$context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=1;start=' . $_REQUEST['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
960
				$context['continue_percent'] = round((200 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
961
962
				return;
963
			}
964
		}
965
966
		$_REQUEST['start'] = 0;
967
	}
968
969
	// Update the topic count of each board.
970
	if ($_REQUEST['step'] <= 2)
@@ 970-1023 (lines=54) @@
967
	}
968
969
	// Update the topic count of each board.
970
	if ($_REQUEST['step'] <= 2)
971
	{
972
		if (empty($_REQUEST['start']))
973
			$smcFunc['db_query']('', '
974
				UPDATE {db_prefix}boards
975
				SET num_topics = {int:num_topics}',
976
				array(
977
					'num_topics' => 0,
978
				)
979
			);
980
981
		while ($_REQUEST['start'] < $max_topics)
982
		{
983
			$request = $smcFunc['db_query']('', '
984
				SELECT /*!40001 SQL_NO_CACHE */ t.id_board, COUNT(*) AS real_num_topics
985
				FROM {db_prefix}topics AS t
986
				WHERE t.approved = {int:is_approved}
987
					AND t.id_topic > {int:id_topic_min}
988
					AND t.id_topic <= {int:id_topic_max}
989
				GROUP BY t.id_board',
990
				array(
991
					'is_approved' => 1,
992
					'id_topic_min' => $_REQUEST['start'],
993
					'id_topic_max' => $_REQUEST['start'] + $increment,
994
				)
995
			);
996
			while ($row = $smcFunc['db_fetch_assoc']($request))
997
				$smcFunc['db_query']('', '
998
					UPDATE {db_prefix}boards
999
					SET num_topics = num_topics + {int:real_num_topics}
1000
					WHERE id_board = {int:id_board}',
1001
					array(
1002
						'id_board' => $row['id_board'],
1003
						'real_num_topics' => $row['real_num_topics'],
1004
					)
1005
				);
1006
			$smcFunc['db_free_result']($request);
1007
1008
			$_REQUEST['start'] += $increment;
1009
1010
			if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3)
1011
			{
1012
				createToken('admin-boardrecount');
1013
				$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '">';
1014
1015
				$context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=2;start=' . $_REQUEST['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1016
				$context['continue_percent'] = round((300 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
1017
1018
				return;
1019
			}
1020
		}
1021
1022
		$_REQUEST['start'] = 0;
1023
	}
1024
1025
	// Update the unapproved post count of each board.
1026
	if ($_REQUEST['step'] <= 3)
@@ 1026-1079 (lines=54) @@
1023
	}
1024
1025
	// Update the unapproved post count of each board.
1026
	if ($_REQUEST['step'] <= 3)
1027
	{
1028
		if (empty($_REQUEST['start']))
1029
			$smcFunc['db_query']('', '
1030
				UPDATE {db_prefix}boards
1031
				SET unapproved_posts = {int:unapproved_posts}',
1032
				array(
1033
					'unapproved_posts' => 0,
1034
				)
1035
			);
1036
1037
		while ($_REQUEST['start'] < $max_topics)
1038
		{
1039
			$request = $smcFunc['db_query']('', '
1040
				SELECT /*!40001 SQL_NO_CACHE */ m.id_board, COUNT(*) AS real_unapproved_posts
1041
				FROM {db_prefix}messages AS m
1042
				WHERE m.id_topic > {int:id_topic_min}
1043
					AND m.id_topic <= {int:id_topic_max}
1044
					AND m.approved = {int:is_approved}
1045
				GROUP BY m.id_board',
1046
				array(
1047
					'id_topic_min' => $_REQUEST['start'],
1048
					'id_topic_max' => $_REQUEST['start'] + $increment,
1049
					'is_approved' => 0,
1050
				)
1051
			);
1052
			while ($row = $smcFunc['db_fetch_assoc']($request))
1053
				$smcFunc['db_query']('', '
1054
					UPDATE {db_prefix}boards
1055
					SET unapproved_posts = unapproved_posts + {int:unapproved_posts}
1056
					WHERE id_board = {int:id_board}',
1057
					array(
1058
						'id_board' => $row['id_board'],
1059
						'unapproved_posts' => $row['real_unapproved_posts'],
1060
					)
1061
				);
1062
			$smcFunc['db_free_result']($request);
1063
1064
			$_REQUEST['start'] += $increment;
1065
1066
			if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3)
1067
			{
1068
				createToken('admin-boardrecount');
1069
				$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '">';
1070
1071
				$context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=3;start=' . $_REQUEST['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1072
				$context['continue_percent'] = round((400 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
1073
1074
				return;
1075
			}
1076
		}
1077
1078
		$_REQUEST['start'] = 0;
1079
	}
1080
1081
	// Update the unapproved topic count of each board.
1082
	if ($_REQUEST['step'] <= 4)
@@ 1082-1135 (lines=54) @@
1079
	}
1080
1081
	// Update the unapproved topic count of each board.
1082
	if ($_REQUEST['step'] <= 4)
1083
	{
1084
		if (empty($_REQUEST['start']))
1085
			$smcFunc['db_query']('', '
1086
				UPDATE {db_prefix}boards
1087
				SET unapproved_topics = {int:unapproved_topics}',
1088
				array(
1089
					'unapproved_topics' => 0,
1090
				)
1091
			);
1092
1093
		while ($_REQUEST['start'] < $max_topics)
1094
		{
1095
			$request = $smcFunc['db_query']('', '
1096
				SELECT /*!40001 SQL_NO_CACHE */ t.id_board, COUNT(*) AS real_unapproved_topics
1097
				FROM {db_prefix}topics AS t
1098
				WHERE t.approved = {int:is_approved}
1099
					AND t.id_topic > {int:id_topic_min}
1100
					AND t.id_topic <= {int:id_topic_max}
1101
				GROUP BY t.id_board',
1102
				array(
1103
					'is_approved' => 0,
1104
					'id_topic_min' => $_REQUEST['start'],
1105
					'id_topic_max' => $_REQUEST['start'] + $increment,
1106
				)
1107
			);
1108
			while ($row = $smcFunc['db_fetch_assoc']($request))
1109
				$smcFunc['db_query']('', '
1110
					UPDATE {db_prefix}boards
1111
					SET unapproved_topics = unapproved_topics + {int:real_unapproved_topics}
1112
					WHERE id_board = {int:id_board}',
1113
					array(
1114
						'id_board' => $row['id_board'],
1115
						'real_unapproved_topics' => $row['real_unapproved_topics'],
1116
					)
1117
				);
1118
			$smcFunc['db_free_result']($request);
1119
1120
			$_REQUEST['start'] += $increment;
1121
1122
			if (array_sum(explode(' ', microtime())) - array_sum(explode(' ', $time_start)) > 3)
1123
			{
1124
				createToken('admin-boardrecount');
1125
				$context['continue_post_data'] = '<input type="hidden" name="' . $context['admin-boardrecount_token_var'] . '" value="' . $context['admin-boardrecount_token'] . '">';
1126
1127
				$context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recount;step=4;start=' . $_REQUEST['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
1128
				$context['continue_percent'] = round((500 + 100 * $_REQUEST['start'] / $max_topics) / $total_steps);
1129
1130
				return;
1131
			}
1132
		}
1133
1134
		$_REQUEST['start'] = 0;
1135
	}
1136
1137
	// Get all members with wrong number of personal messages.
1138
	if ($_REQUEST['step'] <= 5)