Code Duplication    Length = 54-56 lines in 4 locations

Sources/ManageMaintenance.php 4 locations

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