re-request translations with continuous job

Created on 4 May 2023, over 1 year ago

Problem/Motivation

I need to re-request translation only for Job items with STATE_ACTIVE, with continuous job. Actually, when I re-request translations, all job items
with STATE_ACCEPTED switch to STATE_ACTIVE to be translated, but this can have an impact on performance, if I have 1000 tasks already accepted, I don't want to re-request translations for all.

Steps to reproduce

1. Create 2 continuous job like FR to EN and FR to DE (Don't use "Submit continuous job items on cron option"):

2. Use Deepl Translator provider plugin with "Auto accept finished translations" option, and configured with good content type to translate
3. Create node FR with EN & DE translated node
4. Two job items are created with STATE_ACTIVE in admin/tmgmt/job_items
5. Send translation request with bulk operation form like :

6. Create another node FR with EN & DE translated node and restart process

In the file : RequestTranslationTmgmtActionApproveForm.php
In formSubmit() method, all job items are force to change to switch sate with

$item->setState(JobItem::STATE_ACTIVE);

Proposed resolution

In RequestTranslationTmgmtActionApproveForm.php

  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Retrieve selected jobs.
    $jobs = $this->getEntities($this->entityIds);

    // Mark jobs as unprocessed for further processing.
    foreach ($jobs as $job) {
      // Requesting translation is possible only for unprocessed jobs.
      // See JobCheckoutManager::checkoutMultiple() method.

        $job->setState(Job::STATE_UNPROCESSED);

        foreach ($job->getItems() as $item) {
          // Reset statistics for the job item in order to have "count_pending"
          // value not equal to "0". See Job::requestTranslation() and
          // Job::getItems() methods.
          if ($job->getJobType() !== 'continuous') {
            $item->setState(JobItem::STATE_ACTIVE);
          }
          $item->resetData();
          $item->recalculateStatistics();
          $item->save();
        }
    }

    // Launch TMGMT's checkout process.
    $this->checkoutManager->checkoutAndRedirect($form_state, $jobs);
    $this->jobQueue->setDestination('/admin/tmgmt/jobs');
  }
💬 Support request
Status

Active

Version

9.0

Component

Code

Created by

🇫🇷France Flow1990

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

Comments & Activities

Production build 0.71.5 2024