This is a very simple fix to keep the translation links betweend nodes (the tnid's) intact while editing revisions under content moderation. This fixes the problem of nodes losing their translation link with other nodes.

For a more general discussion about integration with i18n see http://drupal.org/node/731942

Comments

eugenmayer’s picture

Status: Needs review » Postponed (maintainer needs more info)

Do we expect any sideeffect when revisions will set live? i mean, actually tnid is in the node table, so iam not sure why it is affected by the content_moderation module at all?

So actually why do we even lose tnid at all? I need to clarify this so we can think about sideffects. If there are no, i will gladly include your patch!

weseze’s picture

Status: Postponed (maintainer needs more info) » Needs review

I can't find the reason why the tnid is lost... I can only assume it has somthing to do with copying/cloning the node. If I find some more time today, I'll look into it.

weseze’s picture

Status: Needs review » Postponed (maintainer needs more info)
weseze’s picture

Status: Postponed (maintainer needs more info) » Active

I've done some more work on this. Turns out my patch is wrong. :)

The tnid is not lost if you edit revisions that already have a tnid link. The tnid is only lost when you create new translations.

The problem starts in content_moderation_nodeapi in the insert-case. (content_moderation.module line 152) The $node object passed in here does not contain a valid tnid. Instead it contains an translation_source object. This object contains the source node.
I noticed that the function _content_moderation_create_pending_revision() is called and that function calls the node_save() function.

  // Yes we dont like non-api deep system calls. But we cant use node_save as
  // we would get into a loop.
  node_save($node);

Strange comment here, so I assume this is the cause of the problem :)

The patch to fix the bug with the tnid being lost:

  if (module_exists('i18n'))
  {
    $node->tnid = $node->translation_source->nid;
  }
  
  // Yes we dont like non-api deep system calls. But we cant use node_save as
  // we would get into a loop.
  node_save($node);

I'm not really sure how all the code in the insert-case works and what it does exactly, so this patch might not fix the real problem.
EugenMayer: Could you explain why you are saving a clone of the node?

eugenmayer’s picture

Iam investigating the code right now. Quick answers:

Could you explain why you are saving a clone of the node?:
Well when you create a moderated node-type you see a kind of "template" ( this node has no live-versions yet).
The "real" created content fo the node is in a revision. So after inserting a node we already have 2 revisions, the template one and the "real one" pending. Thats why i actually call save manually and thats where we run into problems.

weseze’s picture

Can you have a look at this patch? I changed the logic from saving a cloned node, to just saving a new revision of the exisiting node. It seems to work fine for me.

weseze’s picture

Hmm, I patched against my previous patch :)
Here's one against the official 1.2:

eugenmayer’s picture

Well sorry, i just reworte the main parts of content_moderation. That whole part of "fake live revision" is completely removed. It makes just to maybe problems and has nearly no extra use.

Now, when you create a new node, you get a warning that there is no approved one. This is even more straight then the way before, which even had a "live" version without having a live history for this at all (comparing history and the block informations).

I pretty much changed the way the nodeapi method works. I also fixed all the problems concerning tnid / path alias and so forth and some other bugs yet did not got digged out.

eugenmayer’s picture

http://github.com/EugenMayer/content_moderation/tree/rewrite

Here you can see the new code. It would be great if you could test it so we get near the final.

eugenmayer’s picture

Status: Active » Needs review
eugenmayer’s picture

Status: Needs review » Fixed
eugenmayer’s picture

Status: Fixed » Closed (fixed)

released in 1.3