Problem/Motivation

After adding a couple of new domains to the existing list of domains, we're now getting the following error when trying to deploy:

The import failed due to the following reasons:
Deleted and replaced configuration entity "simple_sitemap.type.example_com"

Steps to reproduce

- Create a new domain and export out the configs
- Try to deploy the config
- Notice that when running `drush cim -y` you get the above error

Proposed resolution

The error happens when an entity, in our case, the `simple_sitemap.type.example_com` config entity, you are trying to create already exists.

After some debugging, we found out that the error is emanating from `domain_simple_sitemap_domain_insert()`. In `addSitemapVariant()` it tries to create the sitemap type which is already exported in config:

    // Create a new sitemap type for the domain.
    $type_storage = \Drupal::entityTypeManager()->getStorage('simple_sitemap_type');
    if ($type_storage->load($domain->id()) === NULL) {
      $domain_sitemap = $type_storage->create([
        'id' => $domain->id(),
        'label' => $domain->label() . ' sitemap',
        'description' => 'Sitemap type for domain: ' . $domain->label(),
        'sitemap_generator' => 'default',
        'url_generators' => [
          'domain_entity',
          'custom',
          'entity',
          'entity_menu_link_content',
          'arbitrary',
        ],
      ]);
      // Set the domain to the sitemap type via third party settings.
      $domain_sitemap->setThirdPartySetting('domain_simple_sitemap', 'sitemap_domain', $domain->id());
      // Save our new sitemap type.
      $domain_sitemap->save();
    }

So, this hook is running too early during configuration sync.

Remaining tasks

As mentioned here, we'll need to add the following in `domain_simple_sitemap_domain_insert()`:

   if (\Drupal::isConfigSyncing()) {
     // Do not change data while config import in progress.
     return;
   }

User interface changes

None

API changes

None

Data model changes

None

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

shabana.navas created an issue. See original summary.

shabana.navas changed the visibility of the branch 3465449-import-failed-deleted to hidden.

shabana.navas’s picture

Status: Active » Needs review
StatusFileSize
new766 bytes

joshua1234511 made their first commit to this issue’s fork.

joshua1234511 changed the visibility of the branch 3465449-import-failed-deleted to active.

joshua1234511 changed the visibility of the branch 3.0.x to hidden.

joshua1234511’s picture

Tested the patch provided, The patch fixes the issue.
Raised a MR and setting for code review.

rcodina’s picture

Patch on #3 works like a charm using 3.0.0-rc2! Thanks!

i-trokhanenko’s picture

Status: Needs review » Reviewed & tested by the community

i-trokhanenko’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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