Problem/Motivation

Currently through the sources bulk overview, we can submit a source item to a job anytime.
This might also apply to the cart.

The same item in progress for multiple times can result in inconsistent situations when accepting.

Proposed resolution

Only allow the same item once as part of the job. Well manage this situation in TMGMT core.
Skip items that are not allowed and show a message.

This requires us to cleanly take care of aborting jobs or single items instead of deleting them.
See: #2672924: Disallow item deletion after submission and support item abort

Remaining tasks

User interface changes

API changes

Data model changes

Comments

miro_dietiker created an issue. See original summary.

miro_dietiker’s picture

Title: Never allow submission of an item in process again » Never allow duplicate submission of an item while in process
MarinkoIg’s picture

Assigned: Unassigned » MarinkoIg

Assigned to me.

MarinkoIg’s picture

Status: Active » Needs review
StatusFileSize
new3.24 KB

Initial patch. Not sure is this the right direction..

Status: Needs review » Needs work

The last submitted patch, 4: tmgmt-duplicate-submission-2679949-4.patch, failed testing.

miro_dietiker’s picture

+++ b/sources/content/src/ContentEntitySourcePluginUi.php
@@ -249,29 +250,38 @@ class ContentEntitySourcePluginUi extends SourcePluginUiBase {
+      $query = \Drupal::entityQuery('tmgmt_job_item')
+          ->condition('item_type', $entity->getEntityTypeId())
+          ->condition('item_id', $entity->id());
+      $result = $query->execute();
+      if (!empty($result)) {
+        $items = JobItem::loadMultiple($result);
+      }

I think there should be a helper provided to check if there is a pending item // or if adding an item is allowed. Otherwise too repetitive: There are multiple UI channels to create a job to cover this.

berdir’s picture

We have an API for this? tmgmt_job_item_load_latest()

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new2.22 KB
new3.55 KB

Without test..

Status: Needs review » Needs work

The last submitted patch, 8: 2679949-8.patch, failed testing.

miro_dietiker’s picture

+++ b/sources/content/src/ContentEntitySourcePluginUi.php
@@ -248,10 +248,19 @@ class ContentEntitySourcePluginUi extends SourcePluginUiBase {
+        if(tmgmt_job_item_load_latest('content', $entity->getEntityTypeId(), $entity->id(), $source_lang)) {

As part of this issue, the method also needs to return continuous job items. And also continuous jobs need to use this method.

Note that we only allow one item per language pair (source + translation), and NOT in general on item across all jobs of all languages.

So you can only skip the items before job submission when the source and target language is set - and not when adding job items to the job.

Redefinition:
When on the job checkout form, we could check the job items that are not allowed for the language pair and output a warning with a count.
We will currently not add an indicator in the view per item!
Take no action yet as the user can change the target language. The warning might disappear for the newly selected language.
If the user still submits, the items will be dropped before submission in requestTranslation.

BTW there are some codestyle issues in the patch.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new2.82 KB
new5.04 KB

Work in progress..

Status: Needs review » Needs work

The last submitted patch, 11: 2679949-11.patch, failed testing.

miro_dietiker’s picture

Priority: Normal » Major

Hm, raising priority here. Mostly because of the bug in tmgmt_job_item_load_latest(). If the issue isn't progressing fast enough, we should put it into a separate issue.

berdir’s picture

miro_dietiker’s picture

Yeah right. Good to know there's an issue.
Still keeping it at that level since the new rule to only have one item submitted adds integrity boundaries that are majorly helping with management. ;-)

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new3.42 KB
new2.82 KB

Work in progress..

MarinkoIg’s picture

StatusFileSize
new136.51 KB

..and screenshot.

Status: Needs review » Needs work

The last submitted patch, 16: 2679949-16.patch, failed testing.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new4.44 KB
new3.04 KB

Without solution/part for 'Cart' and without test..

Status: Needs review » Needs work

The last submitted patch, 19: 2679949-19.patch, failed testing.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new6.82 KB
new2.38 KB

Fixed failing test..

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Form/JobForm.php
    @@ -173,6 +176,18 @@ class JobForm extends TmgmtFormBase {
    +        '#title' => \Drupal::translation()->formatPlural($num_of_existing_items, 'Already exist item in translation.', 'Already exist @count items in translation.'),
    
    @@ -490,6 +506,12 @@ class JobForm extends TmgmtFormBase {
    +      entity_delete_multiple('tmgmt_job_item', $ids_of_existing_items);
    

    I think we should add a notification (as a warning again? or just info?) that these items have been dropped.
    The original general statement that "Already exist" is too general, does not explicitly mention that they will be dropped on submission and there is no reference to what item affected.

  2. +++ b/src/Form/JobForm.php
    @@ -572,10 +594,17 @@ class JobForm extends TmgmtFormBase {
    +      $response->addCommand(new ReplaceCommand('.messages--warning', '<div class="messages messages--warning"><label>' . \Drupal::translation()->formatPlural($number_of_existing_items, 'Already exist item in translation.', 'Already exist @count items in translation.') . '</label></div>'));
    

    IMHO the message should be taken from the $form['message'] rebuilt above instead of duplicating build code.
    In any cas the row overlength formatting is also much onfortunate.

  3. +++ b/src/Form/JobForm.php
    @@ -572,10 +594,17 @@ class JobForm extends TmgmtFormBase {
    +      $response->addCommand(new InvokeCommand('.messages--warning', 'addClass', array('hidden')));
    

    There could be other warnings created. We should not hide this. Why is this needed?!

miro_dietiker’s picture

From discussions, more specifically:

On the job form i would display WARNING:
"5 items conflict with pending items and will be dropped on submission."
Then after submission, as an INFO
"5 conflicting items have been dropped."

With a follow up that we would want to annotate the conflicting items somehow more specifically so they can be identified in the item list.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new10.03 KB
new8.38 KB
new93.5 KB
new43.28 KB

Fixed bugs from #22, #23, covered 'Cart' but without test..

Status: Needs review » Needs work

The last submitted patch, 24: 2679949-24.patch, failed testing.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new10.15 KB
new2 KB

Improved code, but I'm not sure how to fix tests.

Status: Needs review » Needs work

The last submitted patch, 26: 2679949-26.patch, failed testing.

johnchque’s picture

+++ b/src/Form/JobForm.php
@@ -525,6 +545,17 @@ class JobForm extends TmgmtFormBase {
+        drupal_set_message(\Drupal::translation()->formatPlural($num_of_items, '1 conflicting item have been dropped.', '@count conflicting items have been dropped.'));

I think here it should be '1 conflicting item has been dropped'.

Also the problem with the tests is that we were submitting twice an item while it was in progress, it had to fail but I wonder why when we dropped the conflicting items we allow to create empty jobs? maybe would be better to discuss that too.

mbovan’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new3.93 KB
new38.49 KB
  1. +++ b/src/Form/JobForm.php
    @@ -208,6 +212,21 @@ class JobForm extends TmgmtFormBase {
    +        '#prefix' => '<div class="messages existing_items messages--warning hidden">',
    ...
    +        $form['message']['#prefix'] = '<div class="messages existing_items messages--warning">';
    

    Does "existing_items" needs to be "existing-items"?

  2. +++ b/src/Form/JobForm.php
    @@ -416,6 +435,7 @@ class JobForm extends TmgmtFormBase {
    +
    

    Extra line, unrelated.

  3. +++ b/src/Form/JobForm.php
    @@ -525,6 +545,17 @@ class JobForm extends TmgmtFormBase {
    +      $ids_of_existing_items = $this->checkoutExistingItems($form_state->get('check_target_language'));
    

    What about $existing_items_ids?

  4. +++ b/tmgmt.module
    @@ -177,6 +177,50 @@ function tmgmt_job_item_load_latest($plugin, $item_type, $item_id, $source_langu
    +    $return = array();
    ...
    +    return $return;
    

    Maybe $job_items instead of $return for the variable name.

Regarding failing tests,
1. Line 228 (TmgmtUiTest), looks like "Save" on empty translation will not actually save a translation which results that "Save as completed" does not appear.
2. Line 351 (TmgmtUiTest) - there is a wrong label. This happens when there are no job items in the job... Since this issue prevents adding duplicated items, the job label should be either updated or tests changed.

Btw, with dropping job items, we can have a situation where we create "empty" jobs (jobs with no job items)

The message looks a bit contradictory in that case... Not sure if we want to prevent job creation in case there is only one (duplicated) job item. Could be a followup.

Creating an empty jobs, leads to something like:

mbovan’s picture

Status: Needs review » Needs work
MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new10.99 KB
new6.16 KB

Fixed mistakes and bugs from #28 and #29.

Status: Needs review » Needs work

The last submitted patch, 31: 2679949-31.patch, failed testing.

johnchque’s picture

The test fail is caused by an old test, maybe we should delete those lines since the progress bar is already being tested somewhere else.

// Test that progress bar is being displayed.
$this->assertRaw('class="tmgmt-progress-pending" style="width: 50%"');
$this->assertRaw('class="tmgmt-progress-translated" style="width: 100%"');

In TMGMTUiReviewTest.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new14.18 KB
new3.19 KB

Added tests for other parts of new code and fixed bug in existing test.

berdir’s picture

StatusFileSize
new20.86 KB
new14.35 KB

I knew this was surprisingly easy on tests. The patch did remove conflicting fine enough, but it also ended up happily submitting completely empty jobs.

I refactored the check so that we can fail validation if that happens. And unsurprisingly, tests explode all over the place. Started fixing some, lets see how many fails are left.

Status: Needs review » Needs work

The last submitted patch, 35: 2679949-35.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new21.45 KB
new1.55 KB

Fixed that failing test too. Added another node so that we are testing the case where one item is deleted.

Not done yet, don't really understand \Drupal\tmgmt\Entity\Job::getConflictingItemIds() yet.

MarinkoIg’s picture

@Berdir, do I need to check this or you will continue with it?

berdir’s picture

StatusFileSize
new18.58 KB
new8.58 KB

I'm on it.

I think I understand what you were trying to do with the second last query. But that assumed that the one you're checking is the one that was changed last. That's not guaranteed.

What I didn't understand is all the logic with check target language and why you did two different checks. There is *always* a target language.

So I tried to simplify this. Only did manual testing now, lets see about tests.

Status: Needs review » Needs work

The last submitted patch, 39: 2679949-39.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new18.69 KB
new1.71 KB

Fixed the tests. The previous code also matched on inactive, not yet submitted job items, the cart test relied on that incorrect behavior. Fixed the test.

Will commit this when green I think. Did quite a lot of testing and this feels solid now.

berdir’s picture

Status: Needs review » Fixed

Committed.

  • Berdir committed 70d9bd4 on 8.x-1.x
    Issue #2679949 by MarinkoIg, Berdir: Never allow duplicate submission of...
miro_dietiker’s picture

Status: Needs review » Fixed

Hm, no idea why this state is not on fixed anymore..

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.