When using drush tmti to import a folder, the job isn't updated for each file resulting in only the first one being imported

Created on 16 April 2025, about 1 month ago

Problem/Motivation

When mass importing XLF files, the commande drush tmti will only import the first file and then will display a message saying that the job is finished referencing the job ID of the first file in the folder.

Steps to reproduce

Export various XLF files, put them in a folder and import this folder, you will get this warning :

$ drush tmti --accept-translation xlf_files
 [notice] Scanning dir xlf_files.
 [notice] Successfully imported file JobID40_fr_en for translation job Ressources (#45).
 [warning] Skipping JobID41_fr_en for finished job Test content (#41).
 [warning] Skipping JobID42_fr_en for finished job Test content (#41).
 [warning] Skipping JobID43_fr_en for finished job Test content (#41).
...

So the first file is imported and all the following are skipped saying that the job is finished.

Proposed resolution

It seems that this code will keep $job in cache and thus won't update for each file.

    $plugin = \Drupal::service('plugin.manager.tmgmt_file.format')->createInstance('xlf');
    foreach ($files as $path => $info) {
      $job = $plugin->validateImport($path);
      if (empty($job)) {
        $this->logger()->error(dt('No translation job found for @filename.', array('@filename' => $info->name)));
        continue;
      }

      if ($job->isFinished()) {
        $this->logger()->warning(dt('Skipping @filename for finished job @name (#@id).', array('@filename' => $info->name, '@name' => $job->label(), '@id' => $job->id())));
        continue;
      }

     // ...

A quick solution that we found was to reinstantiate the plugin in the loop :

    foreach ($files as $path => $info) {
      $plugin = \Drupal::service('plugin.manager.tmgmt_file.format')->createInstance('xlf');
      $job = $plugin->validateImport($path);
      if (empty($job)) {
        $this->logger()->error(dt('No translation job found for @filename.', array('@filename' => $info->name)));
        continue;
      }

Remaining tasks

MR to be submitted.

User interface changes

None

API changes

None

Data model changes

None

🐛 Bug report
Status

Active

Version

1.0

Component

Translator: File

Created by

🇫🇷France tostinni

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