diff --git a/includes/update.inc b/includes/update.inc index 1eb7a1d..20df9f8 100644 --- a/includes/update.inc +++ b/includes/update.inc @@ -178,6 +178,16 @@ function update_prepare_d7_bootstrap() { $_COOKIE[session_name()] = $sid; session_id($sid); } + + // Upgrading from D6 to D7.{0,1,2,3,4,8,...} is different than upgrading + // from D6 to D7.{5,6,7} (which should be considered screwed). To be able + // to properly handle this difference in node_update_701{2,3} we should + // variable_set() something (node_update_7012() may run in another + // invocation of a batch set than we are having here). We do not have + // proper Drupal variable handling here (which is a must for + // variable_set()), so setting only this PHP variable here, and do the + // variable_set() if and when we are ready to do so. + $node_updates_from_d6 = TRUE; } // Create the registry tables. @@ -302,6 +312,9 @@ function update_prepare_d7_bootstrap() { // Set the timezone for this request only. $GLOBALS['conf']['date_default_timezone'] = 'UTC'; } + + // This allows update functions to tell if an upgrade from D6 is being run. + variable_set('node_updates_from_d6', isset($node_updates_from_d6) ? $node_updates_from_d6 : FALSE); } /** diff --git a/modules/node/node.install b/modules/node/node.install index d33f095..d69ba58 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,38 @@ 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). Do nothing if we are upgrading from sites that started + // their life as 7.x ones, though: it is a valid use case to have translatable + // body fields in D7 sites. + if (variable_get('node_updates_from_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. The same operation during a D7 + // update would be 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 f51804c..6b5f34d 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 0000000..5162116 --- /dev/null +++ b/modules/simpletest/tests/upgrade/drupal-6.translatable.database.php @@ -0,0 +1,125 @@ +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 translatable page 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.translatable.test b/modules/simpletest/tests/upgrade/upgrade.translatable.test new file mode 100644 index 0000000..d31a0af --- /dev/null +++ b/modules/simpletest/tests/upgrade/upgrade.translatable.test @@ -0,0 +1,51 @@ + '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'); + } +}