diff options
author | webchick <webchick@24967.no-reply.drupal.org> | 2011-08-23 23:39:37 +0100 |
---|---|---|
committer | webchick <webchick@24967.no-reply.drupal.org> | 2011-08-23 23:39:37 +0100 |
commit | 23c31ac7141f3d8be913705ae269b22187623d98 (patch) | |
tree | 4d465518e085aae12c938c3aac59395cc48526c6 /modules | |
parent | cf9c0729fa3620669c99e5675192399f32824852 (diff) | |
download | brdo-23c31ac7141f3d8be913705ae269b22187623d98.tar.gz brdo-23c31ac7141f3d8be913705ae269b22187623d98.tar.bz2 |
Issue #1164852 follow-up by plach, chx, Boobaa, sun: Fixed critical regression: Node bodies display as empty after upgrade to 7.7 from 6.x if the nodes have a language.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/node/node.install | 33 | ||||
-rw-r--r-- | modules/simpletest/simpletest.info | 1 | ||||
-rw-r--r-- | modules/simpletest/tests/upgrade/drupal-6.translatable.database.php | 125 | ||||
-rw-r--r-- | modules/simpletest/tests/upgrade/upgrade.test | 4 | ||||
-rw-r--r-- | modules/simpletest/tests/upgrade/upgrade.translatable.test | 51 |
5 files changed, 214 insertions, 0 deletions
diff --git a/modules/node/node.install b/modules/node/node.install index d33f095f0..a1f77bb0f 100644 --- a/modules/node/node.install +++ b/modules/node/node.install @@ -616,6 +616,7 @@ function node_update_7006(&$sandbox) { 'module' => 'text', 'cardinality' => 1, 'entity_types' => array('node'), + 'translatable' => TRUE, ); _update_7000_field_create_field($body_field); @@ -867,5 +868,37 @@ function node_update_7011() { } /** + * Switches body fields to untranslatable while upgrading from D6 and makes them language neutral. + */ +function node_update_7012() { + // If we are upgrading from D6, then body fields should be set back to + // untranslatable, as D6 did not know about the idea of translating fields, + // but only nodes. If a D7 > D7 update is running we need to skip this update, + // as it is a valid use case to have translatable body fields in this context. + if (variable_get('update_d6', FALSE)) { + // Make node bodies untranslatable: field_update_field() cannot be used + // throughout the upgrade process and we do not have an update counterpart + // for _update_7000_field_create_field(). Hence we are forced to update the + // 'field_config' table directly. This is a safe operation since it is + // being performed while upgrading from D6. Perfoming the same operation + // during a D7 update is highly discouraged. + db_update('field_config') + ->fields(array('translatable' => 0)) + ->condition('field_name', 'body') + ->execute(); + + // Switch field languages to LANGUAGE_NONE, since initially they were + // assigned $node->language. + foreach (array('field_data_body', 'field_revision_body') as $table) { + db_update($table) + ->fields(array('language' => LANGUAGE_NONE)) + ->execute(); + } + + node_type_cache_reset(); + } +} + +/** * @} End of "addtogroup updates-6.x-to-7.x" */ diff --git a/modules/simpletest/simpletest.info b/modules/simpletest/simpletest.info index f51804c90..6b5f34dc6 100644 --- a/modules/simpletest/simpletest.info +++ b/modules/simpletest/simpletest.info @@ -45,5 +45,6 @@ files[] = tests/upgrade/upgrade.locale.test files[] = tests/upgrade/upgrade.menu.test files[] = tests/upgrade/upgrade.node.test files[] = tests/upgrade/upgrade.taxonomy.test +files[] = tests/upgrade/upgrade.translatable.test files[] = tests/upgrade/upgrade.upload.test files[] = tests/upgrade/upgrade.user.test diff --git a/modules/simpletest/tests/upgrade/drupal-6.translatable.database.php b/modules/simpletest/tests/upgrade/drupal-6.translatable.database.php new file mode 100644 index 000000000..516211606 --- /dev/null +++ b/modules/simpletest/tests/upgrade/drupal-6.translatable.database.php @@ -0,0 +1,125 @@ +<?php + +/** + * Database additions for translatable tests. + */ + +db_insert('node')->fields(array( + 'nid', + 'vid', + 'type', + 'language', + 'title', + 'uid', + 'status', + 'created', + 'changed', + 'comment', + 'promote', + 'moderate', + 'sticky', + 'tnid', + 'translate', +)) +->values(array( + 'nid' => '53', + 'vid' => '63', + 'type' => 'translatable_page', + 'language' => 'fr', + 'title' => 'First translatable page', + 'uid' => '1', + 'status' => '1', + 'created' => '1298363952', + 'changed' => '1298363952', + 'comment' => '2', + 'promote' => '0', + 'moderate' => '0', + 'sticky' => '0', + 'tnid' => '0', + 'translate' => '0', +)) +->execute(); + +db_insert('node_revisions')->fields(array( + 'nid', + 'vid', + 'uid', + 'title', + 'body', + 'teaser', + 'log', + 'timestamp', + 'format', +)) +->values(array( + 'nid' => '53', + 'vid' => '63', + 'uid' => '1', + 'title' => 'First translatable page', + 'body' => 'Body of the first translatable page.', + 'teaser' => 'Teaser of the first translatable page.', + 'log' => '', + 'timestamp' => '1298363952', + 'format' => '1', +)) +->execute(); + +db_insert('node_comment_statistics')->fields(array( + 'nid', + 'last_comment_timestamp', + 'last_comment_name', + 'last_comment_uid', + 'comment_count', +)) +->values(array( + 'nid' => '53', + 'last_comment_timestamp' => '1298363952', + 'last_comment_name' => NULL, + 'last_comment_uid' => '1', + 'comment_count' => '0', +)) +->execute(); + +db_insert('node_type')->fields(array( + 'type', + 'name', + 'module', + 'description', + 'help', + 'has_title', + 'title_label', + 'has_body', + 'body_label', + 'min_word_count', + 'custom', + 'modified', + 'locked', + 'orig_type', +)) +->values(array( + 'type' => 'translatable_page', + 'name' => 'Translatable page', + 'module' => 'node', + 'description' => 'A <em>translatable page</em> is like a normal page, but with multilanguage support.', + 'help' => '', + 'has_title' => '1', + 'title_label' => 'Title', + 'has_body' => '1', + 'body_label' => 'Body', + 'min_word_count' => '0', + 'custom' => '0', + 'modified' => '0', + 'locked' => '1', + 'orig_type' => '', +)) +->execute(); + +db_insert('variable')->fields(array( + 'name', + 'value', +)) +->values(array( + 'name' => 'language_content_type_translatable_page', + 'value' => 's:1:"1";', +)) +->execute(); diff --git a/modules/simpletest/tests/upgrade/upgrade.test b/modules/simpletest/tests/upgrade/upgrade.test index 8a3da8188..6aadee379 100644 --- a/modules/simpletest/tests/upgrade/upgrade.test +++ b/modules/simpletest/tests/upgrade/upgrade.test @@ -402,5 +402,9 @@ class BasicUpgradePath extends UpgradePathTestCase { // Confirm that no {menu_links} entry exists for user/autocomplete. $result = db_query('SELECT COUNT(*) FROM {menu_links} WHERE link_path = :user_autocomplete', array(':user_autocomplete' => 'user/autocomplete'))->fetchField(); $this->assertFalse($result, t('No {menu_links} entry exists for user/autocomplete')); + + // Test that the environment after the upgrade is in a consistent status. + $update_d6 = variable_get('update_d6', FALSE); + $this->assertFalse($update_d6, t('The D6 upgrade flag variable has been correctly disabled.')); } } diff --git a/modules/simpletest/tests/upgrade/upgrade.translatable.test b/modules/simpletest/tests/upgrade/upgrade.translatable.test new file mode 100644 index 000000000..c9360f3b3 --- /dev/null +++ b/modules/simpletest/tests/upgrade/upgrade.translatable.test @@ -0,0 +1,51 @@ +<?php + +/** + * Upgrade test for translatable content types of node.module. + */ +class TranslatableUpgradePathTestCase extends UpgradePathTestCase { + public static function getInfo() { + return array( + 'name' => 'Translatable content upgrade path', + 'description' => 'Upgrade path tests for the translatable content types of Node module.', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + // Path to the database dump files. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php', + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.locale.database.php', + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.translatable.database.php', + ); + parent::setUp(); + + $this->uninstallModulesExcept(array('locale')); + } + + /** + * Test a successful upgrade (no negotiation). + */ + public function testTranslatableUpgrade() { + $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.')); + + // The D6 database contains the english node "First translatable page" with + // nid 53. + $nid = 53; + $title = 'First translatable page'; + $teaser = 'Teaser of the first translatable page.'; + $body = 'Body of the first translatable page.'; + + // Check whether the node displays properly. + $this->drupalGet("node/$nid"); + $this->assertText($body, t('Translatable node body displays properly')); + + // Retrieve node object, ensure that both the body and the teaser has + // survived upgrade properly. + $node = $this->drupalGetNodeByTitle($title); + $this->assertTrue($node != NULL, t('Node @title was loaded', array('@title' => $title))); + $this->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $body, 'Body of the node survived upgrade properly'); + $this->assertEqual($node->body[LANGUAGE_NONE][0]['summary'], $teaser, 'Teaser of the node survived upgrade properly'); + } +} |