We are trying update Domain module from version 1.0.0-alpha to actual one. I run composer update, drush updb, drush entup, drush cex -y. It looks fine.

But if i try reinstall site (drush install, drush cim, I get this error:

[error]  The import failed due to the following reasons:
Unexpected error during import with operation update for domain.record.ourdomain: The hostname (ourdomain.dev) is already registered.

We have enabled Domain, Domain Access and Domain Alias modules.

How I can fix it?

Comments

siva01 created an issue. See original summary.

siva01’s picture

Issue summary: View changes
agentrickard’s picture

Category: Bug report » Support request
agentrickard’s picture

So you are doing a full site reinstall and then importing from config? That sounds like a duplicate config issue.

Check that you don't have duplicate items in the config (and that you are importing config from the correct directory.)

For re-install, you might also need to use the 'config_installer' profile. (https://www.drupal.org/project/config_installer/)

The D8 version doesn't auto-install a default domain anymore, so I don't think it's a module issue.

agentrickard’s picture

Note also that a re-install is not an update, so the description of this issue is not correct.

siva01’s picture

I found, where is is problem. For previous version is domain_id: 321980512. Site install script run drush cim three times. After first cim is domain changed domain_id: 3172555. If I run cim again, it will return update error.

We run update too, but just only on stage/production. So we need both version functional.

agentrickard’s picture

Which alpha versions are you upgrading from and to?

We had to change the logic for generated IDs a long time ago (Oct 2017), and there isn't much to do except (possibly) editing your config files and re-importing.

See Drupal\domain\Entity::createDomainId() for the logic. See also #2908236: Domain ID may vary between 32-bit and 64-bit versions of PHP

However, you'll then have to update the node access table, which uses this data.

Essentially, you'll need a custom update function for dealing with this problem, because alpha-to-alpha updates aren't supported.

siva01’s picture

We try update from 1.0.0-alpha9.

siva01’s picture

What does mean "node access table". In table node_access isn't any domain related column/value. We have table node__field_domain_access, where is column field_domain_access_target_id, but it doesn't use domain_id, but domain machine name.

agentrickard’s picture

Yeah, that's going to catch the ID change. This code should work in an update hook:

$update = FALSE;
$storage = \Drupal::entityTypeManager()->getStorage('domain');
$domains = $storage->loadMultiple();
foreach ($domains as $domain) {
  $current_id = $domain->getDomainId();
  $new_id = $domain->createDomainId();
  if ($current_id != $new_id) {
    $domain->saveProperty('domain_id', $new_id);
    $update = TRUE;
  }
}
if ($update) {
  node_access_needs_rebuild();
}

I would do the following (while being able to restore from backup if this fails):

* Update the module
* Run database updates
* Export config
* In the UI, you will be prompted to rebuild node access. That process can take a while, and I don't know if it can be done via drush.

That should update the config so that it is created properly on a re-install.

agentrickard’s picture

Status: Active » Needs review
StatusFileSize
new611 bytes

Thinking through this issue, this patch might also fix it, though you would still be susceptible to the 32-bit / 64-bit issue.

siva01’s picture

Status: Needs review » Active

Code doesn't work. $domain->saveProperty('domain_id', $new_id); call presave() function, where is validation,if domain exist. And it exist. So if I run this script, I get same error described above.

siva01’s picture

StatusFileSize
new4.3 KB

I try patch and seem it work, but there is missing bracket.

PS: patch was apply on outdated version, so there are unrelated changes. I can't delete it.

siva01’s picture

StatusFileSize
new612 bytes

Adding only missing bracket.

agentrickard’s picture

Category: Support request » Bug report
Status: Active » Reviewed & tested by the community

Thanks for the test. I think we should add that code with a note about why it's there -- essentially, to prevent updating a domain id from a config file.

mkolar’s picture

Thanks @agentrickard this helped

  • agentrickard committed 0fed3e6 on 8.x-1.x authored by siva01
    Issue #3028892 by siva01, agentrickard: Update error:  The hostname is...
agentrickard’s picture

Status: Reviewed & tested by the community » Fixed
michal.sec’s picture

Hi @agentrickard,
is possible to release new version with this fix?

Thanks

agentrickard’s picture

Yes. I was trying to wait for https://www.drupal.org/project/domain/issues/3004243, but that's delayed.

It would be nice to get a review of #3025541: configFactory service invoking hooks early as well.

Status: Fixed » Closed (fixed)

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