Code Duplication    Length = 54-56 lines in 4 locations

Sources/ManageMaintenance.php 4 locations

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