Problem/Motivation

From the code it is unclear if things break fatal, or if TMGMT still works fine if we have jobs / items assigned to a translator... and then delete the translator.

All cases, from new jobs, submitted, needs review and closed need to be tested.

Proposed resolution

If it breaks, fix.
I guess a test should cover these cases.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#31 verify_stability_with-2538360-31-interdiff.txt664 bytessasanikolic
#31 verify_stability_with-2538360-31.patch12.78 KBsasanikolic
#29 verify_stability_with-2538360-29-interdiff.txt516 bytessasanikolic
#29 verify_stability_with-2538360-29.patch12.77 KBsasanikolic
#26 verify_stability_with-2538360-26-interdiff.txt516 bytessasanikolic
#26 verify_stability_with-2538360-26.patch14.11 KBsasanikolic
#25 verify_stability_with-2538360-24-interdiff.txt1.34 KBsasanikolic
#25 verify_stability_with-2538360-24.patch14.5 KBsasanikolic
#22 verify_stability_with-2538360-22-interdiff.txt3.09 KBsasanikolic
#22 verify_stability_with-2538360-22.patch13.17 KBsasanikolic
#20 verify_stability_with-2538360-20-interdiff.txt2.71 KBsasanikolic
#20 verify_stability_with-2538360-20.patch11.68 KBsasanikolic
#18 verify_stability_with-2538360-18-interdiff.txt1.79 KBsasanikolic
#18 verify_stability_with-2538360-18.patch8.97 KBsasanikolic
#15 verify_stability_with-2538360-15-interdiff.txt4.23 KBsasanikolic
#15 verify_stability_with-2538360-15.patch8.92 KBsasanikolic
#13 html_is_escaped_in_all-2532284-11-interdiff.txt1.07 KBsasanikolic
#13 html_is_escaped_in_all-2532284-11.patch2.4 KBsasanikolic
#11 verify_stability_with-2538360-11-interdiff.txt1.96 KBsasanikolic
#11 verify_stability_with-2538360-11.patch8.98 KBsasanikolic
#8 verify_stability_with-2538360-8-interdiff.txt4.04 KBsasanikolic
#8 verify_stability_with-2538360-8.patch8.81 KBsasanikolic
#6 verify_stability_with-2538360-5.patch5.04 KBsasanikolic
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sasanikolic’s picture

Title: Verify stability with exiting jobs when deliting a translator » Verify stability with exiting jobs when deleting a translator
miro_dietiker’s picture

Title: Verify stability with exiting jobs when deleting a translator » Verify stability with existing jobs when deleting a translator

Another try. ;-)

sasanikolic’s picture

As I can see, we have a check that makes sure that translators can't be removed if there are active jobs using it.

I will extend the tests.

miro_dietiker’s picture

Yeah, that test seems pretty fine...

Then let's alter JobInterface::getTranslator() to return the translator entity or an Exception in case it was unsuccessful.
It should provide a hasTranslator that checks if a Translator is selected and the plugin is around...

There are other getTranslator methods that need similar fixing.

If a caller wants to deal with the situation, it needs to add a catch, but it seems in the current implementation, that's not needed..

miro_dietiker’s picture

sasanikolic’s picture

Status: Active » Needs review
FileSize
5.04 KB

Uploading patch with current progress. Added the functions hasTranslator and hasPlugin. There will probably be some test fails.

Also, removed the condition that is checking the active job attached to the translator. So now, we can't delete a translator if it has any job connected with it. In a followup, we should create some kind of automatization that deletes all connections between the translator and the (active) job.

Status: Needs review » Needs work

The last submitted patch, 6: verify_stability_with-2538360-5.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
8.81 KB
4.04 KB

Fixed the test fails...

Also, changed TranslatorTest for the error message, because now we can't delete translators that are connected with a job.

miro_dietiker’s picture

Status: Needs review » Needs work

Yes, this makes things much cleaner.

  1. +++ b/src/Entity/Job.php
    @@ -403,10 +401,22 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac
    +      throw new TMGMTException('Cannot get the translator.');
    

    You might want to check separately for target_id / hasPlugin and provide an explanation on why you can't get the translator.

  2. +++ b/src/Entity/Job.php
    @@ -403,10 +401,22 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac
    +    } else {
    +      return FALSE;
         }
    -    return FALSE;
    

    Doesn't need to change. 2 lines less with a fallback return FALSE.

  3. +++ b/src/Entity/Job.php
    @@ -601,10 +611,7 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac
       public function getTranslatorPlugin() {
    ...
    +    return $this->getTranslator()->getPlugin();
    

    I wonder if we should drop this method at all now. Let's discuss in a followup.

  4. +++ b/src/JobInterface.php
    @@ -244,11 +244,22 @@ interface JobInterface extends ContentEntityInterface, EntityOwnerInterface {
    +   *   True if exists, false otherwise.
    
    +++ b/src/TranslatorInterface.php
    @@ -97,6 +97,14 @@ interface TranslatorInterface extends ConfigEntityInterface {
    +   *   Returns true if it exists, false otherwise.
    

    From coding standard:
    "All caps are used in comments only when referencing constants, for example TRUE."
    So use all caps.

  5. +++ b/src/JobInterface.php
    @@ -244,11 +244,22 @@ interface JobInterface extends ContentEntityInterface, EntityOwnerInterface {
    +   * @return boolean
    

    bool

  6. +++ b/tmgmt.module
    @@ -411,7 +411,6 @@ function tmgmt_translator_load_available($job) {
    -    ->condition('state', Job::STATE_ACTIVE)
    

    That's quite some change. I think we should add some test coverage to proof the new logic.

    In the test that checks if the delete fails when items are there, please set the job also to a different state (such as STATE_FINISHED) and retest deletion error message.

sasanikolic’s picture

Created a followup for the discussion about dropping getTranslatorPlugin().

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
8.98 KB
1.96 KB

Added the fixes.

+++ b/src/Tests/TranslatorTest.php
@@ -62,8 +62,12 @@ class TranslatorTest extends TMGMTTestBase {
+    // With the new behaviour from #2538360, we cannot delete a translator if it
+    // is used by a node of any state.
+    $this->assertText(t('This translator cannot be deleted as long as there are active jobs using it.'));

About the last comment about the test, we have a check for the STATE_FINISHED. Should we also test all/some other states?

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/Entity/Job.php
    @@ -403,9 +401,24 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac
    +    else if (!$this->translator->target_id) {
    +      throw new TMGMTException('Cannot get the translator. The translator is missing.');
    +    }
    +    else if (!$this->translator->entity->hasPlugin()) {
    +      throw new TMGMTException('Cannot get the translator. The plugin is missing.');
    +    }
    +  }
    

    I think we can improve those messages a bit. What about...

    The job has no translator assigned.

    and

    The translator assigned to this job is missing the plugin.

    This method might be easier to follow have the if/elseif first and actually return it at the end.

  2. +++ b/src/Entity/Job.php
    @@ -403,9 +401,24 @@ class Job extends ContentEntityBase implements EntityOwnerInterface, JobInterfac
    +  public function hasTranslator() {
    +    if ($this->translator->target_id && $this->translator->entity->hasPlugin()) {
    +      return TRUE;
    +    }
         return FALSE;
    

    The check that you are doing is already returning a boolean, so you can write that as return $this->translator->target_id && ...

    Also, to be sure, you want to check ->entity, since it is possible that it is referencing a non-existing translator, so an ID would be set but couldn't be loaded.

  3. +++ b/src/JobInterface.php
    @@ -244,11 +244,22 @@ interface JobInterface extends ContentEntityInterface, EntityOwnerInterface {
    +   * @throws TMGMTException
    +   *   Throws an exception.
    

    that description is very helpful I would never have guessed that without that ;)

    Instead, decribe when an exception is thrown. Also, should have full namespace.

  4. +++ b/src/Plugin/views/field/Translator.php
    @@ -18,10 +18,15 @@ use Drupal\views\ResultRow;
     
    +  /**
    +   * @param \Drupal\views\ResultRow $values
    +   * @return string
    +   */
       function render(ResultRow $values) {
    

    This is an implementation of a base class/interface, so just @inheritdoc.

  5. +++ b/src/Plugin/views/field/Translator.php
    @@ -18,10 +18,15 @@ use Drupal\views\ResultRow;
    +      if ($job->hasTranslator()) {
    +        return $job->getTranslator() ? $job->getTranslator()->label() : t('Missing translator');
    +      }
    

    This logic doesn't make sense anymore, it will never go into the Missing Translator case anymore. That needs to become the else case or you need to remove the if again and use hasTranslator() on he first check.

  6. +++ b/src/Tests/TranslatorTest.php
    @@ -62,8 +62,12 @@ class TranslatorTest extends TMGMTTestBase {
         $this->drupalPostForm(NULL, array(), 'Delete');
    -    $this->assertText(t('Add translator'));
    -    $this->assertNoText($translator->label());
    +    // With the new behaviour from #2538360, we cannot delete a translator if it
    +    // is used by a node of any state.
    +    $this->assertText(t('This translator cannot be deleted as long as there are active jobs using it.'));
    +
    +    $this->drupalGet('admin/config/regional/tmgmt_translator');
    +    $this->assertText($translator->label());
    

    Hm. AFAIK it was a feature that you can delete a translator that is only used on completed jobs, why is this changed?

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
2.4 KB
1.07 KB

Ok fixed the issues above, reverted and extended the test.

Also, after talking with @berdir, reverted back the condition for deleting translators only when the job is not in active state as it was at the beginning.

Status: Needs review » Needs work

The last submitted patch, 13: html_is_escaped_in_all-2532284-11.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
8.92 KB
4.23 KB

Uhm, uploaded the wrong patch.

edurenye’s picture

Status: Needs review » Needs work
+++ b/src/JobInterface.php
@@ -464,6 +475,9 @@ interface JobInterface extends ContentEntityInterface, EntityOwnerInterface {
    *   The translator plugin instance.
+   *
+   * @throws TMGMTException
+   *   Throws an exception.
    */
   public function getTranslatorPlugin();

This other method also needs more explanation about when it throws the exception.
The rest looks fine for me.

mbovan’s picture

  1. +++ b/src/Entity/Translator.php
    @@ -219,17 +219,22 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
    + * {@inheritdoc}
    + */
    +  public function getPlugin() {
    

    2 extra spaces needed for doc block.

  2. +++ b/src/Entity/Translator.php
    @@ -219,17 +219,22 @@ class Translator extends ConfigEntityBase implements TranslatorInterface {
    +  public function hasPlugin() {
    +    if (!empty($this->plugin) && \Drupal::service('plugin.manager.tmgmt.translator')->hasDefinition($this->plugin)) {
    +      return TRUE;
         }
    -    catch (PluginException $e) {
    +    else {
    +      return FALSE;
    

    Else block can be removed and only return false after if condition.

  3. +++ b/src/JobInterface.php
    @@ -244,11 +244,22 @@ interface JobInterface extends ContentEntityInterface, EntityOwnerInterface {
    +   *   Throws an exception when there is no translator assigned or when the translator is missing the plugin.
    

    Comment is longer than 80 characters.

  4. +++ b/src/JobInterface.php
    @@ -464,6 +475,9 @@ interface JobInterface extends ContentEntityInterface, EntityOwnerInterface {
    +   *
    +   * @throws TMGMTException
    +   *   Throws an exception.
    

    Berdir's comment (#12/3).

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
8.97 KB
1.79 KB

Fixed other points above.

Status: Needs review » Needs work

The last submitted patch, 18: verify_stability_with-2538360-18.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
11.68 KB
2.71 KB

Added hasTranslator to the JobItemInterface and changed JobItemForm.

#2504639: Fatal error when clicking 'in progress' without a translator broke the tests. This patch should fix it.

Berdir’s picture

Status: Needs review » Needs work
+++ b/tmgmt.module
@@ -401,7 +401,7 @@ function tmgmt_translator_load_available($job) {
  * be modified or deleted. A translator is considered 'busy' if there are jobs
- * attached to it that are in an active state.
+ * attached to it that are in any state.
  *

left-over change, should be reverted too.

Looks good to me, we could hold on and try to find more possibly broken cases. One that we should possibly try is deleting a translator of a completed job and then viewing the job and job items again. Can you try that and extend the existing test for that?

But other than that, I think we should go ahead and get this in asap.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
13.17 KB
3.09 KB

Here is the extended test with the fixes.

Status: Needs review » Needs work

The last submitted patch, 22: verify_stability_with-2538360-22.patch, failed testing.

LKS90’s picture

+++ b/tmgmt.module
@@ -401,7 +401,7 @@ function tmgmt_translator_load_available($job) {
+ * attached to it that are in any active state.

Still there?

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
14.5 KB
1.34 KB

Job messages config file changes for the test fails.

sasanikolic’s picture

Nitpick, removed the "y" from any (#24).

Status: Needs review » Needs work

The last submitted patch, 26: verify_stability_with-2538360-26.patch, failed testing.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
12.77 KB
516 bytes

Rebased.

LKS90’s picture

Status: Needs review » Needs work
+++ b/src/Tests/TranslatorTest.php
@@ -63,7 +65,18 @@ class TranslatorTest extends TMGMTTestBase {
+    $this->assertText($translator->label() . ' has been deleted.');

Revert the change here, this isn't translatable anymore.
After that I'll give my blessing :P.

sasanikolic’s picture

Status: Needs work » Needs review
FileSize
12.78 KB
664 bytes

Reverted. :)

LKS90’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine!

Berdir’s picture

Status: Reviewed & tested by the community » Fixed

I think so too. Committed.

  • Berdir committed 1df447a on 8.x-1.x authored by sasanikolic
    Issue #2538360 by sasanikolic: Verify stability with existing jobs when...

Status: Fixed » Closed (fixed)

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