Thread: Major Additions - Share users database among many forums
View Single Post
  #83  
Old 12-19-2008, 03:12 AM
goncalo goncalo is offline
 
Join Date: Mar 2007
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by SirAdrian View Post
Another (similar) solution is to use MySQL 5's views.

(Example: db2.user is a view of db1.user)
Thank you very much SirAdrian, and congratulations, your solution is great, it took me a couple of hours to make it work.

Congratulations also of course to Mangel.ajo and all you guys that try to improve VBulletin and help each others.

Your solution was good also but I prefered the VIEW one suggested by SirAdrian. Why?

The View option is great, in spite of being also a php programmer, I didn't know that MySQL already had it, it's really great, it's like a way to make a symbolic link to another table.

I don't like changing my code, specially because one day I'ld need to reinstall it again and would forget to make all the updates, with the View option it's very easy, and I noticed it's an option that you are ignoring although it's a great one.

I didn't change any code and have now 2 forums working as one.

What have I done?

- First search all users on my forum b to check if they existed on forum A or not, and if so, correct the situation.
- When I had all users different somehow (small forums I had only to change 5 users that didn't post for over 1 year), I ran a small php script to add all those users one by one on the new forum updating user, usertextfield, userfield fields, the ones that are created with each new user.
- Then I ran a script to find to which userid on the new forum each user on the old forum had.
- Now, changed the user and userfield and usertextfield tables to something like "old_user", and creating a new VIEW for each of those 3 tables pointing them to the same tables on the new forum.

From that moment one, it was done. All users signing up would be added to the new forum user table, and each user signing up on the new forum would be able to login to the old forum as well (signing on forum A and logging to B), because they all shared the same database.

This without changing any code.

But now there are stuff que needs to be done, you have lots of tables there that needed to be changed here also. For each table that we want to be used on the new forum (forum A) you need to rename the table do "old_" and creating a view to the new forum database, so that all those tables are ran on the new forum. I've did this for over 20 tables, like smilies, user reputations, usergroup, many tables that I wanted to be using the new forum.

Even the pm table are duplicated now, the 2 forums with separated private messages, but I'll do the same to those, so that all pm's go to the same database.

Having this done, only one thing was left, obviously, the usernames were all mixed up on the old forum, where their usernames changed so the posts appear with the wrong author.

So as we already had the table showing each user's old and new id, something like:
$olduseridbpt['572']=1027;//Old user 572 is now 1027;
We just need the script to have an update userid query on each table saying that the old user will be the new one, with a simple script (carefull that if the user 100 changes to 80, and then the 80 changes to 200, two users instead of one will have the same number which is bad).

Then we run this process in all tables that have a record and that user's userid or fromuserid (pmtext), receiptto, from, etc. I've done this in seconds with php scripts, on these tables:
threadpost,threadrate,pollvote,post,posthash,pm,pm receipt,pm,pmtext,moderator,moderatorlog,customava tar,customprofilepic,useractivation,subscribeforum ,subscribethread,administrator,attachmenteditlog,s igparsed,userlist,userlistrelationid.

All the tables that had the old user id's were now updated. Now everything is at 100%.

Took me only a couple of hours to program the scripts to make the users update on the tables, create views, test databases, etc, without changing any of the VBulletin code.

The old forum treats the views as they were on its own database so everything is perfect without changing any code.

If you have 2 new forums, it would take minutes! Just change about 20 tables that you want on forum A instead of B after installing forum B, make their views, without changing any code, and it's working perfectly in minutes, and you can reinstall vbulletin many times without having to update anything. All this with views.

I don't mix the session table with a view because there are forum-specific fields there like "inthread" which tell the users in which thread they are, and also I didn't put as a view the datastore table which shows things like how many users ate in a forum, those need to be separated.

Anyway many thanks for this thread, and to SirArthur also, which saved me a lot of time with a simple tip and I wanted to share this with others, because I hate changing code.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01380 seconds
  • Memory Usage 1,790KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete