News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

SMF merge script

Started by gamesmad, August 26, 2006, 10:33:32 AM

Previous topic - Next topic

gamesmad

Im working on an SMF merge script, so far, I have completed the reading of the main database and the modification of the database to be imported.  Tonight I will work on saving the contents of the database to be imported to the main database, and hopefully Ill have a first version ready for tommorow.

Now the important thing, are there any features anyone would like to see in the merge script??  Post in this topic, and Ill include your idea if I can.

Heres what has been done so far, and also what I plan to do -

Create new IDs for the imported database - Done

All IDs EXCEPT calendar holidays, collapsed boards, sessions, settings and themes are added to the highest ID in the main database, so nothing gets overwritten.

Save all the newly created IDs into the main database - Not done yet

All of the new IDs, along with their content, are saved in the main forums database.

All topic references changed - Not done yet

When a topic is moved, a link is made, also users of the forum might have linked to other topics.  The topic IDs will have changed if they have been imported, so every imported message must be searched for topic IDs, and they must all be replaced with their new IDs.

Thanks for your input,

Will

I have copied this from my other post so its easier to find -

I figure I may as well give this out now.  Just to make it absolutely clear, this is not a finished script, and Im only posting it for you guys to pick holes in/modify.  If you modify it I would appreciate it if you post your new code here so we can all use it.

<?php

// Include the settings files
require "Settings.php";
require 
"mergesettings.php";

// Connect to the main forum database
mysql_connect($db_server,$db_user,$db_passwd);
@
mysql_select_db($db_name) or die( "Unable to select main SMF forum database, make sure this script is in your SMF root directory");

echo 
"<b>OK, first we need to get some information about the main forum, so that we dont duplicate IDs when we add in the other forums database.</b> <br>";

// Heres the highest_id function, which finds the highest ID in a database, and informs the user,
// but more importantly, returns the number for use in our script.
function highest_id ($idname,$dbname,$name)
{
require 
"Settings.php";
$query="SELECT MAX(`ID_{$idname}`) FROM {$db_prefix}{$dbname}";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
        {
        while( list (
$key$value) = each($row) )
                {
                echo 
"Number of $name : $value <br>";
        
$number "number";
        
$temp "$dbname$number";
            $
$temp $value;
        return $
$temp;
                }
        }
}

// Find the highest attachment ID
$attachmentsnumber highest_id ("ATTACH","attachments","attachments");

// Find the highest ban group ID
$bangroupsnumber highest_id ("BAN_GROUP","ban_groups","ban groups");

// Find the highest ban item ID
$banitemsnumber highest_id ("BAN","ban_items","ban items");

echo 
"No info about the board permissions table needed <br>";

// Find the highest board ID
$boardsnumber highest_id ("BOARD","boards","boards");

// Find the highest calendar event ID
$calendarnumber highest_id ("EVENT","calendar","calendar events");

echo 
"Calendar holidays not merged, ask me if you really need them <br>";

// Find the highest category ID
$categoriesnumber highest_id ("CAT","categories","categories");

echo 
"Collapsed categories not merged, ask me if you really need them <br>";

echo 
"None of the logs need merging, ask me if you really need them <br>";

// Find the highest membergroup ID
$membergroupsnumber highest_id ("GROUP","membergroups","membergroups");

// Find the highest member ID
$membersnumber highest_id ("MEMBER","members","members");

// Find the highest message icon ID
$messageiconsnumber highest_id ("ICON","message_icons","message icons");

// Find the highest message ID
$messagesnumber highest_id ("MSG","messages","messages");

echo 
"No info about moderators table needed <br>";

// Find the highest package server ID
$packageserversnumber highest_id ("SERVER","package_servers","package servers");

echo 
"No info about permissions table needed <br>";

// Find the highest PM ID
$personalmessagesnumber highest_id ("PM","personal_messages","PMs");

echo 
"No info about the PM recipients table needed <br>";

echo 
"No info about the poll choices table needed <br>";

// Find the highest poll ID
$pollsnumber highest_id ("POLL","polls","polls");

echo 
"Sessions not merged, ask me if you really need them <br>";

echo 
"Settings not merged, ask me if you really need them <br>";

// Find the highest smiley ID
$smileysnumber highest_id ("SMILEY","smileys","smileys");

echo 
"Themes arent imported, just install them on the main forum <br>";

// Find the highest topic ID
$topicsnumber highest_id ("TOPIC","topics","topics");

// Disconnect from the main forum database
mysql_close();

echo 
"<b>Now we have all the IDs, we can get down to business.</b> <br>";

// Connect to the database we are going to import
mysql_connect($import_server,$import_user,$import_passwd);
@
mysql_select_db($import_name) or die( "Unable to select SMF forum database to import, make sure you have set them in \"mergesettings.php\"");

// Adjust the attachment IDs so they dont conflict with the main database, and stick them in an array
$attachmentarray = array();

$query="SELECT ID_ATTACH FROM {$import_prefix}attachments";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$attachmentarray[] = $value $attachmentsnumber;
    echo 
"Attachment $value adjusted to avoid conflict <br>";
}
}

// Adjust the ban groups IDs so they dont conflict with the main database, and stick them in an array
$bangroupsarray = array();

$query="SELECT ID_BAN_GROUP FROM {$import_prefix}ban_groups";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$bangroupsarray[] = $value $bangroupsnumber;
    echo 
"Ban group $value adjusted to avoid conflict <br>";
}
}

// Adjust the ban items IDs so they dont conflict with the main database, and stick them in an array
$banitemsarray = array();

$query="SELECT ID_BAN FROM {$import_prefix}ban_items";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$banitemsarray[] = $value $banitemsnumber;
    echo 
"Ban item $value adjusted to avoid conflict <br>";
}
}

// Adjust the board permissions IDs so they dont conflict with the main database, and stick them in an array
$boardpermissionsarray = array();

$query="SELECT ID_GROUP FROM {$import_prefix}board_permissions";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$boardpermissionsarray[] = $value $membergroupsnumber 2;
    echo 
"Board permission $value adjusted to avoid conflict <br>";
}
}

// Adjust the board IDs so they dont conflict with the main database, and stick them in an array
$boardsarray = array();

$query="SELECT ID_BOARD FROM {$import_prefix}boards";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$boardsarray[] = $value $boardsnumber;
    echo 
"Board $value adjusted to avoid conflict <br>";
}
}

// Adjust the calendar item IDs so they dont conflict with the main database, and stick them in an array
$calendararray = array();

$query="SELECT ID_EVENT FROM {$import_prefix}calendar";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$calendararray[] = $value $calendarnumber;
    echo 
"Calendar entry $value adjusted to avoid conflict <br>";
}
}

// Adjust the category IDs so they dont conflict with the main database, and stick them in an array
$categoriesarray = array();

$query="SELECT ID_CAT FROM {$import_prefix}categories";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$categoriesarray[] = $value $categoriesnumber;
    echo 
"Category $value adjusted to avoid conflict <br>";
}
}

// Adjust the membergroup IDs so they dont conflict with the main database, and stick them in an array
$membergroupsarray = array();

$query="SELECT ID_GROUP FROM {$import_prefix}membergroups";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$membergroupsarray[] = $value $membergroupsnumber;
    echo 
"Membergroup $value adjusted to avoid conflict <br>";
}
}

// Adjust the member IDs so they dont conflict with the main database, and stick them in an array
$membersarray = array();

$query="SELECT ID_MEMBER FROM {$import_prefix}members";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$membersarray[] = $value $membersnumber;
    echo 
"Member $value adjusted to avoid conflict <br>";
}
}

// Adjust the message icon IDs so they dont conflict with the main database, and stick them in an array
$messageiconsarray = array();

$query="SELECT ID_ICON FROM {$import_prefix}message_icons";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$messageiconsarray[] = $value $messageiconsnumber;
    echo 
"Message icon $value adjusted to avoid conflict <br>";
}
}

// Adjust the message IDs so they dont conflict with the main database, and stick them in an array
$messagesarray = array();

$query="SELECT ID_MSG FROM {$import_prefix}messages";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$messagesarray[] = $value $messagesnumber;
    echo 
"Message $value adjusted to avoid conflict <br>";
}
}

// Adjust the package server IDs so they dont conflict with the main database, and stick them in an array
$packageserversarray = array();

$query="SELECT ID_SERVER FROM {$import_prefix}package_servers";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$packageserversarray[] = $value $packageserversnumber;
    echo 
"Package server $value adjusted to avoid conflict <br>";
}
}

// Adjust the permission IDs so they dont conflict with the main database, and stick them in an array
$permissionsarray = array();

$query="SELECT ID_GROUP FROM {$import_prefix}permissions";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$permissionsarray[] = $value $membergroupsnumber 2;
    echo 
"Permission $value adjusted to avoid conflict <br>";
}
}

// Adjust the PM IDs so they dont conflict with the main database, and stick them in an array
$personalmessagesarray = array();

$query="SELECT ID_PM FROM {$import_prefix}personal_messages";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$personalmessagesarray[] = $value $personalmessagesnumber;
    echo 
"PM $value adjusted to avoid conflict <br>";
}
}

// Adjust the PM recipient IDs so they dont conflict with the main database, and stick them in an array
$pmrecipientarray = array();

$query="SELECT ID_PM FROM {$import_prefix}pm_recipients";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$pmrecipientarray[] = $value $personalmessagesnumber;
    echo 
"PM recipient $value adjusted to avoid conflict <br>";
}
}

// Adjust the poll choice IDs so they dont conflict with the main database, and stick them in an array
$pollchoicesarray = array();

$query="SELECT ID_POLL FROM {$import_prefix}poll_choices";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$pollchoicesarray[] = $value $pollsnumber;
    echo 
"Poll choice $value adjusted to avoid conflict <br>";
}
}

// Adjust the poll IDs so they dont conflict with the main database, and stick them in an array
$pollsarray = array();

$query="SELECT ID_POLL FROM {$import_prefix}polls";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$pollsarray[] = $value $pollsnumber;
    echo 
"Poll $value adjusted to avoid conflict <br>";
}
}

// Adjust the smiley IDs so they dont conflict with the main database, and stick them in an array
$smileysarray = array();

$query="SELECT ID_SMILEY FROM {$import_prefix}smileys";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$smileysarray[] = $value $smileysnumber;
    echo 
"Smiley $value adjusted to avoid conflict <br>";
}
}

// Adjust the topic IDs so they dont conflict with the main database, and stick them in an array
$topicsarray = array();

$query="SELECT ID_TOPIC FROM {$import_prefix}topics";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$topicsarray[] = $value $topicsnumber;
    echo 
"Topic $value adjusted to avoid conflict <br>";
}
}

// Disconnect from the import forum database
mysql_close();

echo 
"<b>We're nearly there, all we have to do is save the rows (now with shiny new IDs) into the database</b> <br>";

// Connect to the main forum database again, if we cant connect now, the server must have exploded
mysql_connect($db_server,$db_user,$db_passwd);
@
mysql_select_db($db_name) or die( "Unable to select main SMF forum database, your server must have exploded");

// OK, lets have some fun writing masses of new rows to the database ;)

function insertrows ($dbname,
{
require 
"Settings.php";
$query="INSERT INTO {$db_prefix}{$dbname}";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
    {
    while( list (
$key$value) = each($row) )
        {
        
$topicsarray[] = $value $topicsnumber;
        echo 
"Topic $value adjusted to avoid conflict <br>";
        }
    }
}
?>


And the mergesettings file -

<?php

// The following settings are for the database you want to import
// You can use a remote server for the database, but it will be slower
$import_server "127.0.0.1";
$import_user "root";
$import_passwd "";
$import_name "rc3";
$import_prefix "forum2_";

?>


If you dont like a part of my code, correct it, dont flame me, as I have put a fair bit of time into this.

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

kegobeer

What is an "SMF merge script"?  Merge into what?
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Gary

I think its to merge two SMF Forums.

-AwwLilMaggie
Gary M. Gadsdon
Do NOT PM me unless I say so
War of the Simpsons
Bongo Comics Fan Forum
Youtube Let's Plays

^ YT is changing monetisation policy, help reach 1000 sub threshold.

gamesmad

Yes, as AwwLilMaggie said, it is to merge two SMF forums into one.  Ive seen a few requests for one, and the best solution was to convert the forums to phpBB, use the phpBB merge script, and then convert back.  So I figure I could make SMF its own merge script to save people some effort ;)

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Harzem

There are a few more people who are working on a merge script also. Let's see who will finish sooner :)

Even I was thinking of writing one, but I'm leaving it for the others, since I'm working on some comprehensive mods for SMF.

When merging forums, I would merge members with the same e-mail address, so if there is a user who is a member of both forums, he won't get duplicate membership for the resultant forum ;)

gamesmad

Thats quite a good idea actually, Ill merge emails awell as usernames, thanks HarZeM :)  Anyone else got any ideas?

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Harzem

I don't suggest merging same usernames. There may be different guys using the same name, even same password. But email addresses are unique.

gamesmad

If I dont merge usernames, what am I going to do with them?  You cant have two of the same username, that would cause all sorts of problems...

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Harzem

That's what the main problem of merging forums is. If you merge users, there is a possibility about them being different users. If you don't, there are duplicate names and you must change one of them.

In SMF, you can login with your email address as well (maybe you didn't know that until now). You may think about a solution using this fact.

gamesmad

No, I didnt know that actually.  If there are duplicate members, the member who created their username first will get to keep it, the other one(s) will have a number added to their name, then they can login with their email addy, complain to the admin and get their username changed.  Not ideal, but its as good as it will be...

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Dannii

Before you merge the database I suggest you do a search for any duplicate email addresses and ask those users to change their's first.
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Harzem

eldacar, I think duplicate email addresses are the ones that should be merged as the same user. Because - they are the same user :)

But duplicate names with different email addies are the problem.

Dannii

Hmm, you could merge the users I suppose :o
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Gary

If there's a duplicate name with a different email, just add something like a "1" on the end, and have the script send an email to the changed user.

An IPB Merge Script did that.

-AwwLilMaggie
Gary M. Gadsdon
Do NOT PM me unless I say so
War of the Simpsons
Bongo Comics Fan Forum
Youtube Let's Plays

^ YT is changing monetisation policy, help reach 1000 sub threshold.

Dannii

For duplicate names change their user names to the email address, and keep their display name the same.
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Harzem

If there are duplicate names, delete them both :P If someone isn't able to be unique, just get rid of that guy!

gamesmad

Quote from: HarzeM on August 28, 2006, 07:56:03 AM
If there are duplicate names, delete them both :P If someone isn't able to be unique, just get rid of that guy!

LOL  :P

I will probably go with AwwLilMaggie suggestion of adding a number and emailing the user.  The user who registered first will get to keep their username.  Or I could use the post count...  Decisions decisions ;)

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Harzem

Quote from: gamesmad on August 28, 2006, 09:42:17 AM
Decisions decisions ;)

What about an option to ask the merger person?

"What would you like to do with duplicate membernames?
A) Rename newer registered one by adding 1
B) Rename newer one to his email address
C) Delete the newer one
D) Random Action :P"

gamesmad

#18
Probably a good idea actually.  I figure I may as well give this out now.  Just to make it absolutely clear, this is not a finished script, and Im only posting it for you guys to pick holes in/modify.  If you modify it I would appreciate it if you post your new code here so we can all use it.

<?php

// Include the settings files
require "Settings.php";
require 
"mergesettings.php";

// Connect to the main forum database
mysql_connect($db_server,$db_user,$db_passwd);
@
mysql_select_db($db_name) or die( "Unable to select main SMF forum database, make sure this script is in your SMF root directory");

echo 
"<b>OK, first we need to get some information about the main forum, so that we dont duplicate IDs when we add in the other forums database.</b> <br>";

// Heres the highest_id function, which finds the highest ID in a database, and informs the user,
// but more importantly, returns the number for use in our script.
function highest_id ($idname,$dbname,$name)
{
require 
"Settings.php";
$query="SELECT MAX(`ID_{$idname}`) FROM {$db_prefix}{$dbname}";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
        {
        while( list (
$key$value) = each($row) )
                {
                echo 
"Number of $name : $value <br>";
        
$number "number";
        
$temp "$dbname$number";
            $
$temp $value;
        return $
$temp;
                }
        }
}

// Find the highest attachment ID
$attachmentsnumber highest_id ("ATTACH","attachments","attachments");

// Find the highest ban group ID
$bangroupsnumber highest_id ("BAN_GROUP","ban_groups","ban groups");

// Find the highest ban item ID
$banitemsnumber highest_id ("BAN","ban_items","ban items");

echo 
"No info about the board permissions table needed <br>";

// Find the highest board ID
$boardsnumber highest_id ("BOARD","boards","boards");

// Find the highest calendar event ID
$calendarnumber highest_id ("EVENT","calendar","calendar events");

echo 
"Calendar holidays not merged, ask me if you really need them <br>";

// Find the highest category ID
$categoriesnumber highest_id ("CAT","categories","categories");

echo 
"Collapsed categories not merged, ask me if you really need them <br>";

echo 
"None of the logs need merging, ask me if you really need them <br>";

// Find the highest membergroup ID
$membergroupsnumber highest_id ("GROUP","membergroups","membergroups");

// Find the highest member ID
$membersnumber highest_id ("MEMBER","members","members");

// Find the highest message icon ID
$messageiconsnumber highest_id ("ICON","message_icons","message icons");

// Find the highest message ID
$messagesnumber highest_id ("MSG","messages","messages");

echo 
"No info about moderators table needed <br>";

// Find the highest package server ID
$packageserversnumber highest_id ("SERVER","package_servers","package servers");

echo 
"No info about permissions table needed <br>";

// Find the highest PM ID
$personalmessagesnumber highest_id ("PM","personal_messages","PMs");

echo 
"No info about the PM recipients table needed <br>";

echo 
"No info about the poll choices table needed <br>";

// Find the highest poll ID
$pollsnumber highest_id ("POLL","polls","polls");

echo 
"Sessions not merged, ask me if you really need them <br>";

echo 
"Settings not merged, ask me if you really need them <br>";

// Find the highest smiley ID
$smileysnumber highest_id ("SMILEY","smileys","smileys");

echo 
"Themes arent imported, just install them on the main forum <br>";

// Find the highest topic ID
$topicsnumber highest_id ("TOPIC","topics","topics");

// Disconnect from the main forum database
mysql_close();

echo 
"<b>Now we have all the IDs, we can get down to business.</b> <br>";

// Connect to the database we are going to import
mysql_connect($import_server,$import_user,$import_passwd);
@
mysql_select_db($import_name) or die( "Unable to select SMF forum database to import, make sure you have set them in \"mergesettings.php\"");

// Adjust the attachment IDs so they dont conflict with the main database, and stick them in an array
$attachmentarray = array();

$query="SELECT ID_ATTACH FROM {$import_prefix}attachments";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$attachmentarray[] = $value $attachmentsnumber;
    echo 
"Attachment $value adjusted to avoid conflict <br>";
}
}

// Adjust the ban groups IDs so they dont conflict with the main database, and stick them in an array
$bangroupsarray = array();

$query="SELECT ID_BAN_GROUP FROM {$import_prefix}ban_groups";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$bangroupsarray[] = $value $bangroupsnumber;
    echo 
"Ban group $value adjusted to avoid conflict <br>";
}
}

// Adjust the ban items IDs so they dont conflict with the main database, and stick them in an array
$banitemsarray = array();

$query="SELECT ID_BAN FROM {$import_prefix}ban_items";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$banitemsarray[] = $value $banitemsnumber;
    echo 
"Ban item $value adjusted to avoid conflict <br>";
}
}

// Adjust the board permissions IDs so they dont conflict with the main database, and stick them in an array
$boardpermissionsarray = array();

$query="SELECT ID_GROUP FROM {$import_prefix}board_permissions";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$boardpermissionsarray[] = $value $membergroupsnumber 2;
    echo 
"Board permission $value adjusted to avoid conflict <br>";
}
}

// Adjust the board IDs so they dont conflict with the main database, and stick them in an array
$boardsarray = array();

$query="SELECT ID_BOARD FROM {$import_prefix}boards";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$boardsarray[] = $value $boardsnumber;
    echo 
"Board $value adjusted to avoid conflict <br>";
}
}

// Adjust the calendar item IDs so they dont conflict with the main database, and stick them in an array
$calendararray = array();

$query="SELECT ID_EVENT FROM {$import_prefix}calendar";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$calendararray[] = $value $calendarnumber;
    echo 
"Calendar entry $value adjusted to avoid conflict <br>";
}
}

// Adjust the category IDs so they dont conflict with the main database, and stick them in an array
$categoriesarray = array();

$query="SELECT ID_CAT FROM {$import_prefix}categories";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$categoriesarray[] = $value $categoriesnumber;
    echo 
"Category $value adjusted to avoid conflict <br>";
}
}

// Adjust the membergroup IDs so they dont conflict with the main database, and stick them in an array
$membergroupsarray = array();

$query="SELECT ID_GROUP FROM {$import_prefix}membergroups";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$membergroupsarray[] = $value $membergroupsnumber;
    echo 
"Membergroup $value adjusted to avoid conflict <br>";
}
}

// Adjust the member IDs so they dont conflict with the main database, and stick them in an array
$membersarray = array();

$query="SELECT ID_MEMBER FROM {$import_prefix}members";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$membersarray[] = $value $membersnumber;
    echo 
"Member $value adjusted to avoid conflict <br>";
}
}

// Adjust the message icon IDs so they dont conflict with the main database, and stick them in an array
$messageiconsarray = array();

$query="SELECT ID_ICON FROM {$import_prefix}message_icons";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$messageiconsarray[] = $value $messageiconsnumber;
    echo 
"Message icon $value adjusted to avoid conflict <br>";
}
}

// Adjust the message IDs so they dont conflict with the main database, and stick them in an array
$messagesarray = array();

$query="SELECT ID_MSG FROM {$import_prefix}messages";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$messagesarray[] = $value $messagesnumber;
    echo 
"Message $value adjusted to avoid conflict <br>";
}
}

// Adjust the package server IDs so they dont conflict with the main database, and stick them in an array
$packageserversarray = array();

$query="SELECT ID_SERVER FROM {$import_prefix}package_servers";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$packageserversarray[] = $value $packageserversnumber;
    echo 
"Package server $value adjusted to avoid conflict <br>";
}
}

// Adjust the permission IDs so they dont conflict with the main database, and stick them in an array
$permissionsarray = array();

$query="SELECT ID_GROUP FROM {$import_prefix}permissions";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$permissionsarray[] = $value $membergroupsnumber 2;
    echo 
"Permission $value adjusted to avoid conflict <br>";
}
}

// Adjust the PM IDs so they dont conflict with the main database, and stick them in an array
$personalmessagesarray = array();

$query="SELECT ID_PM FROM {$import_prefix}personal_messages";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$personalmessagesarray[] = $value $personalmessagesnumber;
    echo 
"PM $value adjusted to avoid conflict <br>";
}
}

// Adjust the PM recipient IDs so they dont conflict with the main database, and stick them in an array
$pmrecipientarray = array();

$query="SELECT ID_PM FROM {$import_prefix}pm_recipients";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$pmrecipientarray[] = $value $personalmessagesnumber;
    echo 
"PM recipient $value adjusted to avoid conflict <br>";
}
}

// Adjust the poll choice IDs so they dont conflict with the main database, and stick them in an array
$pollchoicesarray = array();

$query="SELECT ID_POLL FROM {$import_prefix}poll_choices";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$pollchoicesarray[] = $value $pollsnumber;
    echo 
"Poll choice $value adjusted to avoid conflict <br>";
}
}

// Adjust the poll IDs so they dont conflict with the main database, and stick them in an array
$pollsarray = array();

$query="SELECT ID_POLL FROM {$import_prefix}polls";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$pollsarray[] = $value $pollsnumber;
    echo 
"Poll $value adjusted to avoid conflict <br>";
}
}

// Adjust the smiley IDs so they dont conflict with the main database, and stick them in an array
$smileysarray = array();

$query="SELECT ID_SMILEY FROM {$import_prefix}smileys";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$smileysarray[] = $value $smileysnumber;
    echo 
"Smiley $value adjusted to avoid conflict <br>";
}
}

// Adjust the topic IDs so they dont conflict with the main database, and stick them in an array
$topicsarray = array();

$query="SELECT ID_TOPIC FROM {$import_prefix}topics";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
{
while( list (
$key$value) = each($row) )
{
    
$topicsarray[] = $value $topicsnumber;
    echo 
"Topic $value adjusted to avoid conflict <br>";
}
}

// Disconnect from the import forum database
mysql_close();

echo 
"<b>We're nearly there, all we have to do is save the rows (now with shiny new IDs) into the database</b> <br>";

// Connect to the main forum database again, if we cant connect now, the server must have exploded
mysql_connect($db_server,$db_user,$db_passwd);
@
mysql_select_db($db_name) or die( "Unable to select main SMF forum database, your server must have exploded");

// OK, lets have some fun writing masses of new rows to the database ;)

function insertrows ($dbname,
{
require 
"Settings.php";
$query="INSERT INTO {$db_prefix}{$dbname}";

$result=mysql_query($query) or
        die( 
mysql_error() );

while (
$row mysql_fetch_array($resultMYSQL_ASSOC))
    {
    while( list (
$key$value) = each($row) )
        {
        
$topicsarray[] = $value $topicsnumber;
        echo 
"Topic $value adjusted to avoid conflict <br>";
        }
    }
}
?>


And the mergesettings file -

<?php

// The following settings are for the database you want to import
// You can use a remote server for the database, but it will be slower
$import_server "127.0.0.1";
$import_user "root";
$import_passwd "";
$import_name "rc3";
$import_prefix "forum2_";

?>


If you dont like a part of my code, correct it, dont flame me, as I have put a fair bit of time into this.

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Gary

Quote from: HarzeM on August 28, 2006, 09:46:52 AM
What about an option to ask the merger person?

"What would you like to do with duplicate membernames?
A) Rename newer registered one by adding 1
B) Rename newer one to his email address
C) Delete the newer one
D) Random Action :P"

Aside from point D, thats a good idea. ;)

-AwwLilMaggie
Gary M. Gadsdon
Do NOT PM me unless I say so
War of the Simpsons
Bongo Comics Fan Forum
Youtube Let's Plays

^ YT is changing monetisation policy, help reach 1000 sub threshold.

gamesmad

Quote from: AwwLilMaggie on August 28, 2006, 09:56:24 AMthats a good idea. ;)

OK, thats decided then, I will include a dropdown box on the setup page.

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Rudolf

When mergin two databases the very first thing you have to decide is which will be the master and which one is the slave.
Then set up the rules based on this.
Obviously database merging should result in a third database, without changing the originals.

You should work systematically, by looking at every table and decide what to do with them and how your actions affect other tables.
The user issue is an interesting one. There are many possibilities. It could happen that the same name is used by two different person, or that the same person is registered on both forums with two different names AND emails. In this case, the best thing to do is to create a second user and notify about the change.
Successively, the user can tell you what's the picture. If it's the same user, as a forum administrator you will merge the two users (on the newly created forum).
The bad thing is that for this you'll have to write a "merge user" mod for SMF. :P

---
Two things about your code:
1. It can be made much more compact thus easier to manage. (ie. the highest_id's)
2. It's not quite clear the logic behind the code. What are you doing? What tables are converted (as of now)?

But I didn't have enough time to look at it, right now.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Rudolf

#22
Quote from: HarzeM on August 28, 2006, 09:46:52 AM

What about an option to ask the merger person?

"What would you like to do with duplicate membernames?
A) Rename newer registered one by adding 1
B) Rename newer one to his email address
C) Delete the newer one
D) Random Action :P"

Please don't use the B option. Users might have set to hide their emails on the forums, if you set it as their username you will be revealing it. That's not fair towards the users.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

gamesmad

Thanks for your comments Rudolf.  I was actually thinking of it more as a way to import another database into the current forum.  You put the merge script in your main forum, and setup the details in mergesettings.php to the database you want to import.  With the script how it is now, nothing gets changed at all, it just sets up all the new IDs into arrays ready to be written into the database.

About making the code more compact, I would greatly appreciate it if you have the time to go over it and improve it however you can.

VERY good thinking about not using option B, I would certainly have overlooked that.

Thanks,

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Harzem

#24
Quote from: Rudolf on August 28, 2006, 10:06:51 AM
Quote from: HarzeM on August 28, 2006, 09:46:52 AM

What about an option to ask the merger person?

"What would you like to do with duplicate membernames?
A) Rename newer registered one by adding 1
B) Rename newer one to his email address
C) Delete the newer one
D) Random Action :P"

Please don't use the B option. Users might have set to hide their emails on the forums, if you set it as their username you will be revealing it. That's not fair towards the users.

Actually that's wrong. Because we are changing their login names, not display names ;) Login names are always hidden.

@gamesmad, I suggest to use slightly different variable names:

$import_dbserver = "127.0.0.1";
$import_dbuser = "root";
$import_dbpasswd = "";
$import_dbname = "rc3";
$import_dbprefix = "forum2_";

So any merger won't think import_name is the forum name, instead of database name.

Rudolf

I am at work now, so I have all the time >:D
jk

I will look into it, because I had some thoughts about a merging script myself. I also had a debate about a general mergin script. A script that would merge two identical databases of any structure - it's impossible without human intervention.
But I digress. The case of SMF is much more simple, because we know the structure and we just need to make some decisions to make - that's our part. The rest (the hard work) will be done by the script ;) That's the beauty in programming.

I was also thinking about a "merge users" mod for SMF, for separate reasons, but I'm sure it would prove useful for people who like to merge forums.
I'll look at the code more closely when I get home.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

gamesmad

HarZem scores yet another good point ;)  So I can use option B :P

I will make a merge users thing once I have made the entire merge script.  Hopefully it will be possible very easily, because using the three functions I have made (only 1 so far), you can extract, adjust, and save any IDs you need to.

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Rudolf

Quote from: HarzeM on August 28, 2006, 10:33:32 AM
Actually that's wrong. Because we are changing their login names, not display names ;) Login names are always hidden.

Actually, this is wrong.
When you register your display name = login name. Conclusion: Login names are not always hidden.
Maybe, what you mean is that you would change only the login name leaving the display name (realName) as it is? In this case the two users would appear the same on the new forum, for people who can't see the emails or the real usernames.
You would need to change the second display name too. And we're back to the step one: changing names. So why not simply give the choise to rename(adding '1' or '_copy') or delete existing users. The deleted users would become like guests.
It can't get easier then that, and it's comprehensive for low-end users too.

This brings up the question: what if the usernames are different but the display names are the same? In this case you would reset the display name for users in the "slave" database. For things like this you need to decide which database will rule.

Hehe, I canceled that point. But he still contributed in bringing out the issue.
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

gamesmad

The main database (the one you are importing TO) will "rule".  As you say, if display names are the same but real names are different, both display names will be reset and the first one to sign in and change it back gets the name ;)

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Rudolf

Quote from: gamesmad on August 28, 2006, 10:49:28 AM
The main database (the one you are importing TO) will "rule".  As you say, if display names are the same but real names are different, both display names will be reset and the first one to sign in and change it back gets the name ;)

Will

That's the coolest thing!
I will update all my mods in the next few weeks. Thanks for your patience.

SVG-Collapse (you need an SVG compliant browser)

Leipe Po

why dont you tel the id part over to mysql?.... this is asking for errors....
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

gamesmad

Yeah, Ill probably rewrite it like that, it would be simple code anyway.

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

Leipe Po

yeah just blank out the id part...
There is only one thing more importend to me then coding:
My Girlfriend

Microsoft - "You've got questions.  We've got dancing paperclips."

gamesmad

That would be pretty much the only option for adjusting that part actually.

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

higherauthority

Oh man this would totally help me out big time!!!

let me know when its complete

gamesmad

Will do, Ill keep the code in the OP up to date, and Ill rename the topic when its done.

Will
1 on 1 SMF Help - Want 1 on 1 SMF Help? Post in Help Wanted or drop me a message!

Go Charter! - Please consider becoming a charter member to support SMF development.

Please do not PM me with general questions, posting in the appropriate board will ensure everyone benefits from the advice given.

JavaJones

I would be willing to kill and/or pay for this. Eagerly hoping to hear a status update! Thanks.  :D

- Oshyan

merm

I just talked with Gamesmad. He says that there hasn't been much progress on the script lately because he's been too busy.

Hopefully we'll find an option for this soon!

JavaJones

Well, as I said I'd be willing to pay a little for this. If anyone else would contribute even a little bit, maybe we can get a pool going. I think it would really increase SMF's usefulness to a lot of people.

- Oshyan

lordmenace


JavaJones

Have been PM'ing with some people involved. It's "in progress" but no timeline. :(

I've got $100 on this script. Anyone else in? We can setup a contribution pool/bounty, any amount will help! Although they've said money won't make it go faster. :P

- Oshyan

Resourcez

hmm, I took a script that Oldiesmann provided,  fixed the code and added attachments and a couple of missed bits - successfully merged 2 SMF forums.

However, it was done on 2 forums with the same user database, so the merging of members and PMs is untested.
If you have everything under control, you're not moving fast enough.
Bugs HereSupport HereDonationsProPackage Parser
TP 1.1 • SMF 1.1.21/2.0.9 • MySQL 5.6.23 PHP 5.4.42 Apache 2.4.12
(PMs not responded to - I provide a support site)

JavaJones

Hmm, that's highly intriguing. Is there an easy way to maintain posts and poster name without having them associated with an actual user? If so I'd be willing to discard the user database of one of my forums as long as I could keep all posts.

- Oshyan

Resourcez

#43
This was done 3 months ago - to date, we haven't seen any irregularities in the merged forum.  We also had to convert 2 different types of DragonflyCMS forums before we merged (and converted a DragonflyCMS coppermine database), so we had some challenges.

In theory it should work just as well with merging the user databases - I just haven't tested it because I had no need for it.  Just duplicate your site and a database and test to be sure.

I fixed the code issues and left the extra member and PM stuff commented out.
btw, when I say "fixed", that's no reflection on Oldiesmann - quite obviously he just threw some untested code together on the fly, and made it clear it was untested :)

Download Here - code restored for full conversion.

If it does the job, please donate to Oldiesmann - whilst I modified the original considerably, I wouldn't have known where to start without his original.
If you have everything under control, you're not moving fast enough.
Bugs HereSupport HereDonationsProPackage Parser
TP 1.1 • SMF 1.1.21/2.0.9 • MySQL 5.6.23 PHP 5.4.42 Apache 2.4.12
(PMs not responded to - I provide a support site)

JavaJones

Any update on this? I still have a great need for this, with integrated users preferably. Still have money on it, too. My timeline is more flexible now, but I'd like to do the project that depends on this within the next few months for sure.

Thanks!

- Oshyan

MuddHarryS

Has anyone used Resourcez script?

lordmenace

Quote from: MuddHarryS on January 30, 2007, 09:23:59 PM
Has anyone used Resourcez script?

I'd like to know this as well.

Gary

I did try it, but I tried it on 1.1.1 which was a no go, since the thing is for RC3.

-AwwLilMaggie
Gary M. Gadsdon
Do NOT PM me unless I say so
War of the Simpsons
Bongo Comics Fan Forum
Youtube Let's Plays

^ YT is changing monetisation policy, help reach 1000 sub threshold.

Advertisement: