Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal-3174996
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
drupal-3174996
Commits
34cd3174
Commit
34cd3174
authored
15 years ago
by
Dries Buytaert
Browse files
Options
Downloads
Patches
Plain Diff
- Patch
#394584
by Berdir: converted translation module to the new database abstraction layer.
parent
cb3cde8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/translation/translation.module
+50
-11
50 additions, 11 deletions
modules/translation/translation.module
with
50 additions
and
11 deletions
modules/translation/translation.module
+
50
−
11
View file @
34cd3174
...
...
@@ -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
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment