Commit 8ed9f604 authored by webchick's avatar webchick

#891028 by chx: Fixed Orphan node types lose bodies on upgrade.

parent 7cc3d92d
......@@ -512,10 +512,24 @@ function node_update_7006(&$sandbox) {
$result = db_select('node_type', 'node_type')
->fields('node_type')
->execute();
foreach ($result as $type_object) {
$node_types[$type_object->type] = $type_object;
}
$extra_types = db_query('SELECT DISTINCT type FROM {node} WHERE type NOT IN (:types)', array(':types' => array_keys($node_types)))->fetchCol();
foreach ($extra_types as $type) {
$type_object = new stdClass;
$type_object->type = $type;
// Always create a body. Querying node_revisions for a non-empty body
// would skip creating body fields for types that have a body but
// the nodes of that type so far had empty bodies.
$type_object->has_body = 1;
$type_object->body_label = 'Body';
$node_types[$type_object->type] = $type_object;
}
$default_trim_length = variable_get('teaser_length', 600);
// Add body field instances for existing node types.
foreach ($result as $node_type) {
foreach ($node_types as $node_type) {
if ($node_type->has_body) {
$instance = node_add_body_field($node_type, $node_type->body_label);
// Update newly created instance to convert teaser_length variable
......
......@@ -39,5 +39,5 @@ files[] = tests/unicode.test
files[] = tests/update.test
files[] = tests/xmlrpc.test
files[] = tests/upgrade/upgrade.test
files[] = tests/upgrade/upgrade.poll.test
files[] = tests/upgrade/upgrade.node.test
files[] = tests/upgrade/upgrade.taxonomy.test
......@@ -9788,6 +9788,23 @@
'tnid' => '0',
'translate' => '0',
))
->values(array(
'nid' => '37',
'vid' => '49',
'type' => 'broken',
'language' => '',
'title' => 'node title 24',
'uid' => '6',
'status' => '1',
'created' => '1263769200',
'changed' => '1279310614',
'comment' => '0',
'promote' => '0',
'moderate' => '0',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
))
->execute();
db_create_table('node_access', array(
......@@ -10158,6 +10175,13 @@
'last_comment_uid' => '5',
'comment_count' => '0',
))
->values(array(
'nid' => '37',
'last_comment_timestamp' => '1279310615',
'last_comment_name' => NULL,
'last_comment_uid' => '6',
'comment_count' => '0',
))
->execute();
db_create_table('node_counter', array(
......@@ -10798,6 +10822,17 @@
'timestamp' => '1282936268',
'format' => '0',
))
->values(array(
'nid' => '37',
'vid' => '49',
'uid' => '6',
'title' => 'node title 24',
'body' => 'node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37',
'teaser' => 'node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37node body (broken) - 37no',
'log' => 'added 12 node',
'timestamp' => '1279310614',
'format' => '0',
))
->execute();
db_create_table('node_type', array(
......@@ -19284,6 +19319,12 @@
'dst' => 'content/poll/11/results',
'language' => '',
))
->values(array(
'pid' => '49',
'src' => 'node/37',
'dst' => 'content/1263769200',
'language' => '',
))
->execute();
db_create_table('users', array(
......
<?php
// $Id$
/**
* Upgrade test for node bodies.
*
* Load a filled installation of Drupal 6 and run the upgrade process on it.
*/
class NodeBodyUpgradePathTestCase extends UpgradePathTestCase {
public static function getInfo() {
return array(
'name' => 'Node body upgrade path',
'description' => 'Node body upgrade path tests.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump.
$this->databaseDumpFile = drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php';
parent::setUp();
}
/**
* Test a successful upgrade.
*/
public function testNodyBodyUpgrade() {
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
$this->drupalGet("content/1263769200");
$this->assertText('node body (broken) - 37');
}
}
/**
* Upgrade test for node type poll.
*
* Load a bare installation of Drupal 6 and run the upgrade process on it.
*
* The install only contains dblog (although it's optional, it's only so that
* another hook_watchdog module can take its place, the site is not functional
* without watchdog) and update.
*/
class PollUpgradePathTestCase extends UpgradePathTestCase {
public static function getInfo() {
return array(
'name' => 'Poll upgrade path',
'description' => 'Poll upgrade path tests.',
'group' => 'Upgrade path',
);
}
public function setUp() {
// Path to the database dump.
$this->databaseDumpFile = drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php';
parent::setUp();
$this->uninstallModulesExcept(array('poll'));
}
/**
* Test a successful upgrade.
*/
public function testPollUpgrade() {
$this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.'));
// Check modules page for poll
$this->drupalGet('admin/modules');
// Verify that the poll data is still correctly available
for ($i = 0; $i < 12; $i++) {
$this->drupalGet("content/poll/$i");
$nbchoices = ($i % 4) + 2;
for ($c = 0; $c < $nbchoices; $c++) {
$this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on poll view'));
}
// Now check that the votes are correct
$this->clickLink(t('Results'));
for ($c = 0; $c < $nbchoices; $c++) {
$this->assertText("Choice $c for poll $i", t('Choice text is displayed correctly on result view'));
}
$nbvotes = floor (($i % 4) + 5);
$elements = $this->xpath("//div[@class='percent']");
for ($c = 0; $c < $nbchoices; $c++) {
$votes = floor($nbvotes / $nbchoices);
if (($nbvotes % $nbchoices) > $c) $votes++;
$this->assertTrue(preg_match("/$votes vote/", $elements[$c]), t('The number of votes is displayed correctly: expected ' . $votes . ', got ' . $elements[$c]));
}
}
}
}
......@@ -185,3 +185,23 @@
drupal_execute('poll_view_voting', $form_state, $node);
}
}
$uid = 6;
$user = user_load($uid);
$node = new stdClass;
$node->uid = $uid;
$node->type = 'broken';
$node->sticky = 0;
$node->title = "node title 24";
$node->body = str_repeat("node body ($node->type) - 37", 100);
$node->teaser = node_teaser($node->body);
$node->filter = variable_get('filter_default_format', 1);
$node->format = FILTER_FORMAT_DEFAULT;
$node->status = 1;
$node->language = '';
$node->revision = 0;
$node->promote = 0;
$node->created = 1263769200;
$node->log = "added $i node";
node_save($node);
path_set_alias("node/$node->nid", "content/1263769200");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment