소스 검색

Merge pull request #720 from Joker-SMF/release-2.1

- Fix for #383
Arantor 11 년 전
부모
커밋
589bb4d29e
2개의 변경된 파일28개의 추가작업 그리고 32개의 파일을 삭제
  1. 25 28
      Sources/ManageNews.php
  2. 3 4
      Themes/default/ManageNews.template.php

+ 25 - 28
Sources/ManageNews.php

@@ -522,7 +522,6 @@ function ComposeMailing()
 		$context['recipients']['emails'] = !empty($_POST['emails']) ? explode(';', $_POST['emails']) : array();
 		$context['email_force'] = !empty($_POST['email_force']) ? 1 : 0;
 		$context['total_emails'] = !empty($_POST['total_emails']) ? (int) $_POST['total_emails'] : 0;
-		$context['max_id_member'] = !empty($_POST['max_id_member']) ? (int) $_POST['max_id_member'] : 0;
 		$context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
 		$context['send_html'] = !empty($_POST['send_html']) ? '1' : '0';
 
@@ -659,12 +658,12 @@ function ComposeMailing()
 	// For progress bar!
 	$context['total_emails'] = count($context['recipients']['emails']);
 	$request = $smcFunc['db_query']('', '
-		SELECT MAX(id_member)
+		SELECT COUNT(*)
 		FROM {db_prefix}members',
 		array(
 		)
 	);
-	list ($context['max_id_member']) = $smcFunc['db_fetch_row']($request);
+	list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
 	$smcFunc['db_free_result']($request);
 
 	// Clean up the arrays.
@@ -708,10 +707,23 @@ function SendMailing($clean_only = false)
 	$context['email_force'] = !empty($_POST['email_force']) ? 1 : 0;
 	$context['send_pm'] = !empty($_POST['send_pm']) ? 1 : 0;
 	$context['total_emails'] = !empty($_POST['total_emails']) ? (int) $_POST['total_emails'] : 0;
-	$context['max_id_member'] = !empty($_POST['max_id_member']) ? (int) $_POST['max_id_member'] : 0;
 	$context['send_html'] = !empty($_POST['send_html']) ? '1' : '0';
 	$context['parse_html'] = !empty($_POST['parse_html']) ? '1' : '0';
 
+	//One can't simply nullify things around
+	if(empty($_REQUEST['total_members'])) {
+		$request = $smcFunc['db_query']('', '
+			SELECT COUNT(*)
+			FROM {db_prefix}members',
+			array(
+			)
+		);
+		list ($context['total_members']) = $smcFunc['db_fetch_row']($request);
+		$smcFunc['db_free_result']($request);
+	} else {
+		$context['total_members'] = (int) $_REQUEST['total_members'];
+	}
+
 	// Create our main context.
 	$context['recipients'] = array(
 		'groups' => array(),
@@ -884,8 +896,6 @@ function SendMailing($clean_only = false)
 		$i++;
 	}
 
-	// Got some more to send this batch?
-	$last_id_member = 0;
 	if ($i < $num_at_once)
 	{
 		// Need to build quite a query!
@@ -937,16 +947,13 @@ function SendMailing($clean_only = false)
 		$result = $smcFunc['db_query']('', '
 			SELECT mem.id_member, mem.email_address, mem.real_name, mem.id_group, mem.additional_groups, mem.id_post_group
 			FROM {db_prefix}members AS mem
-			WHERE mem.id_member > {int:min_id_member}
-				AND mem.id_member < {int:max_id_member}
-				AND ' . $sendQuery . '
+			WHERE ' . $sendQuery . '
 				AND mem.is_activated = {int:is_activated}
 			ORDER BY mem.id_member ASC
-			LIMIT {int:atonce}',
+			LIMIT {int:start}, {int:atonce}',
 			array_merge($sendParams, array(
-				'min_id_member' => $context['start'],
-				'max_id_member' => $context['start'] + $num_at_once - $i,
-				'atonce' => $num_at_once - $i,
+				'start' => $context['start'],
+				'atonce' => $num_at_once,
 				'regular_group' => 0,
 				'notify_announcements' => 1,
 				'is_activated' => 1,
@@ -955,8 +962,6 @@ function SendMailing($clean_only = false)
 
 		while ($row = $smcFunc['db_fetch_assoc']($result))
 		{
-			$last_id_member = $row['id_member'];
-
 			// What groups are we looking at here?
 			if (empty($row['additional_groups']))
 				$groups = array($row['id_group'], $row['id_post_group']);
@@ -999,26 +1004,18 @@ function SendMailing($clean_only = false)
 		$smcFunc['db_free_result']($result);
 	}
 
-	// If used our batch assume we still have a member.
-	if ($i >= $num_at_once)
-		$last_id_member = $context['start'];
-	// Or we didn't have one in range?
-	elseif (empty($last_id_member) && $context['start'] + $num_at_once < $context['max_id_member'])
-		$last_id_member = $context['start'] + $num_at_once;
-	// If we have no id_member then we're done.
-	elseif (empty($last_id_member) && empty($context['recipients']['emails']))
+
+	$context['start'] = $context['start'] + $num_at_once;
+	if (empty($context['recipients']['emails']) && ($context['start'] >= $context['total_members']))
 	{
 		// Log this into the admin log.
 		logAction('newsletter', array(), 'admin');
-
 		redirectexit('action=admin');
 	}
 
-	$context['start'] = $last_id_member;
-
 	// Working out progress is a black art of sorts.
-	$percentEmails = $context['total_emails'] == 0 ? 0 : ((count($context['recipients']['emails']) / $context['total_emails']) * ($context['total_emails'] / ($context['total_emails'] + $context['max_id_member'])));
-	$percentMembers = ($context['start'] / $context['max_id_member']) * ($context['max_id_member'] / ($context['total_emails'] + $context['max_id_member']));
+	$percentEmails = $context['total_emails'] == 0 ? 0 : ((count($context['recipients']['emails']) / $context['total_emails']) * ($context['total_emails'] / ($context['total_emails'] + $context['total_members'])));
+	$percentMembers = ($context['start'] / $context['total_members']) * ($context['total_members'] / ($context['total_emails'] + $context['total_members']));
 	$context['percentage_done'] = round(($percentEmails + $percentMembers) * 100, 2);
 
 	$context['page_title'] = $txt['admin_newsletters'];

+ 3 - 4
Themes/default/ManageNews.template.php

@@ -261,8 +261,7 @@ function template_email_members_compose()
 			</div>
 			<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
 			<input type="hidden" name="email_force" value="', $context['email_force'], '" />
-			<input type="hidden" name="total_emails" value="', $context['total_emails'], '" />
-			<input type="hidden" name="max_id_member" value="', $context['max_id_member'], '" />';
+			<input type="hidden" name="total_emails" value="', $context['total_emails'], '" />';
 
 	foreach ($context['recipients'] as $key => $values)
 		echo '
@@ -420,8 +419,8 @@ function template_email_members_send()
 					<input type="hidden" name="subject" value="', $context['subject'], '" />
 					<input type="hidden" name="message" value="', $context['message'], '" />
 					<input type="hidden" name="start" value="', $context['start'], '" />
+					<input type="hidden" name="total_members" value="', $context['total_members'], '" />
 					<input type="hidden" name="total_emails" value="', $context['total_emails'], '" />
-					<input type="hidden" name="max_id_member" value="', $context['max_id_member'], '" />
 					<input type="hidden" name="send_pm" value="', $context['send_pm'], '" />
 					<input type="hidden" name="send_html" value="', $context['send_html'], '" />
 					<input type="hidden" name="parse_html" value="', $context['parse_html'], '" />';
@@ -456,4 +455,4 @@ function template_email_members_send()
 	// ]]></script>';
 }
 
-?>
+?>