Browse Source

! When reattributing, updated reported posts and also return the count of what changed.

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 years ago
parent
commit
fb69d09769
1 changed files with 37 additions and 11 deletions
  1. 37 11
      Sources/Subs-Members.php

+ 37 - 11
Sources/Subs-Members.php

@@ -1168,6 +1168,12 @@ function reattributePosts($memID, $email = false, $membername = false, $post_cou
 {
 	global $smcFunc;
 
+	$updated = array(
+		'messages' => 0,
+		'topics' => 0,
+		'reports' => 0,
+	);
+
 	// Firstly, if email and username aren't passed find out the members email address and name.
 	if ($email === false && $membername === false)
 	{
@@ -1229,20 +1235,40 @@ function reattributePosts($memID, $email = false, $membername = false, $post_cou
 			'member_name' => $membername,
 		)
 	);
+	$updated['messages'] = $smcFunc['db_affected_rows']();
 
-	// ...and the topics too!
-	$smcFunc['db_query']('', '
-		UPDATE {db_prefix}topics as t, {db_prefix}messages as m
-		SET t.id_member_started = {int:memID}
-		WHERE m.id_member = {int:memID}
-			AND t.id_first_msg = m.id_msg',
-		array(
-			'memID' => $memID,
-		)
-	);
+	// Did we update any messages?
+	if ($updated['messages'] > 0)
+	{
+		// First, check for updated topics.
+		$smcFunc['db_query']('', '
+			UPDATE {db_prefix}topics as t, {db_prefix}messages as m
+			SET t.id_member_started = {int:memID}
+			WHERE m.id_member = {int:memID}
+				AND t.id_first_msg = m.id_msg',
+			array(
+				'memID' => $memID,
+			)
+		);
+		$updated['topics'] = $smcFunc['db_affected_rows']();
+
+		// Second, check for updated reports.
+		$smcFunc['db_query']('', '
+			UPDATE {db_prefix}log_reported AS lr, {db_prefix}messages AS m
+			SET lr.id_member = {int:memID}
+			WHERE lr.id_msg = m.id_msg
+				AND m.id_member = {int:memID}',
+			array(
+				'memID' => $memID,
+			)
+		);
+		$updated['reports'] = $smcFunc['db_affected_rows']();
+	}
 
 	// Allow mods with their own post tables to reattribute posts as well :)
- 	call_integration_hook('integrate_reattribute_posts', array($memID, $email, $membername, $post_count));
+ 	call_integration_hook('integrate_reattribute_posts', array($memID, $email, $membername, $post_count, &$updated));
+
+	return $updated;
 }
 
 /**