You are here

function translation_remove_from_set in Drupal 6

Same name and namespace in other branches
  1. 7 modules/translation/translation.module \translation_remove_from_set()

Remove a node from its translation set (if any) and update the set accordingly.

1 call to translation_remove_from_set()
translation_nodeapi in modules/translation/translation.module
Implementation of hook_nodeapi().

File

modules/translation/translation.module, line 254
Manages content translations.

Code

function translation_remove_from_set($node) {
  if (isset($node->tnid)) {
    if (db_result(db_query('SELECT COUNT(*) FROM {node} WHERE tnid = %d', $node->tnid)) == 1) {

      // There is only one node left in the set: remove the set altogether.
      db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE tnid = %d', $node->tnid);
    }
    else {
      db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE nid = %d', $node->nid);

      // If the node being removed was the source of the translation set,
      // we pick a new source - preferably one that is up to date.
      if ($node->tnid == $node->nid) {
        $new_tnid = db_result(db_query('SELECT nid FROM {node} WHERE tnid = %d ORDER BY translate ASC, nid ASC', $node->tnid));
        db_query('UPDATE {node} SET tnid = %d WHERE tnid = %d', $new_tnid, $node->tnid);
      }
    }
  }
}