PDA

View Full Version : SMF user merging script



Lefteris_D
December 10th, 2004, 12:17
This is my first real addon for a forum other than Invision or vBulletin3 so some debugging is required. If anyone has an SMF installed as well I'd be very happy if you can have it tested.

Just drop it in the root directory of your forum and log in as any valid administrator account.


<?php

require(dirname(__FILE__) . '/SSI.php');
require_once($sourcedir . '/ManageMembers.php');

// Check if user is Administrator
if (!$context['allow_admin'])
{
echo 'A valid administrator forum session is required to access this page.';
exit;
}

?>

<html>
<home>
<title>SMF User Merging Script</title>
</home>
<body>
<br />
<table border="1" width="800" align="center" bgcolor="lightgray">
<tr>
<td align="center"><b>SMF User Merging Script</b></td>
</tr>
<?php
if (isset($_POST['step'])) {
//Continue
} else {
?>
<tr>
<td>
This script will allow a forum administrator to merge two users into one. The script currently supports:
<ul>
<li>User topics</li>
<li>User posts</li>
<li>User callendar events</li>
<li>User Attachments</li>
<li>Private Messages</li>
</ul>
Everything else shall be removed once the "source user" has been deleted. To perform the operation you need the source user and destination user ID's.
<br />
</br />
<span style="color: darkred;"><b>Please Note:</b> This script comes with no support and it might damage your forum. A database backup before continuing is suggested. Also make sure that both user ID's are valid.</span>
<br />
<br />
<div align="center"><FORM action="smf-merge-users.php" method="post"><INPUT type="hidden" name="step" value="dataform"><INPUT type="submit" value="Begin"></FORM></div>
</td>
</tr>
<?php
exit;
}

if ($_POST['step'] == 'dataform')
{
// ok
}
else
{
// Catch 0 bug
if ($_POST['destinationid'] == '0')
{
echo '<tr><td>';
echo '<div align="center"><b>Warning:</b> Destination User ID cannot be 0</div>';
echo '</td></tr>';
echo '</table></body></html>';
exit;
}
else
{
// do nothing
}
if ($_POST['sourceid'] == '0')
{
echo '<tr><td>';
echo '<div align="center"><b>Warning:</b> Source User ID cannot be 0</div>';
echo '</td></tr>';
echo '</table></body></html>';
exit;
}
else
{
// do nothing
}

// $_POST['destinationid'] and $_POST['sourceid'] must not be the same
if ($_POST['destinationid'] == $_POST['sourceid'])
{
echo '<tr><td>';
echo '<div align="center"><b>Warning:</b> Destination User and Source User cannot be the same</div>';
echo '</td></tr>';
echo '</table></body></html>';
exit;
}
else
{
// do nothing
}

if ($_POST['sourceid'] == '0')
{
echo '<tr><td>';
echo '<div align="center"><b>Warning:</b> Source User ID cannot be 0</div>';
echo '</td></tr>';
echo '</table></body></html>';
exit;
}
else
{
// do nothing
}

// Make sure $_POST['destinationid'] is not null
if ($_POST['destinationid'] == NULL)
{
echo '<tr><td>';
echo '<div align="center"><b>Warning:</b> Destination User ID cannot be empty</div>';
echo '</td></tr>';
echo '</table></body></html>';
exit;
}
else
{
// do nothing
}

// Make sure $_POST['sourceid'] is not null
if ($_POST['sourceid'] == NULL)
{
echo '<tr><td>';
echo '<div align="center"><b>Warning:</b> Source User ID cannot be empty</div>';
echo '</td></tr>';
echo '</table></body></html>';
exit;
}
else
{
// do nothing
}
}
// Let's begin with the steps!

// Data Form (Step 0)
if ($_POST['step'] == 'dataform')
{
echo '<tr><td align="center">Please insert the required information.<br />';
echo '<FORM action="smf-merge-users.php" method="post">Source User(will be deleted): <INPUT type="text" name="sourceid" SIZE="5" MAXLENGTH="5"><br />Destination User(will remain intact)<INPUT type="text" name="destinationid" SIZE="5" MAXLENGTH="5"><br /><INPUT type="hidden" name="step" value="mergethreads"><BR><INPUT type="submit" value="Click to proceed to merge topics"></FORM>';
echo '</td></tr>';
}
else
{
// do nothing
}



// Topic Merging Operation (Step 1)
if ($_POST['step'] == 'mergethreads')
{
$dstid = $_POST['destinationid'];
$srcid = $_POST['sourceid'];

echo '<tr><td><div align="center">Step 1: Μerging Topics<br />';
// Add the SQL code here
db_query("UPDATE {$db_prefix}topics SET ID_MEMBER_STARTED=$dstid WHERE ID_MEMBER_STARTED=$srcid", __FILE__, __LINE__);
db_query("UPDATE {$db_prefix}topics SET ID_MEMBER_UPDATED=$dstid WHERE ID_MEMBER_UPDATED=$srcid", __FILE__, __LINE__);
?>
<FORM action="smf-merge-users.php" method="post"><INPUT type="hidden" name="sourceid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['sourceid']; ?>"><INPUT type="hidden" name="destinationid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['destinationid']; ?>"><br /><INPUT type="hidden" name="step" value="mergeposts"><INPUT type="submit" value="Click to proceed to merge posts"></FORM>
<br />
<?php
echo '</div></td></tr>';
}
else
{
// do nothing
}


// Post Merging Operation (Step 2)
if ($_POST['step'] == 'mergeposts')
{
$dstid = $_POST['destinationid'];
$srcid = $_POST['sourceid'];

echo '<tr><td><div align="center">Step 2: Merging posts<br />';
// Add the SQL code here
db_query("UPDATE {$db_prefix}messages SET ID_MEMBER='$dstid' WHERE ID_MEMBER='$srcid'", __FILE__, __LINE__);
?>
<FORM action="smf-merge-users.php" method="post"><INPUT type="hidden" name="sourceid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['sourceid']; ?>"><INPUT type="hidden" name="destinationid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['destinationid']; ?>"><br /><INPUT type="hidden" name="step" value="mergeattachments"><INPUT type="submit" value="Click to proceed to merge attachments"></FORM>
<br />
<?php
echo '</div></td></tr>';
}
else
{
// do nothing
}


// Merge Attachments (Step 3)
if ($_POST['step'] == 'mergeattachments')
{
$dstid = $_POST['destinationid'];
$srcid = $_POST['sourceid'];
echo '<tr><td><div align="center">Step 3: Merging attachments<br />';
// Add the SQL code here
db_query("UPDATE {$db_prefix}attachments SET ID_MEMBER='$dstid' WHERE ID_MEMBER='$srcid'", __FILE__, __LINE__);
?>
<FORM action="smf-merge-users.php" method="post"><INPUT type="hidden" name="sourceid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['sourceid']; ?>"><INPUT type="hidden" name="destinationid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['destinationid']; ?>"><br /><INPUT type="hidden" name="step" value="mergepm"><INPUT type="submit" value="Merge Private Messages"></FORM>
<br />
<?php
echo '</div></td></tr>';
}
else
{
// do nothing
}

// Merge Private Messages (Step 4)
if ($_POST['step'] == 'mergepm')
{
$dstid = $_POST['destinationid'];
$srcid = $_POST['sourceid'];
echo '<tr><td><div align="center">Step 4: Merging Private Messages<br />';
// Add the SQL code here
db_query("UPDATE {$db_prefix}instant_messages SET ID_MEMBER_FROM='$dstid' WHERE ID_MEMBER_FROM='$srcid'", __FILE__, __LINE__);
db_query("UPDATE {$db_prefix}im_recipients SET ID_MEMBER='$dstid' WHERE ID_MEMBER='$srcid'", __FILE__, __LINE__);
?>
<FORM action="smf-merge-users.php" method="post"><INPUT type="hidden" name="sourceid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['sourceid']; ?>"><INPUT type="hidden" name="destinationid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['destinationid']; ?>"><br /><INPUT type="hidden" name="step" value="mergecallevents"><INPUT type="submit" value="Click to merge callendar events"></FORM>
<br />
<?php
echo '</div></td></tr>';
}
else
{
// do nothing
}

// Merge Callendar Events (Step 5)
if ($_POST['step'] == 'mergecallevents')
{
$dstid = $_POST['destinationid'];
$srcid = $_POST['sourceid'];
echo '<tr><td><div align="center">Step 3: Merging callendar events<br />';
// Add the SQL code here
db_query("UPDATE {$db_prefix}calendar SET ID_MEMBER='$dstid' WHERE ID_MEMBER='$srcid'", __FILE__, __LINE__);
?>
<FORM action="smf-merge-users.php" method="post"><INPUT type="hidden" name="sourceid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['sourceid']; ?>"><INPUT type="hidden" name="destinationid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['destinationid']; ?>"><br /><INPUT type="hidden" name="step" value="deluser"><INPUT type="submit" value="Click to delete user"></FORM>
<br />
<?php
echo '</div></td></tr>';
}
else
{
// do nothing
}

// Delete user and remaining data (Step 6)
if ($_POST['step'] == 'deluser')
{
echo '<tr><td><div align="center">Step 6: Deleting User and remaining data<br />';
$users = $_POST['sourceid'];
// Kill the source user
deleteMembers($users)
?>
<FORM action="smf-merge-users.php" method="post">
<INPUT type="hidden" name="sourceid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['sourceid']; ?>">
<INPUT type="hidden" name="destinationid" SIZE="5" MAXLENGTH="5" value="<? echo $_POST['destinationid']; ?>">
<br />
<INPUT type="hidden" name="step" value="showfinal"><INPUT type="submit" value="Continue"></FORM>
</div><br /></td></tr>
<?
}
else
{
// do nothing
}

// Show Final Message (Step 7)
if ($_POST['step'] == 'showfinal')
{
echo '<tr><td><br /><div align="center">The source user has been deleted!<br />Please check your forum to ensure that the user merging was a success.<br /><br /><a href="smf-merge-users.php" target="_self">Back To Start</a><br /><br /></div></td></tr>';
}
else
{
// do nothing
}
?>
</table>
</body>
</html>

Code Updated


Currently merges: User topics
User posts
User callendar events
User Attachments
Private Messages
Everything else shall be removed once the "source user" has been deleted.

Any comments are welcome.

Jale
December 13th, 2004, 01:14
How do I put that on my phpbbplanet forum? Can I use a FTP client to do that? (if it's possible) :huh:

Lefteris_D
December 13th, 2004, 10:59
Sorry, you need to have SMF (http://www.simplemachines.org/community/index.php) installed and FTP access.

It does not work on phpBB.