From 0acc2f337ce9aed5f105be4acc0c73ebe5003f12 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Mon, 18 Oct 2021 10:26:38 +0100
Subject: [PATCH] Issue #3219140 by danflanagan8, huzooka, quietone, Wim Leers:
 d7_language_content_comment_settings triggers MigrateException if the source
 bundle is longer than 32 chars: use migration_lookup

---
 .../d7_language_content_comment_settings.yml      | 15 +++++----------
 ...tentCommentSettingsNoEntityTranslationTest.php | 13 +++++++++++++
 .../MigrateLanguageContentCommentSettingsTest.php | 13 +++++++++++++
 .../migrate_drupal/tests/fixtures/drupal7.php     |  4 ++++
 .../tests/src/Functional/d7/Upgrade7Test.php      |  2 +-
 5 files changed, 36 insertions(+), 11 deletions(-)

diff --git a/core/modules/content_translation/migrations/d7_language_content_comment_settings.yml b/core/modules/content_translation/migrations/d7_language_content_comment_settings.yml
index c40173d4fca9..4515535d1324 100644
--- a/core/modules/content_translation/migrations/d7_language_content_comment_settings.yml
+++ b/core/modules/content_translation/migrations/d7_language_content_comment_settings.yml
@@ -8,22 +8,17 @@ source:
   plugin: d7_language_content_settings
   constants:
     target_type: comment
-    id_prefix: comment_node_
-    label_suffix: comment
 process:
   target_bundle:
     -
-      plugin: concat
+      plugin: migration_lookup
+      migration: d7_comment_type
+      no_stub: true
       source:
-        - constants/id_prefix
         - type
     -
-      plugin: static_map
-      bypass: true
-      # The Forum module provides its own comment type (comment_forum), which we
-      # want to reuse if it exists.
-      map:
-        comment_node_forum: comment_forum
+      plugin: skip_on_empty
+      method: row
   target_entity_type_id: constants/target_type
   default_langcode:
     -
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php
index 287a98e2fdfc..29cb946832e8 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsNoEntityTranslationTest.php
@@ -31,6 +31,7 @@ class MigrateLanguageContentCommentSettingsNoEntityTranslationTest extends Migra
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->startCollectingMessages();
     $this->migrateCommentTypes();
     $this->executeMigrations([
       'language',
@@ -57,6 +58,9 @@ public static function migrateDumpAlter(KernelTestBase $test) {
    * Tests migration of content language settings.
    */
   public function testLanguageCommentSettings() {
+    // Confirm there is no message about a missing bundle.
+    $this->assertEmpty($this->migrateMessages, $this->migrateMessages['error'][0] ?? '');
+
     // Article and Blog content type have multilingual settings of 'Enabled,
     // with Translation'. Assert that comments are translatable and the default
     // language is 'current_interface'.
@@ -88,6 +92,15 @@ public function testLanguageCommentSettings() {
     $this->assertTrue($config->isLanguageAlterable());
     $this->assertSame($third_party_settings, $config->get('third_party_settings'));
 
+    // The content type with a long name has multilingual settings of 'Enabled'.
+    $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_a_thirty_two_char');
+    $this->assertFalse($config->isNew());
+    $this->assertSame('comment', $config->getTargetEntityTypeId());
+    $this->assertSame('comment_node_a_thirty_two_char', $config->getTargetBundle());
+    $this->assertSame('current_interface', $config->getDefaultLangcode());
+    $this->assertTrue($config->isLanguageAlterable());
+    $this->assertSame($third_party_settings, $config->get('third_party_settings'));
+
     // Test content type has multilingual settings of 'Enabled, with field
     // translation'.
     $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_test_content_type');
diff --git a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php
index 4032c9dd05ba..db157140ced5 100644
--- a/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php
+++ b/core/modules/language/tests/src/Kernel/Migrate/d7/MigrateLanguageContentCommentSettingsTest.php
@@ -28,6 +28,7 @@ class MigrateLanguageContentCommentSettingsTest extends MigrateDrupal7TestBase {
    */
   protected function setUp(): void {
     parent::setUp();
+    $this->startCollectingMessages();
     $this->migrateCommentTypes();
     $this->executeMigrations([
       'language',
@@ -39,6 +40,9 @@ protected function setUp(): void {
    * Tests migration of content language settings.
    */
   public function testLanguageCommentSettings() {
+    // Confirm there is no message about a missing bundle.
+    $this->assertEmpty($this->migrateMessages, $this->migrateMessages['error'][0] ?? '');
+
     // Article and Blog content type have multilingual settings of 'Enabled,
     // with Translation'. Assert that comments are translatable and the default
     // language is 'current_interface'.
@@ -70,6 +74,15 @@ public function testLanguageCommentSettings() {
     $this->assertTrue($config->isLanguageAlterable());
     $this->assertSame($third_party_settings, $config->get('third_party_settings'));
 
+    // The content type with a long name has multilingual settings of 'Enabled'.
+    $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_a_thirty_two_char');
+    $this->assertFalse($config->isNew());
+    $this->assertSame('comment', $config->getTargetEntityTypeId());
+    $this->assertSame('comment_node_a_thirty_two_char', $config->getTargetBundle());
+    $this->assertSame('current_interface', $config->getDefaultLangcode());
+    $this->assertTrue($config->isLanguageAlterable());
+    $this->assertSame($third_party_settings, $config->get('third_party_settings'));
+
     // Test content type has multilingual settings of 'Enabled, with field
     // translation'.
     $config = ContentLanguageSettings::loadByEntityTypeBundle('comment', 'comment_node_test_content_type');
diff --git a/core/modules/migrate_drupal/tests/fixtures/drupal7.php b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
index 2412555aaf42..7743bb83b95d 100644
--- a/core/modules/migrate_drupal/tests/fixtures/drupal7.php
+++ b/core/modules/migrate_drupal/tests/fixtures/drupal7.php
@@ -59872,6 +59872,10 @@
   'name' => 'language_content_type_article',
   'value' => 's:1:"2";',
 ))
+->values(array(
+  'name' => 'language_content_type_a_thirty_two_character_type_name',
+  'value' => 's:1:"1";',
+))
 ->values(array(
   'name' => 'language_content_type_blog',
   'value' => 's:1:"2";',
diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php
index dd14e7a3b5b3..c0aeedc9f34a 100644
--- a/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php
+++ b/core/modules/migrate_drupal_ui/tests/src/Functional/d7/Upgrade7Test.php
@@ -89,7 +89,7 @@ protected function getEntityCounts() {
       'file' => 3,
       'filter_format' => 7,
       'image_style' => 7,
-      'language_content_settings' => 22,
+      'language_content_settings' => 24,
       'node' => 7,
       'node_type' => 8,
       'rdf_mapping' => 8,
-- 
GitLab