From ab2591f8b19c64d8483c15de233183bfe456d35a Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Thu, 16 Jan 2025 13:13:08 +0000
Subject: [PATCH] Allow overriding host for local copy of the global database

Some testing scenarios (e.g. when testing containers using podman
services) require using a different host for the "local" instance.
---
 db-backends.php | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/db-backends.php b/db-backends.php
index ace5b2a..678ca3a 100644
--- a/db-backends.php
+++ b/db-backends.php
@@ -49,9 +49,16 @@ function noblogs_load_global_dataset() {
   global $wpdb;
   global $noblogs_config;
   $master = $noblogs_config['db_config']['master'];
+  // IP adress of the local mysql instance with the 'master' db.
+  // We want to override this in certain testing scenarios, to use
+  // a mysql server not on localhost.
+  $local_master_host = '127.0.0.1';
+  if (isset($master['local_host'])) {
+    $local_master_host = $master['local_host'];
+  }
   if ($noblogs_config['db_config']['is_master']) {
     $wpdb->add_database(array(
-       "host" => "127.0.0.1:" . $master['port'],
+       "host" => $local_master_host . ":" . $master['port'],
        "user" => $master['user'],
        "password" => $master['password'],
        "name" => $master['name'],
@@ -72,7 +79,7 @@ function noblogs_load_global_dataset() {
        "timeout" => 2
     ));
     $wpdb->add_database(array(
-       "host" => "127.0.0.1:" . $master['port'],
+       "host" => $local_master_host . ":" . $master['port'],
        "user" => $master['user'],
        "password" => $master['password'],
        "name" => $master['name'],
-- 
GitLab