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..

CommentFileSizeAuthor
#2 multisite_fix.patch.txt6.34 KBTobias Maier

Comments

mfb’s picture

final line should read: '%s' => '',

Tobias Maier’s picture

Status: Active » Needs review
StatusFileSize
new6.34 KB

I 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 of t())
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.

mfb’s picture

Looks good and the module works..

Tobias Maier’s picture

Status: Needs review » Reviewed & tested by the community

does this mean rtbc?

DriesK’s picture

Status: Reviewed & tested by the community » Fixed

Committed. 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.

Anonymous’s picture

Status: Fixed » Closed (fixed)