Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ai
noblogs-wp
Commits
1c8be710
Commit
1c8be710
authored
Mar 06, 2011
by
root
Committed by
agata
Oct 17, 2019
Browse files
a few fixes to the global wpdb_hash instance (moved into $wpdb)
parent
ebcc5c16
Changes
5
Show whitespace changes
Inline
Side-by-side
db-config.php
View file @
1c8be710
<?php
// Common settings
$wpdb
->
save_queries
=
false
;
$wpdb
->
persistent
=
false
;
$wpdb
->
max_connections
=
30
;
define
(
"NOBLOGS_BACKEND_CONFIG"
,
"/etc/noblogs/backends"
);
requir
e_once
(
'r2db/db-hash.php'
);
requir
e_once
(
'r2db/db-backends.php'
);
includ
e_once
(
'r2db/db-hash.php'
);
includ
e_once
(
'r2db/db-backends.php'
);
// Add the global database (configured in wp-config.php), stores the global
// blogs and users tables.
...
...
@@ -16,5 +21,5 @@ $wpdb->add_database(array(
"write"
=>
1
,
"read"
=>
1
,
"timeout"
=>
2
));
$wpdb_reverse_backend_map
=
noblogs_load_backends
(
NOBLOGS_BACKEND_CONFIG
,
$wpdb
_
hash
);
$wpdb_reverse_backend_map
=
noblogs_load_backends
(
NOBLOGS_BACKEND_CONFIG
,
$wpdb
->
hash
_map
);
r2db/db-backends.php
View file @
1c8be710
<?php
function
noblogs_load_backends
(
$db_config_file
,
&
$hashptr
)
{
function
noblogs_load_backends
(
$db_config_file
,
$hashptr
)
{
global
$wpdb
;
$backend_map
=
array
();
...
...
r2db/db-hash.php
View file @
1c8be710
<?php
require_once
(
'
flexihash.php'
);
require_once
(
dirname
(
__FILE__
)
.
'/
flexihash.php'
);
$wpdb
_
hash
=
new
Flexihash
();
$wpdb
->
hash
_map
=
new
Flexihash
();
/* Hashing function to map blogs to databases.
*
* Implements a consistent hashing scheme using Flexihash.
*/
function
noblogs_db_callback
(
$query
,
$wpdb
)
{
global
$wpdb
_
hash
;
$wpdb_hash
=
$wpdb
->
hash
_map
;
if
(
preg_match
(
"/^
{
$wpdb
->
base_prefix
}
(\d+)_/"
,
$wpdb
->
table
,
$matches
))
{
$blog_id
=
$matches
[
1
];
return
$wpdb_hash
->
lookup
(
$blog_id
);
...
...
r2db/tools/db-migrate-to-new-schema.php
View file @
1c8be710
...
...
@@ -5,7 +5,7 @@
define
(
'WP_CACHE'
,
false
);
/** Setup WordPress environment */
require_once
(
'wp-load.php'
);
require_once
(
'db-config
-new
.php'
);
require_once
(
'db-config.php'
);
function
old_hash
(
$dbid
)
{
...
...
@@ -24,11 +24,10 @@ function old_hash($dbid) {
}
}
function
new_hash
(
$dbid
)
{
global
$wpdb_hash
;
global
$wpdb_reverse_backend_map
;
$lookup
=
$wpdb_hash
->
lookup
(
$dbid
);
$backend
=
$wpdb_reverse_backend_map
[
$lookup
];
function
new_hash
(
$dbid
,
$reversemap
)
{
global
$wpdb
;
$lookup
=
$wpdb
->
hash_map
->
lookup
(
$dbid
);
$backend
=
$reversemap
[
$lookup
];
$result
=
array
();
if
(
preg_match
(
'/^(.*):([0-9]*)$/'
,
$backend
[
'host'
],
$matches
))
{
$result
[
'host'
]
=
$matches
[
1
];
...
...
@@ -54,11 +53,15 @@ function get_all_blogs()
{
global
$wpdb
;
$sql
=
"SELECT blog_id, domain, path FROM
$wpdb->blogs
WHERE public = 1 AND deleted = 0 AND archived = '0' ORDER BY domain, path"
;
// $sql = "SELECT blog_id, domain, path FROM $wpdb->blogs WHERE public = 1 AND deleted = 0 AND archived = '0' ORDER BY domain, path";
$sql
=
"SELECT blog_id, domain, path FROM
$wpdb->blogs
WHERE public = 0 ORDER BY domain, path"
;
$result
=
$wpdb
->
get_results
(
$sql
);
return
(
$result
);
}
$hashmap
=
new
Flexihash
();
$reverse_backend_map
=
noblogs_load_backends
(
NOBLOGS_BACKEND_CONFIG
,
$hashmap
);
$new_counts
=
array
();
$moved_count
=
0
;
$blogs
=
get_all_blogs
();
...
...
@@ -67,7 +70,7 @@ foreach ($blogs as $blog) {
$old_params
=
old_hash
(
$blog_id
);
$old_dburi
=
mysqlurl
(
$old_params
);
$new_params
=
new_hash
(
$blog_id
);
$new_params
=
new_hash
(
$blog_id
,
$reverse_backend_map
);
$new_dburi
=
mysqlurl
(
$new_params
);
if
(
$new_counts
[
$new_params
[
'host'
]])
{
...
...
wp-content/db.php
View file @
1c8be710
...
...
@@ -51,6 +51,13 @@ define( 'HYPERDB_CONN_HOST_ERROR', 2003 ); // Can't connect to MySQL server on
define
(
'HYPERDB_SERVER_GONE_ERROR'
,
2006
);
// MySQL server has gone away
class
hyperdb
extends
wpdb
{
/**
* A/I patch!
* store a FlexiHash() instance here.
*/
var
$hash_map
;
/**
* The last table that was queried
* @var string
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment