I am running a drupal multi-site system, with shared code and seperated DB. Each individual multi-site represents one continent and can have different language versions.
What i want: I am working on a module, that gathers all available languages on all multi-sites into one big continent/language map.
To query cross-multi-site data i use db_set_active([multisite])
and manually fetch some data via db_query()
.
foreach ($multisites as $multisite) {
db_set_active($multisite['db']); //switch context
$links = db_query(Select language from {languages} etc...)) // run query
do_somthing_with_data($links) //work with data
db_set_active(); //switch to default
}
This works pretty fine,
but there are already drupal-core functions in language.inc
i want to use (e.g. language_negotiation_get_switch_links()
).
foreach ($multisites as $multisite) {
db_set_active($multisite['db']); //switch context
$links = language_negotiation_get_switch_links(...,...) // run core-function
db_set_active(); //switch to default
}
Here is my problem:
Several core functions use variable_set()
and variable_get()
. They are persistent and initialized on bootstrap.
When changing the active database with db_set_active()
, incoming queries have the new context, but values fetched with variable_get()
are inconsistent, because they store data from default database, filled on bootstrap.
In a nutshell:
I want to run core-functions on one multi-site with data from another multi-site. db_set_active()
works fine, but data is inconsistent because variable_get()
uses data, which is initialized on bootstrap.
Has anyone ever worked with this issue?
Kind regards larry
Addition:
As I got deeper into development it became more and more complicated. I don't recommend the procedure of cross-multi-site-core-function-calling, because the initialization of core-functionality is triggered during bootstrap.
Here an example:
The multi-site you are browsing to does not need to initialize language.inc, because it has just one language-version. Further in code-progress you switch context to a multi-site with two or more languages but language.inc functionality is not available, because it was not initialized.