summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-04-17 06:55:07 +0000
committerDries Buytaert <dries@buytaert.net>2009-04-17 06:55:07 +0000
commit34cd317476b9b8e5ebc43d845702b1feaa576afd (patch)
tree1e012a513274d1fea84938cbb078e6ffaecdbb78 /modules
parentcb3cde8be11bd1d54bdbb323b72919072f2cb930 (diff)
downloadbrdo-34cd317476b9b8e5ebc43d845702b1feaa576afd.tar.gz
brdo-34cd317476b9b8e5ebc43d845702b1feaa576afd.tar.bz2
- Patch #394584 by Berdir: converted translation module to the new database abstraction layer.
Diffstat (limited to 'modules')
-rw-r--r--modules/translation/translation.module61
1 files changed, 50 insertions, 11 deletions
diff --git a/modules/translation/translation.module b/modules/translation/translation.module
index 9f3f0c569..2b4ab19ef 100644
--- a/modules/translation/translation.module
+++ b/modules/translation/translation.module
@@ -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;
}
}