Skip to content
Snippets Groups Projects
Commit 34cd3174 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #394584 by Berdir: converted translation module to the new database abstraction layer.

parent cb3cde8b
No related branches found
No related tags found
No related merge requests found
......@@ -234,9 +234,21 @@ function translation_node_insert($node) {
else {
// Create new translation set, using nid from the source node.
$tnid = $node->translation_source->nid;
db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->translation_source->nid);
db_update('node')
->fields(array(
'tnid' => $tnid,
'translate' => 0,
))
->condition('nid', $node->translation_source->nid)
->execute();
}
db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $tnid, 0, $node->nid);
db_update('node')
->fields(array(
'tnid' => $tnid,
'translate' => 0,
))
->condition('nid', $node->nid)
->execute();
}
}
}
......@@ -249,10 +261,20 @@ function translation_node_update($node) {
if (translation_supported_type($node->type)) {
if (isset($node->translation) && $node->translation && !empty($node->language) && $node->tnid) {
// Update translation information.
db_query("UPDATE {node} SET tnid = %d, translate = %d WHERE nid = %d", $node->tnid, $node->translation['status'], $node->nid);
db_update('node')
->fields(array(
'tnid' => $node->tnid,
'translate' => $node->translation['status'],
))
->condition('nid', $node->nid)
->execute();
if (!empty($node->translation['retranslate'])) {
// This is the source node, asking to mark all translations outdated.
db_query("UPDATE {node} SET translate = 1 WHERE tnid = %d AND nid <> %d", $node->tnid, $node->nid);
db_update('node')
->fields(array('translate' => 1))
->condition('nid', $node->nid, '<>')
->condition('tnid', $node->tnid)
->execute();
}
}
}
......@@ -290,18 +312,30 @@ function translation_node_delete($node) {
*/
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) {
$query = db_update('node')
->fields(array(
'tnid' => 0,
'translate' => 0,
));
if (db_query('SELECT COUNT(*) FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField() == 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);
$query
->condition('tnid', $node->tnid)
->execute();
}
else {
db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE nid = %d', $node->nid);
$query
->condition('nid', $node->nid)
->execute();
// 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);
$new_tnid = db_query('SELECT nid FROM {node} WHERE tnid = :tnid ORDER BY translate ASC, nid ASC', array(':tnid' => $node->tnid))->fetchField();
db_update('node')
->fields(array('tnid' => $new_tnid))
->condition('tnid', $node->tnid)
->execute();
}
}
}
......@@ -326,8 +360,13 @@ function translation_node_get_translations($tnid) {
if (is_numeric($tnid) && $tnid) {
if (!isset($translations[$tnid])) {
$translations[$tnid] = array();
$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, n.language FROM {node} n WHERE n.tnid = %d'), $tnid);
while ($node = db_fetch_object($result)) {
$result = db_select('node', 'n')
->fields('n', array('nid', 'title', 'language'))
->condition('n.tnid', $tnid)
->addTag('node_access')
->execute();
foreach ($result as $node) {
$translations[$tnid][$node->language] = $node;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment