When installing Domain Access a default site is created. It should have ID 0 because that is what determines it's the default site.

However if your MySQL is configured with auto_increment_offset it will break with the current code.

    db_query("INSERT INTO {domain} (subdomain, sitename, scheme, valid) VALUES ('%s', '%s', '%s', %d)", $root, $site, $scheme, 1);
    // MySQL won't let us insert row 0 into an autoincrement table.
    // Similar to the {users} table, this leaves us with no row 1.
    db_query("UPDATE {domain} SET domain_id = domain_id - 1");

This should not assume the domain_id is 1. A better approach would be to have it force it to 0 instead of decreasing its current value with 1.

Do you agree? Then I can roll a patch for it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agentrickard’s picture

Status: Active » Needs review

This is very similar to how core does it.

Do you not have the same problem with user 0?

See system_install().

  // Inserting uid 0 here confuses MySQL -- the next user might be created as
  // uid 2 which is not what we want. So we insert the first user here, the
  // anonymous user. uid is 1 here for now, but very soon it will be changed
  // to 0.
  db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', '');

  // We need some placeholders here as name and mail are uniques and data is
  // presumed to be a serialized array. Install will change uid 1 immediately
  // anyways. So we insert the superuser here, the uid is 2 here for now, but
  // very soon it will be changed to 1.
  db_query("INSERT INTO {users} (name, mail, created, data) VALUES('%s', '%s', %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', time(), serialize(array()));

  // This sets the above two users uid 0 (anonymous). We avoid an explicit 0
  // otherwise MySQL might insert the next auto_increment value.
  db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", '');

If user module works for you, then the fix is likely this:

db_query("UPDATE {domain} SET domain_id = domain_id - domain_id");

I suspect that the Drupal core code changed at some point, because this code was originally taken from system install.

tobiassjosten’s picture

That fix works perfectly and looks solid. Here's a patch as promised.

agentrickard’s picture

Thanks.

Note that this also applies to 7.x.2.

agentrickard’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev

Works as expected. Committing to 6.x.

agentrickard’s picture

Status: Needs review » Fixed
FileSize
790 bytes

And a committed patch for 7.x.2.

This issue does not affect 7.x.3.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.