summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2012-08-26 21:46:48 (GMT)
committerwebchick2012-08-26 21:46:48 (GMT)
commitd5702e7bfcf77225ca66b42a730755c0bb830cc4 (patch)
tree3c7581e87cfc1e42d6060fac14ca8465c4dfbbbb
parent4a677afc98db977d546d54017b0bee71ffd6e226 (diff)
Issue #1688144 by Sweetchuck, lazysoundsystem: Fixed tnid does not updated to zero after node delete.
-rw-r--r--core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php56
-rw-r--r--core/modules/translation/translation.module6
2 files changed, 58 insertions, 4 deletions
diff --git a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
index a409150..cab26ee 100644
--- a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
+++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
@@ -250,6 +250,55 @@ class TranslationTest extends WebTestBase {
}
/**
+ * Delete a basic page with a translation.
+ */
+ function testMultilanguageContentDelete() {
+ // Add Italian to have three items in the translation set.
+ $this->drupalLogin($this->admin_user);
+ $this->addLanguage('it');
+ $this->resetCaches();
+ $this->drupalLogin($this->translator);
+
+ // Create Basic page in English.
+ $node_title = $this->randomName();
+ $node_body = $this->randomName();
+ $nodes = array('en' => $this->createPage($node_title, $node_body, 'en'));
+
+ // Add Spanish translation.
+ $nodes['es'] = $this->createTranslation($nodes['en'], $this->randomName(), $this->randomName(), 'es');
+ // Reload the English node to get the updated tnid.
+ $nodes['en'] = node_load($nodes['en']->nid, NULL, TRUE);
+
+ // Add Italian translation.
+ // Use Spanish translation as source, rather than the original English one
+ // to check correct tnid handling in createTranslation().
+ $nodes['it'] = $this->createTranslation($nodes['es'], $this->randomName(), $this->randomName(), 'it');
+
+ // Delete the original translation source.
+ node_delete($nodes['en']->nid);
+
+ // Reload the remaining nodes.
+ $nodes['es'] = node_load($nodes['es']->nid, NULL, TRUE);
+ $nodes['it'] = node_load($nodes['it']->nid, NULL, TRUE);
+
+ // The new tnid is selected by the state of {node}.translate.
+ // As the original source node has been deleted, the new tnid could be
+ // generated from either remaining node.
+ $this->assertNotEqual($nodes['es']->tnid, 0, 'ES still in translation set.');
+ $this->assertNotEqual($nodes['it']->tnid, 0, 'IT still in translation set.');
+ $this->assertEqual($nodes['es']->tnid, $nodes['it']->tnid, 'ES and IT still in same translation set.');
+
+ // Delete the spanish node.
+ node_delete($nodes['es']->nid);
+
+ // Reload the italian node. This is the last one.
+ $nodes['it'] = node_load($nodes['it']->nid, NULL, TRUE);
+
+ // The tnid must be zero.
+ $this->assertEqual($nodes['it']->tnid, 0, 'Translation set is terminated.');
+ }
+
+ /**
* Resets static caches to make the test code match the client-side behavior.
*/
function resetCaches() {
@@ -298,7 +347,7 @@ class TranslationTest extends WebTestBase {
}
else {
// It's installed. No need to do anything.
- $this->assertTrue(true, 'Language [' . $language_code . '] already installed.');
+ $this->assertTrue(TRUE, 'Language [' . $language_code . '] already installed.');
}
}
@@ -364,8 +413,11 @@ class TranslationTest extends WebTestBase {
// Check to make sure that translation was successful.
$translation = $this->drupalGetNodeByTitle($title);
+ // Maybe the source node was not in translation set,
+ // or it is not the base node of the translation set.
+ $tnid = (empty($node->tnid) ? $node->nid : $node->tnid);
$this->assertTrue($translation, t('Node found in database.'));
- $this->assertTrue($translation->tnid == $node->nid, t('Translation set id correctly stored.'));
+ $this->assertTrue($translation->tnid == $tnid, 'Translation set id correctly stored.');
return $translation;
}
diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module
index 909117f..880d30d 100644
--- a/core/modules/translation/translation.module
+++ b/core/modules/translation/translation.module
@@ -413,8 +413,10 @@ function translation_remove_from_set($node) {
'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.
+ if (db_query('SELECT COUNT(nid) FROM {node} WHERE nid <> :nid AND tnid = :tnid', array(':nid' => $node->nid, ':tnid' => $node->tnid))->fetchField() == 1) {
+ // Apart from the node being deleted, only one node remains in the set:
+ // remove the set altogether
+
$query
->condition('tnid', $node->tnid)
->execute();