Imports fail when langcode contains a hyphen

Created on 6 June 2024, 8 months ago

Problem/Motivation

When attempting to import content where the langcode contains a hyphen e.g. en-gb the following error is returned:

Migration failed with source plugin exception: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.migrate_map_390813_3218699_node_page_engb' doesn't exist: SELECT "map".* FROM "migrate_map_390813_3218699_node_page_engb" "map" WHERE "source_ids_hash" = :db_condition_placeholder_0; Array ( [:db_condition_placeholder_0] => 3004253c59e5994d3f0860c16190e0e73644d7b539adb292ef94614fc451dee0 ) in /var/www/html/web/core/modules/mysql/src/Driver/Database/mysql/ExceptionHandler.php line 56

<!--break-->

The migration process creates a table in the format of 'migrate_map_390813_3218699_node_page_en-gb'. The error appears to be due to a mismatch between the query (where the hyphen is removed) and the table name (where the hyphen persists).

The 'pluginId' is used to create the table name which has the langcode appended. The issue can be resolved by removing the hyphen from the table name.

Steps to reproduce

Ensure a Drupal site has the Content Workflow modules installed and is configured for multilingual content.

  • Create a project in Content Workflow
  • Create a Content Workflow template in the project with a title plain text field (important it's set as plain text) and a body text field
  • Add another tab with the same fields for a translation
  • Create a content item in the project with content in each tab
  • Add a language to Drupal that contains a hyphen
  • Configure the Basic page content type to be translatable
  • Map the Content Workflow project to the Basic page content type for both languages
  • Run an import
  • Confirm the translation failed to import

Proposed resolution

Sanitise the 'pluginId' value by removing the hyphen

diff --git a/content_workflow_bynder.module b/content_workflow_bynder.module
index b90b141..112dbc9 100644
--- a/content_workflow_bynder.module
+++ b/content_workflow_bynder.module
@@ -70,6 +70,9 @@ function content_workflow_bynder_import_process($cwb_ids, array $import_options,
 
       if ($migration) {
 
+        // Strip out '-' from language-country part of id.
+        $migration->set('pluginId', str_replace('-', '', $migrationId));
+
         // Do not use the item list feature of the parent migration class,
         // limit the source directly as this is more efficient and sources
         // may be multiplied to support repeatable components.

Remaining tasks

N/A

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024