Advertisement:

Author Topic: mergeSMF.php - Script to merge two SMF forums  (Read 37547 times)

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,761
  • Gender: Male
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #20 on: April 02, 2014, 06:28:26 AM »
Quote
What happens to Forum2? Does it stay in place same as before you ran the script?
I assume yes. Usually the source has data only read from.

Quote
If this is the case, is there any way to merge them into one forum but in a totally different location/database, so that the original Forum1 and Forum2 stay as they are? At least temporarily.
Create a copy of forum 1 (target forum), duplicate database, duplicate files and run repair_settings in it. So you should have now 3 forums. The third forum will be your temporary merged forum and both other forums are untouched.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

Quote
Over 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #21 on: April 02, 2014, 06:57:50 AM »
That's a great idea, thanks. So I could experiment on merging Forum2 with Forum3(copy of 1) without affecting the live version of Forum1. And if it works as planned, I can then delete Forum1 and move Forum3 over (or run the script again using Forum1).

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,761
  • Gender: Male
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #22 on: April 02, 2014, 07:07:01 AM »
Yup.

You should be careful, though, this is usually a very server-intensive operation. If you have a lot of users online, it is possible that some inconsistencies occur (eg: a user creates a post after the copy operation for members but before copy of posts). It is always advisable to choose a "dead period" of your forum, take it out for some minutes while the tool runs (maintenance mode = 2 in Settings.php) and take it out of maintenance mode after.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

Quote
Over 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Offline bfeist

  • Semi-Newbie
  • *
  • Posts: 30
  • Gender: Male
  • Admin of temac.ca/smf
    • http://www.linkedin.com/in/feist on LinkedIn
    • @benfeist on Twitter
    • Articles and Interests
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #23 on: April 02, 2014, 11:36:06 AM »
I highly recommend that you do this in a sandbox environment, perhaps even locally in a development environment.

Also, the way the script is written, both forums data has to be house in the same database with a different table prefix. So if your larger Forum1 starts with smf_, export it from your live database and import it to your sandbox environment. You then need to export Forum2's datadatabase to SQL, modify the table names to start with smf2_ for example, then import those tables into the same sandbox database. This will result in a database that contains two sets of SMF forum tables, one starting with smf_, the other with smf2_

Hope this helps.

Ben

Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #24 on: April 05, 2014, 05:42:09 PM »
When you say you have to merge the smaller one with the bigger one, is that by amount of posts or amount of topics? My "smaller" one has more total posts, but they're in less topics.

Offline bfeist

  • Semi-Newbie
  • *
  • Posts: 30
  • Gender: Male
  • Admin of temac.ca/smf
    • http://www.linkedin.com/in/feist on LinkedIn
    • @benfeist on Twitter
    • Articles and Interests
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #25 on: April 06, 2014, 12:29:07 AM »
Hmmm, I'll have to take a close look at the code to answer you. I'll have a look in the morning.

Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #26 on: April 06, 2014, 01:54:36 PM »
Hmmm, I'll have to take a close look at the code to answer you. I'll have a look in the morning.

Hope you can find the answer :)

I just tried merging the smaller forum (more posts, less topics) with the larger one (less posts, more topics). The process seemed to work. I checked the tables for the newly merged larger board and I can see threads which only used to exist on the smaller board. But when I go to the larger board (after recounting the totals) none of the topics or boards are there. The categories moved over, but no boards or topics. I wonder if this means more posts = larger forum, so I actually did them the wrong way around? Could that be why the boards/topics are in the database but not visible?

I'll try and go back to the start and merge them in the opposite direction, see what happens

Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #27 on: April 06, 2014, 02:23:10 PM »
haha, so I tried the opposite way around ("larger" forum with more posts less topics, "smaller" forum with less posts more topics). All of the posts did indeed move from the smaller one to the larger one... problem is none of the boards did, and all of the posts have attached themselves to random topics all over the place. Also, all of the posts are attributed to the right username but none of those usernames are attached to accounts, so they all look like guests posts.

It's a great idea for a script, but I'm not sure it works in a live forum environment :)

Offline bfeist

  • Semi-Newbie
  • *
  • Posts: 30
  • Gender: Male
  • Admin of temac.ca/smf
    • http://www.linkedin.com/in/feist on LinkedIn
    • @benfeist on Twitter
    • Articles and Interests
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #28 on: April 06, 2014, 05:29:00 PM »
The problem is that the original script does things in kind of a "lazy way" in that all it's really doing is looking for the maxvalue of the posts table on the larger forum, then adding that amount to the postIDs of the smaller forum and merging them in with all of the supporting stuff (like boards, users etc). This results in things like sorting being out of order without further mods.

The right way to do a merge script would be to do an actual line-by-line merge of every table, threading the values together by date. There would be no concept of "smaller" or "larger" forum, instead an actual splicing of all tables in each forum would occur, new postIDs, topicIDs, userIDs, etc would be generated for both forums. Coding-wise this is a complete rewrite.

Since I wrote this script for myself, I haven't seen many other people using it. Someone above mentioned that merging forums is a common request. If there's enough demand for it maybe I'll take a stab at the rewrite. But so far in the 8 months since I've written this version, only one or two people have given it a shot. Thoughts?


Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #29 on: April 07, 2014, 03:09:40 AM »
I don't have an answer for that. I'd guess that maybe there aren't many people that run two similar enough forums who'd want to merge them. Maybe there ARE a lot of people who'd like the ability to merge but are worried about all their data being corrupted. Who knows.

I'd happily donate a little money if it helped you do a complete re-write and make this awesome, but I dunno if I could give enough to make it worth your while.

Offline trot12345

  • Newbie
  • *
  • Posts: 3
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #30 on: April 09, 2014, 03:47:38 AM »
My partner and i discovered the idea out and it worked well like a dream! Thanks a lot a great deal!! the one dilemma can be that the mod to help mix users was taken out

Offline bfeist

  • Semi-Newbie
  • *
  • Posts: 30
  • Gender: Male
  • Admin of temac.ca/smf
    • http://www.linkedin.com/in/feist on LinkedIn
    • @benfeist on Twitter
    • Articles and Interests
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #31 on: April 09, 2014, 06:50:20 AM »
Great to hear you had success. Here's the mod to merge users:
https://github.com/Spuds/SMF-Admin-Toolbox


Offline Dzonny

  • Localizer
  • SMF Super Hero
  • *
  • Posts: 11,912
  • Gender: Male
  • No sleep...
    • dzontra.nikola on Facebook
    • Dzonny on GitHub
    • dzontranikola on LinkedIn
    • @opusteniforum on Twitter
    • Samo opusteno
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #32 on: April 09, 2014, 09:41:15 AM »
Just mentioning, you can always make a backup of forum files and database before merging and then restore it wherever you want, so you have working copy of forum before merging.

Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #33 on: April 09, 2014, 10:44:47 AM »
I did all my testing on duplicate copies of the forum directories/databases so I didn't harm the originals. Then I could just drop all the tables and re-import the databases each time and try again.

Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #34 on: April 09, 2014, 10:45:59 AM »
By the way, do you HAVE to use SMF 2.0.6+ for this to work? I just realised we're still on 2.0.4. Though I don't see why that would cause problems for something like this. Am I wrong?

(Yes, I know I should update soon)

Offline margarett

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,761
  • Gender: Male
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #35 on: April 09, 2014, 11:57:52 AM »
You should be on 2.0.6 because of security fixes introduced meanwhile.

Other than that, it has to work fine, there were no database changes since 2.0 RC-something ;)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

Quote
Over 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Offline JTVaughn

  • Jr. Member
  • **
  • Posts: 177
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #36 on: April 18, 2014, 01:30:52 PM »
Is it possible to only merge the boards/topics/posts and nothing else? i.e. no users/attachments etc? 99% of my users are the same on both

And a question about the script: how does it work with assigning posts to users? Does it just say "post was made by member ID #3 on one board, so merge it over and assign to member ID #3 on the other board"? Is that why the posts were all funky and attributed to the wrong people when I tried it?

Offline bfeist

  • Semi-Newbie
  • *
  • Posts: 30
  • Gender: Male
  • Admin of temac.ca/smf
    • http://www.linkedin.com/in/feist on LinkedIn
    • @benfeist on Twitter
    • Articles and Interests
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #37 on: April 18, 2014, 08:24:23 PM »
Is it possible to only merge the boards/topics/posts and nothing else? i.e. no users/attachments etc? 99% of my users are the same on both

And a question about the script: how does it work with assigning posts to users? Does it just say "post was made by member ID #3 on one board, so merge it over and assign to member ID #3 on the other board"? Is that why the posts were all funky and attributed to the wrong people when I tried it?

You can comment out different sections of the script if you only want to merge certain tables.

There's a good chance you have different memberIDs on your different boards. It's easiest to do it the way the script already does it:
- All duplicate users from secondary board are renamed as <username>_todelete during the merge.
- You then use a separate tool to merge users, thus removing the _todelete users: https://github.com/Spuds/SMF-Admin-Toolbox

Offline ExSpirit

  • Jr. Member
  • **
  • Posts: 190
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #38 on: June 17, 2014, 06:52:06 AM »
There's a problem because of ID_TOPIC - those numbers are not changed, so messages are messed up - assigned to wrong topic at the end...

Offline bfeist

  • Semi-Newbie
  • *
  • Posts: 30
  • Gender: Male
  • Admin of temac.ca/smf
    • http://www.linkedin.com/in/feist on LinkedIn
    • @benfeist on Twitter
    • Articles and Interests
Re: mergeSMF.php - Script to merge two SMF forums
« Reply #39 on: June 17, 2014, 10:45:26 AM »
There's a problem because of ID_TOPIC - those numbers are not changed, so messages are messed up - assigned to wrong topic at the end...

This happens in step 8. The approach is to find the highest topic ID of the larger board, and add that number to all topics in the smaller board before merge. It's possible you have your boards mixed up and are trying to merge the larger into the smaller by accident.