diff --git a/modules/field/field.install b/modules/field/field.install index d56eb90..8e48155 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -435,5 +435,51 @@ function field_update_7001() { } /** + * Disable 'translatable' flag for all fields that do not contain language-specific field values. + */ +function field_update_7002() { + $fields = _update_7000_field_read_fields(array( + // Only currently enabled fields are affected. + 'translatable' => 1, + // Field storage engines depend on the module and hook system; we can only + // query and update fields in SQL. Alternative field storage engines have to + // implement a corresponding module update on their own. + 'storage_type' => 'field_sql_storage', + // Field configuration and values of deleted fields are irrelevant. + 'deleted' => 0, + )); + $changed_fields = array(); + foreach ($fields as $field) { + $tables = array("field_data_{$field['field_name']}", "field_revision_{$field['field_name']}"); + $has_language = FALSE; + foreach ($tables as $table) { + // 'und' denotes LANGUAGE_NONE; constant values may change over time. + $query = db_select($table)->condition('language', 'und', '<>')->range(0, 1); + $query->addExpression(1); + $has_language = $has_language || $query->execute()->fetchField(); + } + // Only in case there is no language-specific field value, update the + // field's configuration to mark it untranslatable. + // Note: There is a small chance of disabling the translatable flag for + // fields that actually have a field translation handler associated (but + // e.g., no values yet). However, since the field translation handler + // entirely depends on module hooks, it is impossible to gather this + // information in a module update. + if (!$has_language) { + $changed_fields[] = $field['field_name']; + db_update('field_config') + ->condition('id', $field['id']) + ->fields(array('translatable' => 0)) + ->execute(); + } + } + if ($changed_fields) { + drupal_set_message(t('The following fields have been changed to be no longer translatable: %field-list.', array( + '%field-list' => implode(', ', $changed_fields), + ))); + } +} + +/** * @} End of "addtogroup updates-6.x-to-7.x" */ diff --git a/modules/node/node.install b/modules/node/node.install index 2498091..46771f1 100644 --- a/modules/node/node.install +++ b/modules/node/node.install @@ -708,9 +708,12 @@ function node_update_7006(&$sandbox) { 'type' => $revision->type, ); // After node_update_7009() we will always have LANGUAGE_NONE as - // language neutral language code, but here we still have empty - // strings. - $langcode = empty($revision->language) ? LANGUAGE_NONE : $revision->language; + // language neutral language code, but here we still don't have + // those, so let's stick with LANGUAGE_NONE here: Drupal 6 has + // translation support only for content types, not for fields, so + // any and all fields upgraded from Drupal 6 should NOT be + // language-aware, including body. + $langcode = LANGUAGE_NONE; if (!empty($revision->teaser) && $revision->teaser != text_summary($revision->body)) { $node->body[$langcode][0]['summary'] = $revision->teaser; } 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..cb66e78 --- /dev/null +++ b/modules/simpletest/tests/upgrade/upgrade.translatable.test @@ -0,0 +1,51 @@ + 'Translatable 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 translatable (English) node + // "First translatable page" with nid 53. + $nid = 53; + $title = 'First translatable page'; + $teaser = 'Teaser of the first translatable page.'; + + // Check whether the node displays properly. + $this->drupalGet("node/$nid"); + $this->assertText($body = 'Body of the first translatable page.', 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->verbose('Upgraded node: ' . var_export($node, TRUE)); + $this->assertEqual($node->body[LANGUAGE_NONE][0]['value'], $body, 'Body of the node survided upgrade properly'); + $this->assertEqual($node->body[LANGUAGE_NONE][0]['summary'], $teaser, 'Teaser of the node survided upgrade properly'); + } +}