diff --git a/core/modules/content_translation/content_translation.services.yml b/core/modules/content_translation/content_translation.services.yml index f7cc11f..e73fb0d 100644 --- a/core/modules/content_translation/content_translation.services.yml +++ b/core/modules/content_translation/content_translation.services.yml @@ -27,6 +27,6 @@ services: content_translation.updates_manager: class: Drupal\content_translation\ContentTranslationUpdatesManager - arguments: ['@entity.manager', '@entity.definition_update_manager'] + arguments: ['@entity.manager', '@entity.definition_update_manager', '@lock'] tags: - { name: event_subscriber } diff --git a/core/modules/content_translation/src/ContentTranslationUpdatesManager.php b/core/modules/content_translation/src/ContentTranslationUpdatesManager.php index 98b16de..af59e64 100644 --- a/core/modules/content_translation/src/ContentTranslationUpdatesManager.php +++ b/core/modules/content_translation/src/ContentTranslationUpdatesManager.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; +use Drupal\Core\Lock\LockBackendInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; /** @@ -33,6 +34,13 @@ class ContentTranslationUpdatesManager implements EventSubscriberInterface { protected $updateManager; /** + * The lock backend. + * + * @var \Drupal\Core\Lock\LockBackendInterface + */ + protected $lock; + + /** * Constructs an updates manager instance. * * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager @@ -40,9 +48,10 @@ class ContentTranslationUpdatesManager implements EventSubscriberInterface { * @param \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface $update_manager * The entity definition update manager. */ - public function __construct(EntityManagerInterface $entity_manager, EntityDefinitionUpdateManagerInterface $update_manager) { + public function __construct(EntityManagerInterface $entity_manager, EntityDefinitionUpdateManagerInterface $update_manager, LockBackendInterface $lock) { $this->entityManager = $entity_manager; $this->updateManager = $update_manager; + $this->lock = $lock; } /** @@ -66,7 +75,11 @@ public function updateDefinitions(array $entity_types) { } } } - $this->updateManager->applyUpdates(); + // Acquire a lock to avoid race conditons. + if ($this->lock->acquire('content_translation_entity_schema_updates')) { + $this->updateManager->applyUpdates(); + $this->lock->release('content_translation_entity_schema_updates'); + } } } diff --git a/core/modules/content_translation/src/Tests/ContentTranslationConfigImportTest.php b/core/modules/content_translation/src/Tests/ContentTranslationConfigImportTest.php index 9d3450c..d82c4cb 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationConfigImportTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationConfigImportTest.php @@ -30,7 +30,7 @@ class ContentTranslationConfigImportTest extends KernelTestBase { * * @var array */ - public static $modules = array('system', 'user', 'entity_test', 'language', 'content_translation'); + public static $modules = array('system', 'user', 'entity_test', 'language', 'content_translation', 'text'); /** * {@inheritdoc} diff --git a/core/modules/content_translation/src/Tests/ContentTranslationSettingsApiTest.php b/core/modules/content_translation/src/Tests/ContentTranslationSettingsApiTest.php index 397288a..eff9757 100644 --- a/core/modules/content_translation/src/Tests/ContentTranslationSettingsApiTest.php +++ b/core/modules/content_translation/src/Tests/ContentTranslationSettingsApiTest.php @@ -21,7 +21,7 @@ class ContentTranslationSettingsApiTest extends KernelTestBase { * * @var array */ - public static $modules = array('language', 'content_translation', 'user', 'entity_test'); + public static $modules = array('language', 'content_translation', 'user', 'entity_test', 'text'); /** * {@inheritdoc}