function comment_entity_translation_upgrade in Entity Translation 7
Implements hook_entity_translation_upgrade().
File
- entity_translation_upgrade/
entity_translation_upgrade.admin.inc, line 229 - Converts node translations into field-based translations.
Code
function comment_entity_translation_upgrade($node, $translation) {
// Attach comments to the original node.
db_update('comment')
->fields(array(
'nid' => $node->nid,
'language' => $translation->language,
))
->condition('nid', $translation->nid)
->execute();
// Update node-comment statistics.
$ncs = db_select('node_comment_statistics', 'ncs')
->fields('ncs')
->condition('nid', array(
$node->nid,
$translation->nid,
))
->execute()
->fetchAllAssoc('nid');
$last = $ncs[$node->nid]->last_comment_timestamp > $ncs[$translation->nid]->last_comment_timestamp;
$ncs_updated = $last ? $ncs[$node->nid] : $ncs[$translation->nid];
$ncs_updated->nid = $node->nid;
$ncs_updated->comment_count = $ncs[$node->nid]->comment_count + $ncs[$translation->nid]->comment_count;
db_update('node_comment_statistics')
->fields((array) $ncs_updated)
->condition('nid', $node->nid)
->execute();
}