Skip to content
Snippets Groups Projects
Commit 0231e8c8 authored by ale's avatar ale
Browse files

Update code for new $r2db_hash_map global

parent 66c0a7a6
No related branches found
No related tags found
1 merge request!1Update code for new $r2db_hash_map global
Pipeline #12521 passed
......@@ -134,7 +134,11 @@ function backend_to_http_endpoint($backend) {
// Print the blog -> backend map.
function generate_map() {
global $wpdb;
$wpdb_hash = &$wpdb->hash_map;
global $r2db_hash_map;
$wpdb_hash = $r2db_hash_map;
if (!$wpdb_hash) {
$wpdb_hash = &$wpdb->hash_map;
}
$blogs = get_blogs();
......
......@@ -28,6 +28,13 @@ function noblogs_get_blog($blogname) {
// Return the database connection information associated with a blog.
function noblogs_get_backend_for_blog($blog_id) {
global $wpdb;
global $r2db_hash_map;
// Compatibility shim between old/new r2db.
$hash_map = $r2db_hash_map;
if (!$hash_map) {
$hash_map = $wpdb->hash_map;
}
// Create a temporary hash object just to load the backends
// (we cannot use the map in $wpdb because it doesn't have the
......@@ -37,7 +44,7 @@ function noblogs_get_backend_for_blog($blog_id) {
// Lookup the blog ID using the $wpdb hash just to be safe (though
// we should get an identical result using $hashmap).
$lookup = $wpdb->hash_map->lookup($blog_id);
$lookup = $hash_map->lookup($blog_id);
$backend = $reversemap[$lookup];
// Be nice and split the database host into 'host' and 'port' elements.
......@@ -57,14 +64,20 @@ function noblogs_get_backend_for_blog($blog_id) {
// Return the full backend -> blogs map.
function noblogs_get_backend_map() {
global $wpdb;
$wpdb_hash = &$wpdb->hash_map;
global $r2db_hash_map;
// Compatibility shim between old/new r2db.
$hash_map = $r2db_hash_map;
if (!$hash_map) {
$hash_map = $wpdb->hash_map;
}
$blogs = noblogs_get_blogs();
$backend_map = array();
foreach ($blogs as $blog) {
$blog_id = $blog->blog_id;
$backend_id = $wpdb_hash->lookup($blog_id);
$backend_id = $hash_map->lookup($blog_id);
if (!array_key_exists($backend_id, $backend_map)) {
$backend_map[$backend_id] = array();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment