Situation: run entity_translation_upgrade using post beta6 latest dev entity_translation_upgrade for a content translation node using the GUI, OR the drush plugin for that matter #1800158: Entity Translation Upgrade, drush extension.

entity_translation_upgrade_do needs to automatically create the entity_translation row for the source language in entity_translation

example:

select * from entity_translation where entity_id = 12345;

PRIOR to patch:

Entity_type entity_id language source uid status translate created
node        12345     fr       en     99     1       0      1499977756
select * from entity_translation where entity_id = 12345;

AFTER PATCH and redoing the entity_translation_upgrade for that content (restore backup and rerun ET_upgrade)

Entity_type entity_id language source uid status translate created
node        12345     en       fr     1      1       0      1499977756
node        12345     fr       en     99     1       0      1499977756

Without this patch, after an entity_translation upgrade the french fields show up on the /en/node/12345/edit
simply clicking translate will add this missing row, but best if this is correctly fixed during the actual entity_translation upgrade because I don't want our users to have to click several thousand times the translate link.

SOLUTION: apply latest patch below PRIOR to running entity_translation_upgrade for a node translation to entity_translation upgrade, we recommend that we commit this fix asap.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joseph.olstad created an issue. See original summary.

joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

joseph.olstad’s picture

Issue summary: View changes
gdaw’s picture

Thanks a bunch!

RTBC +1

gdaw’s picture

Status: Needs review » Reviewed & tested by the community
joseph.olstad’s picture

Issue summary: View changes
joseph.olstad’s picture

Issue summary: View changes
dsutter’s picture

Works for me.
RTBC +1

joseph.olstad’s picture

PLEASE COMMIT! Lets get this in right away, plan for a 1.0 release!

stefanos.petrakis@gmail.com’s picture

Status: Reviewed & tested by the community » Needs work

Hi all and thanks for the report, patch-work and feedback.

I think that that piece of code reads a bit inconsistent, as in:

+ IF $translations->original is empty
+ THEN $translations->data must be empty too
+ THEREFORE we can go ahead and initialize the data property


As an alternative option, this code (which exists inside the updateTranslations() function) runs an explicit check on the data property:

    if (empty($this->getTranslations()->data)) {
      $this->initTranslations();
    }

This seems to solve the reported problem as well, any opinions against this?

And at least a test for this scenario should be included in the patch, something along those lines:

  1. Enable content translation for a content type
  2. Add a source node and a translated node of that content type
  3. Enable translation for the body field
  4. Run the Entity Translation upgrade for that content type
  5. Load the source node
  6. Edit the source node
  7. Assert that the source node form's body-field contains the same value as the source node object body field in the current active language

Would anyone of the people involved so far care to provide an updated patch with the test?

joseph.olstad’s picture

Funny you mention that @stefanos.petrakis , I grabbed that code VERBATIM from 7.x-1.x dev of entity_translation

so if it's needs work in my patch, then entity_translation 7.x-1.x dev needs work.

see this screenshot line 231 of entity_translation.admin.inc :
line 231

now look at the patch:

+      // Initialize translations if they are empty.
+      $translations = $handler->getTranslations();
+      if (empty($translations->original)) {
+        $handler->initTranslations();
+        $handler->saveTranslations();
+      }

SAME=SAME

it works, passes testing, and conforms exactly to the entity_translation module, copied verbatim.

The code is fired when the 'translate' link is clicked, that's where I copied the code from.

The same operation must occur in the entity_translation_upgrade_do during an entity_translation_upgrade

Somewhere between beta5 and the current 1.x dev , this became an issue, or perhaps I didn't notice it before.

But yes, the patch is needed, would prefer to perform refactoring in a new ticket, I maintain my call for RTBC, feel free to make a new change to the logic as long as it works , but this patch works as is, and is following the design pattern set up by the developers of entity_translation.

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community
joseph.olstad’s picture

a bit inconsistent, as in

as in, ? what? entity_translation? lol

the patch >is< consistent with entity_translation, as described.

joseph.olstad’s picture

Want a side order of chicken and some fries with that?

stefanos.petrakis@gmail.com’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

With inconsistent I meant that reading that code in isolation, leads to the conclusion that if $handler->translations->original is not set, then it is safe to overwrite the $handler->translations->data property by calling initTranslations(). That is a leap of faith. Any useful feedback on that specific point?

Even if that code came from the current code base, it doesn't mean that there is no room for reviews and/or improvement.
And code duplication should be avoided.

About testing: increasing the test coverage is a must on the way to a stable release (#1624830: Plan for Entity Translation 7.x-1.0 release).
The current patch passes testing because there is no test case for the problem we are dealing with in this issue.
We are trying to reproduce the error which means we are half-way done with the testing conceptually, I already suggested a testing scenario.
Any possibility on helping with adding tests?

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
1.95 KB

Ok, I protest, but if you insist.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: D7_entity_translation_upgrade_fix-2899658-19.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joseph.olstad’s picture

here's another one, not sure why #19 failed , been a long day.

joseph.olstad’s picture

Status: Needs work » Needs review
joseph.olstad’s picture

The last submitted patch, 22: D7_entity_translation_upgrade_fix-2899658-22.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 24: D7_entity_translation_upgrade_fix-2899658-23.patch, failed testing. View results

joseph.olstad’s picture

Status: Needs work » Needs review
FileSize
2.05 KB

this unrelated code sniffer patch was autogenerated , interesting, nice job drupal.org , if you're going to complain, at least be helpful about it.
https://dispatcher.drupalci.org/job/drupal_d7/31890/artifact/jenkins-dru...

joseph.olstad’s picture

joseph.olstad’s picture

The last submitted patch, 27: D7_entity_translation_upgrade_fix-2899658-27.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 28: D7_entity_translation_upgrade_fix-2899658-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joseph.olstad’s picture

Status: Needs work » Needs review
FileSize
1.95 KB

looks like handler object has a problem with pointers or pass by reference?

who cares?

ALRIGHT, it was a nice though, ok, back to PATCH 5 yet????????????????????????

joseph.olstad’s picture

ok, back to patch 5

Status: Needs review » Needs work

The last submitted patch, 32: D7_entity_translation_upgrade_fix-2899658-30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joseph.olstad’s picture

patch 30 failed too.

stefanos.petrakis
can we just go with patch 5 ?

or can you please explain to me why patch 30 isn't working?

stefanos.petrakis@gmail.com’s picture

Here is a rewrite with tests.

The tests (entity_translation-tests-2899658-36.patch) should fail when run on their own, because of the reported issue.

The fix on its own (entity_translation-fix_for_empty_translations-2899658-36.patch) is here for reference and follows the idea of simplicity/readability (for the next time someone has to look at that piece of code).
The idea from @joseph.olstad about wrapping this inside a function is good for code reuse, but I don't want to refactor other files (entity_translation.admin.inc) without having some proof that we won't break sth. Optimally this should move into a new task.

The complete tests+fix patch (entity_translation-upgrade_fix_with_tests_added-2899658-36.patch) is also available and should be used to resolve this issue.

Let's see what the CI thinks. And a big thanks to @joseph.olstad for the amazing efforts here.

The last submitted patch, 36: entity_translation-upgrade_fix_with_tests_added-2899658-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 36: entity_translation-tests-2899658-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

joseph.olstad’s picture

Nice work Stefanos, the tests pass except an unrelated strict warning

joseph.olstad’s picture

Nice, the tests are requeued after the unrelated issue was fixed.

expecting a pass.

joseph.olstad’s picture

Ok, so the tests without the fix and with the fix prove that the fix is needed and is working.

+    // Check that the body is displayed when the active language is English.
+    $this->drupalGet('node/' . $node->nid);
+    $this->assertRaw($node_body, t('Body field displayed correctly in the source language.'));
+
+    // Check that the translated body is displayed when the active language is Spanish.
+    $this->drupalGet('es/node/' . $node->nid);
+    $this->assertRaw($node_translation_body, t('Body field displayed correctly in the target language.'));

without the fix, this will fail

WITH the fix, it passes.

joseph.olstad’s picture

Status: Needs work » Reviewed & tested by the community

RTBC this one:
https://www.drupal.org/files/issues/entity_translation-upgrade_fix_with_...
upgrade fix with tests.

Thanks Stefanos for awesome tests!

joseph.olstad’s picture

71 passes

stefanos.petrakis@gmail.com’s picture

Status: Reviewed & tested by the community » Fixed

Committed!

joseph.olstad’s picture

Thanks very much!

joseph.olstad’s picture

btw, I created a freebie patch for you based on the d.o code sniffer results from one of my failed patches (above).

see the patch here:
#2900094: Run a coder review on the ET codebase

joseph.olstad’s picture

Credit should also go to dsutter and gdaw, dsutter for finding the needle in the haystack, and gdaw for his thorough quality assurance.

Thanks everyone!

Status: Fixed » Closed (fixed)

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