vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.7 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=228)
-   -   Major Additions - Share users database among many forums (https://vborg.vbsupport.ru/showthread.php?t=185021)

mangel.ajo 07-10-2008 10:00 PM

Share users database among many forums
 
This is a feature requested many times, and we are still waiting, so I released a patch to be able to run many forums with the same user database.

This is an EXPERIMENTAL PATCH I'm running on my forums.

Code:

--- ../../../private/upload/includes/class_core.php    2008-07-10 11:17:32.000000000 +0200
+++ class_core.php      2008-07-11 17:44:20.000000000 +0200
@@ -405,6 +405,33 @@
                $this->connection_recent =& $link;
                $this->querycount++;

+              $shared_tables = Array("user","useractivation","userban","usertitle","userchangelog","usertextfield","userfield","usergroup","userlist","usernote","profilevisitor","reputation","reputationlevel","spamlog","strikes","pm","pmreceipt","pmtext","avatar","profilefield");
+
+              $main_prefix = "FP_";
+              foreach ($shared_tables as $shared_table)
+              {
+                      $orig = TABLE_PREFIX.$shared_table;
+                      $dst  = $main_prefix.$shared_table;
+
+                      $this->sql = str_replace($orig." ",$dst." "  ,$this->sql);
+                      $this->sql = str_replace($orig.".",$dst."."  ,$this->sql);
+                      $this->sql = str_replace($orig."\r",$dst."\r",$this->sql);
+                      $this->sql = str_replace($orig."\n",$dst."\n",$this->sql);
+                      $this->sql = str_replace($orig."\t",$dst."\t",$this->sql);
+
+              }
+

                if ($queryresult = $this->functions[$buffered ? 'query' : 'query_unbuffered']($this->sql, $link))
                {

You can add "session" to $shared_tables if you want to share your sessions among forums under the same domain (Thanks Lionel)

This is only useful for new forums joining anothers one user database.

Requirements:
  • An old forum where all users are.
  • Sharing the same database, using diferent prefixes for tables (TABLE_PREFIX)
For example: Imagine we have FORUM_A , FORUM_B, and FORUM_C each one with their respective licenses.

FORUM A has table prefix FA_ in database, FORUM_B has FB_ and FORUM_C has FC_

FORUM A is the main, and older forum, where we have all our users.

then we would install FORUM_B and FORUM_C normally, using the same database that FORUM_A uses, but setting up their own table prefixes.


once FB_ and FC_ are installed then we go patching class_core.php from FORUM_B and FORUM_C setting up $main_prefix = "FA_"; so they use FORUM_A for shared tables.

Possible problems:
  • memcached issues?, not sure
  • avatar/signature pics/etc issues when storage is set to disk.
  • more to come...


Author: Optimizacion Web

Dark Zero 07-11-2008 03:29 PM

Interesting approach, i keep an eye on it :)

FRANKTHETANK 2 07-11-2008 04:32 PM

yea this might come in handy

Tekmon 07-11-2008 05:41 PM

I implimented a similar one where the seperate forums just shared the user, pm and one or two more tables and it works pretty well. However it does require mass changes to the FB and FC PHP files where yours would not?

If I read your correctly it looks like if the table being queried is in the array it will use the FA table prefix?

lodac 07-11-2008 08:40 PM

I have been looking for something like this. I will follow.

Adrian Schneider 07-11-2008 08:46 PM

Another (similar) solution is to use MySQL 5's views.

(Example: db2.user is a view of db1.user)

mangel.ajo 07-11-2008 08:54 PM

Quote:

Originally Posted by Tekmon (Post 1572959)
I implimented a similar one where the seperate forums just shared the user, pm and one or two more tables and it works pretty well. However it does require mass changes to the FB and FC PHP files where yours would not?

If I read your correctly it looks like if the table being queried is in the array it will use the FA table prefix?

Is good to know that your modifications worked, It makes me feel better :D

And, yes, the result is that when any table in "shared tables" is queried the query ends up rewritten so it goes to the FA_ prefix.

mangel.ajo 07-11-2008 08:55 PM

Quote:

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

(Example: db2.user is a view of db1.user)

Hmmm, if database can gives us that functionality it could be interesting because we wouldn't need to patch at all.

Can you point us to some document about mysql5 views?

How do you setup a view?

Greetings,
Miguel ?ngel.

Lionel 07-11-2008 09:00 PM

add to your array
Quote:

,"strikes","pm","pmreceipt","pmtext","session","av atar","profilefield"
also take a look at this

mangel.ajo 07-11-2008 09:12 PM

Thanks Lionel!!

Anyway, I'm not sure if the table "session" would be safe to be shared among all forums... why? ... because it points to the threadid or URL the user is watching, and that would be different between one forum and another.

Anyway it would be nice because this way the total user activity in the forums would be reflected.


All times are GMT. The time now is 09:56 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01183 seconds
  • Memory Usage 1,744KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete