Skip to content
Snippets Groups Projects
Commit 23c31ac7 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1164852 follow-up by plach, chx, Boobaa, sun: Fixed critical...

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.
parent cf9c0729
No related branches found
No related tags found
No related merge requests found
......@@ -178,6 +178,14 @@ 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 broken. To be able to
// properly handle this difference in node_update_7012 we need to keep track
// of whether a D6 > D7 upgrade or a D7 > D7 update is running.
// Since variable_set() is not available here, the D6 status is being saved
// in a local variable to be able to store it later.
$update_d6 = TRUE;
}
// Create the registry tables.
......@@ -302,6 +310,11 @@ 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 running.
if (!empty($update_d6)) {
variable_set('update_d6', TRUE);
}
}
/**
......@@ -1081,6 +1094,10 @@ function update_batch($start, $redirect = NULL, $url = NULL, $batch = array(), $
* @see update_batch()
*/
function update_finished($success, $results, $operations) {
// Remove the D6 upgrade flag variable so that subsequent update runs do not
// get the wrong context.
variable_del('update_d6');
// Clear the caches in case the data has been updated.
drupal_flush_all_caches();
......
......@@ -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);
......@@ -866,6 +867,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. 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"
*/
......@@ -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
<?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();
......@@ -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.'));
}
}
<?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');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment