Index: modules/simpletest/tests/translation_test.info =================================================================== RCS file: modules/simpletest/tests/translation_test.info diff -N modules/simpletest/tests/translation_test.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/simpletest/tests/translation_test.info 21 Jan 2009 00:11:15 -0000 @@ -0,0 +1,9 @@ +; $Id$ +name = "Translation test" +description = "Support module for Translation testing." +package = Testing +version = VERSION +core = 7.x +files[] = translation_test.module +dependencies[] = translation +hidden = TRUE Index: modules/simpletest/tests/translation_test.module =================================================================== RCS file: modules/simpletest/tests/translation_test.module diff -N modules/simpletest/tests/translation_test.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/simpletest/tests/translation_test.module 21 Jan 2009 00:11:15 -0000 @@ -0,0 +1,9 @@ +nid); +} Index: modules/translation/translation.api.php =================================================================== RCS file: modules/translation/translation.api.php diff -N modules/translation/translation.api.php --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/translation/translation.api.php 21 Jan 2009 00:11:15 -0000 @@ -0,0 +1,17 @@ +/** + * Respond to changes in a node's translation set. + * + * The node object is extended with a 'translation_change' array containing + * both the old and new tnid. + * + * @param $node + * The node being acted upon. + */ +function hook_nodeapi_translation_change($node) { + $update = db_update('my_table') + ->fields(array( + 'tnid' => $node->translation_change['new_tnid'], + )) + ->condition('tnid', $node->tnid, '=') + ->execute(); +} Index: modules/translation/translation.module =================================================================== RCS file: /cvs/drupal/drupal/modules/translation/translation.module,v retrieving revision 1.37 diff -u -p -r1.37 translation.module --- modules/translation/translation.module 16 Dec 2008 22:05:51 -0000 1.37 +++ modules/translation/translation.module 21 Jan 2009 00:11:15 -0000 @@ -262,16 +262,47 @@ function translation_remove_from_set($no if (isset($node->tnid)) { if (db_result(db_query('SELECT COUNT(*) FROM {node} WHERE tnid = %d', $node->tnid)) == 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); + $node->translation_change = array( + 'old_tnid' => $node->tnid, + 'new_tnid' => 0, + // Determine the remaining former member of the translation set. + // May be needed e.g. to reassign existing data from the tnid to this nid. + 'remaining_nid' => db_query('SELECT nid FROM {node} WHERE tnid = :tnid', array(':tnid' => $node->tnid))->fetchField(), + ); + db_update('node') + ->fields(array( + 'tnid' => 0, + 'translate' => 0, + )) + ->condition('tnid', $node->tnid, '=') + ->execute(); + // Allow other modules to respond to the removal of this translation set. + node_invoke_nodeapi($node, 'translation_change'); } else { - db_query('UPDATE {node} SET tnid = 0, translate = 0 WHERE nid = %d', $node->nid); + db_update('node') + ->fields(array( + 'tnid' => 0, + 'translate' => 0, + )) + ->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); + $node->translation_change = array( + 'old_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' => $node->translation_change['new_tnid'], + )) + ->condition('tnid', $node->tnid, '=') + ->execute(); + // Allow other modules to respond to the changed source for this translation set. + node_invoke_nodeapi($node, 'translation_change'); } } } Index: modules/translation/translation.test =================================================================== RCS file: /cvs/drupal/drupal/modules/translation/translation.test,v retrieving revision 1.7 diff -u -p -r1.7 translation.test --- modules/translation/translation.test 30 Dec 2008 16:43:19 -0000 1.7 +++ modules/translation/translation.test 21 Jan 2009 00:11:15 -0000 @@ -1,6 +1,9 @@ drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages')); - $translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'translate content')); + $translator = $this->drupalCreateUser(array('create page content', 'edit own page content', 'delete own page content', 'translate content')); $this->drupalLogin($admin_user); @@ -67,6 +70,15 @@ class TranslationTestCase extends Drupal $edit['translation[status]'] = FALSE; $this->drupalPost('node/' . $node_translation->nid . '/edit', $edit, t('Save')); $this->assertRaw(t('Page %title has been updated.', array('%title' => $node_translation_title)), t('Translated node updated.')); + + // Delete the source node. + $this->drupalPost('node/' . $node->nid . '/edit', array(), t('Delete')); + $this->drupalPost(NULL, array(), t('Delete')); + + // Assert that hook_translation_change() was called. + $this->assertEqual(variable_get('translation_change_called', ''), $node->nid, t('hook_nodeapi_translation_change() was called.')); + + } /**