With a setup like
$db_prefix = array(
'default' => 'foo_', // this line changes for each slave
'users' => '',
'sessions' => '',
'authmap' => '',
'sequences' => '',
'profile_fields' => '',
'profile_values' => '',
'users_roles' => '',
'role' => '',
);
where two or more sites share the users table, some queries in the graphstat module fail.
The error is a series of:
user warning: Table 'foo.foo_users' doesn't exist query: SELECT COUNT(uid) FROM foo_users WHERE created <= 1146788121 AND uid != 0 in /drupal/includes/database.mysqli.inc on line 121.
The problematic line of code is:
$data[$key][$time] = db_result(db_query("SELECT COUNT(%s) FROM {%s} WHERE %s <= %d AND %s != 0", $id, $key, $key == 'comments' ? 'timestamp' : 'created', $time, $id));
Apparently this query construction isn't possible -- the only way I can make it work is to add %s' => '', to my $db_prefix array in settings.php -- but that doesn't seem like a good thing to do..
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | multisite_fix.patch.txt | 6.34 KB | Tobias Maier |
Comments
Comment #1
mfbfinal line should read:
'%s' => '',Comment #2
Tobias Maier commentedI had the same problem but I found a real patch.
the problem is because of db_query() first of all it prefixes the table.
But the table "%s" is not in $db_prefix[] this means it gets no of the false prefix in front of the table.
This means we have to insert the right table before we hand over the string as argument.
This is what this patch does
As a bonus it uses the t() the right way. (get
<p>out oft())and moves the check for the statistics module to the top. (better for readability)
If i find a little bit time i want to provide more patches which simplify code or adds new features...
so please apply this patch asap.
Comment #3
mfbLooks good and the module works..
Comment #4
Tobias Maier commenteddoes this mean rtbc?
Comment #5
DriesK commentedCommitted. Thanks!
As to your plan to supply more patches: I'm in the process of fully rewriting graphstat module (and it's almost done I think). The module is to become a generic module for rendering graphs. The idea is that graphstat.module itself doesn't do anything but rendering graphs based on data injected by other modules through .inc files. These graphstat includes calculate the actual data to be displayed, and implement a small number of (new) graphstat hooks to have graphstat.module render the graphs.
Comment #6
(not verified) commented