function i18nsync_node_taxonomy in Internationalization 5
Same name and namespace in other branches
- 5.3 experimental/i18nsync.module \i18nsync_node_taxonomy()
- 5.2 experimental/i18nsync.module \i18nsync_node_taxonomy()
- 6 i18nsync/i18nsync.module \i18nsync_node_taxonomy()
Actual synchronization for node, vocabulary
These are the 'magic' db queries.
1 call to i18nsync_node_taxonomy()
- i18nsync_nodeapi in experimental/
i18nsync.module - Implementation of hook_nodeapi().
File
- experimental/
i18nsync.module, line 196 - Internationalization (i18n) package. Synchronization of translations
Code
function i18nsync_node_taxonomy($node, $vocabulary) {
// Paranoid extra check. This queries may really delete data
if ($vocabulary->language || !$node->nid || !$node->trid || !$node->language || !$vocabulary->vid) {
return;
}
// Reset all terms for this vocabulary for other nodes in the translation set
// First delete all terms without language
db_query("DELETE FROM {term_node} WHERE nid != %d " . " AND nid IN (SELECT nid FROM {i18n_node} WHERE trid = %d) " . " AND tid IN (SELECT tid FROM {term_data} WHERE (language = '' OR language IS NULL) AND vid = %d) ", $node->nid, $node->trid, $vocabulary->vid);
// Now delete all terms which have a translation in the node language
// We don't touch the terms that have language but no translation
db_query("DELETE FROM {term_node} WHERE nid != %d " . " AND nid IN (SELECT nid FROM {i18n_node} WHERE trid = %d) " . " AND tid IN (SELECT td.tid FROM {term_data} td INNER JOIN {term_data} tt ON td.trid = tt.trid " . " WHERE td.vid = %d AND td.trid AND tt.language = '%s') ", $node->nid, $node->trid, $vocabulary->vid, $node->language);
// Copy terms with no language
db_query("INSERT INTO {term_node}(tid, nid) SELECT tn.tid, n.nid " . " FROM {i18n_node} n , {term_node} tn " . " INNER JOIN {term_data} td ON tn.tid = td.tid " . " WHERE tn.nid = %d AND n.nid != %d AND n.trid = %d AND td.vid = %d " . " AND td.language = '' OR td.language IS NULL", $node->nid, $node->nid, $node->trid, $vocabulary->vid);
// Now copy terms translating on the fly
db_query("INSERT INTO {term_node}(tid, nid) SELECT tdt.tid, n.nid " . " FROM {i18n_node} n , {term_data} tdt " . " INNER JOIN {term_data} td ON tdt.trid = td.trid " . " INNER JOIN {term_node} tn ON tn.tid = td.tid " . " WHERE tdt.trid AND tdt.language = n.language " . " AND n.nid != %d AND tn.nid = %d AND n.trid = %d AND td.vid = %d", $node->nid, $node->nid, $node->trid, $vocabulary->vid);
}