localgovdrupal / localgov_core

LocalGovDrupal Core module, for helper functions and core dependencies.
GNU General Public License v2.0
3 stars 6 forks source link

Installing site from existing config fails #245

Open stephen-cox opened 3 months ago

stephen-cox commented 3 months ago

Error is: 'block' entity with ID 'localgov_base_publication_navigation' already exists.

Steps to reproduce

Delete the install_localgov hook from the profile or patch core from https://www.drupal.org/project/drupal/issues/2982052

drush si localgov -y
drush localgov_workflows localgov_publications -y
drush cex -y
drush si localgov --existing-config -y

Exception trace

  at /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:519
 Drupal\Core\Entity\EntityStorageBase->doPreSave() at /app/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php:483
 Drupal\Core\Entity\EntityStorageBase->save() at /app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:257
 Drupal\Core\Config\Entity\ConfigEntityStorage->save() at /app/web/core/lib/Drupal/Core/Entity/EntityBase.php:354
 Drupal\Core\Entity\EntityBase->save() at /app/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php:614
 Drupal\Core\Config\Entity\ConfigEntityBase->save() at /app/web/modules/contrib/localgov_core/src/Service/DefaultBlockInstaller.php:136
 Drupal\localgov_core\Service\DefaultBlockInstaller->installForModule() at /app/web/modules/contrib/localgov_core/src/Service/DefaultBlockInstaller.php:109
 Drupal\localgov_core\Service\DefaultBlockInstaller->install() at /app/web/modules/contrib/localgov_core/localgov_core.module:73
 localgov_core_localgov_post_install() at /app/web/profiles/contrib/localgov/localgov.profile:45
 {closure}() at /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php:395
 Drupal\Core\Extension\ModuleHandler->invokeAllWith() at /app/web/profiles/contrib/localgov/localgov.profile:46
 localgov_post_install_task() at /app/web/core/includes/install.core.inc:697
 install_run_task() at /app/web/core/includes/install.core.inc:574
 install_run_tasks() at /app/web/core/includes/install.core.inc:122
 install_drupal() at /app/vendor/drush/drush/includes/drush.inc:69
 drush_call_user_func_array() at /app/vendor/drush/drush/includes/drush.inc:53
 drush_op() at /app/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php:167
 Drush\Commands\core\SiteInstallCommands->install() at n/a:n/a
 call_user_func_array() at /app/vendor/consolidation/annotated-command/src/CommandProcessor.php:276
 Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback() at /app/vendor/consolidation/annotated-command/src/CommandProcessor.php:212
 Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter() at /app/vendor/consolidation/annotated-command/src/CommandProcessor.php:176
 Consolidation\AnnotatedCommand\CommandProcessor->process() at /app/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:391
 Consolidation\AnnotatedCommand\AnnotatedCommand->execute() at /app/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /app/vendor/symfony/console/Application.php:1096
 Symfony\Component\Console\Application->doRunCommand() at /app/vendor/symfony/console/Application.php:324
 Symfony\Component\Console\Application->doRun() at /app/vendor/symfony/console/Application.php:175
 Symfony\Component\Console\Application->run() at /app/vendor/drush/drush/src/Runtime/Runtime.php:110
 Drush\Runtime\Runtime->doRun() at /app/vendor/drush/drush/src/Runtime/Runtime.php:40
 Drush\Runtime\Runtime->run() at /app/vendor/drush/drush/drush.php:139
 require() at /app/vendor/drush/drush/drush:4
 include() at /app/vendor/bin/drush:119
rupertj commented 2 months ago

I think this needs fixing in localgov_core. Once the default block installer service has figured out what ID it should be using for a block, it should check if that ID is in use before trying to save it.

rupertj commented 2 months ago

I've realised this is probably yet another case where we need to add and check the $is_syncing param, but I think what I already proposed to add the check for existing IDs is worth doing too, as it'll make the block installer slightly more robust.

rupertj commented 2 months ago

Ive just followed the steps to recreate with

"localgovdrupal/localgov_core": "dev-fix/2.x/245-installing-site-from-existing-config-fails as 2.13.7"

And the site installs from config successfully now, with publications enabled.