Code Duplication    Length = 54-56 lines in 4 locations

Sources/ManageMaintenance.php 4 locations

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