I have a Drupal Site A that shares the users table of Drupal Site B. The Site A settings.php file has the following entry for $db_prefix:

$db_prefix = array(
...
"users" => "pvun.",
"sequences" => 'pvun.'
...
);

There are problems, however, when a new user gets created in Site A. I get a duplicate entry error. After investigating, I saw the following entry in the id column of my sequences table: pvun.users_uid. It's value is set to 1.

I investigated the problem and it stems from the fact that the db_prefix_tables() function, which gets called indirectly by the db_next_id({users}_uid) line in the user.module, does not take into account sites sharing tables.

I think the db_next_id() function needs to be rewritten to hanlde the case of sites sharing tables. A test would need to be run to determine if the prefix ended in a '.' or not.

Comments

Steve Dondley’s picture

StatusFileSize
new2.29 KB

OK, here's a first go at a patch. Most of the changes are made to the db_prefix_tables() function. The overall behavior of that function is determined by a new argument passed to it, $next_id.

If $next_id is set to FALSE
or
it's set to TRUE by the db_next_id() and the last character in the db_prefix is not equal to '.' (signifying that it is not a tabled shared between two databases), the module behaves the same.

However, if it's set to TRUE and the db_prefix does end in '.' (signifying that it is a shared table), the function simply removes the curly braces.

Steve Dondley’s picture

StatusFileSize
new2.31 KB

Use this patch instead. Fixed a bug.

Steve Dondley’s picture

StatusFileSize
new1.24 KB

Here's a much cleaner patch. Thanks to Java_ for bringing some helpful info about this bug and pointing out the obvious to me.

Steve Dondley’s picture

StatusFileSize
new1.81 KB

Let's try this again. Last patch wouldn't work for any site that used table prefixes. I think this patch should do it. Someone should definitely review it, however.

killes@www.drop.org’s picture

Status: Needs review » Active

Steve and I resolved this to be a docs issue. Steve, will you provide better docs?

Steve Dondley’s picture

Status: Active » Closed (fixed)

I already did. Forgot to close this out. See http://drupal.org/node/22268