Commit 4a242a80 authored by Dries's avatar Dries
Browse files

- Patch #543294 by Damien Tournoud et al: add status/promote/sticky to node_revisions table.

parent b2730e86
...@@ -225,6 +225,36 @@ function node_schema() { ...@@ -225,6 +225,36 @@ function node_schema() {
'not null' => TRUE, 'not null' => TRUE,
'default' => 0, 'default' => 0,
), ),
'status' => array(
'description' => 'Boolean indicating whether the node (at the time of this revision) is published (visible to non-administrators).',
'type' => 'int',
'not null' => TRUE,
'default' => 1,
),
'comment' => array(
'description' => 'Whether comments are allowed on this node (at the time of this revision): 0 = no, 1 = closed (read only), 2 = open (read/write).',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'promote' => array(
'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed on the front page.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'moderate' => array(
'description' => 'Previously, a boolean indicating whether the node (at the time of this revision) was "in moderation"; mostly no longer used.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'sticky' => array(
'description' => 'Boolean indicating whether the node (at the time of this revision) should be displayed at the top of lists in which it appears.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
), ),
'indexes' => array( 'indexes' => array(
'nid' => array('nid'), 'nid' => array('nid'),
...@@ -406,20 +436,29 @@ function node_update_7004() { ...@@ -406,20 +436,29 @@ function node_update_7004() {
} }
/** /**
* Convert body and teaser from node properties to fields. * Add status/comment/promote/moderate and sticky columns to the {node_revision} table.
*/ */
function node_update_7005(&$context) { function node_update_7005() {
$ret = array();
foreach(array('status', 'comment', 'promote', 'moderate', 'sticky') as $column) {
db_add_field($ret, 'node_revision', $column, array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
}
return $ret;
}
/**
* Convert body and teaser from node properties to fields, and migrate status/comment/promote/moderate and sticky columns to the {node_revision} table.
*/
function node_update_7006(&$context) {
$ret = array('#finished' => 0); $ret = array('#finished' => 0);
// Get node type info for every invocation. // Get node type info for every invocation.
node_type_clear(); node_type_clear();
$node_types = node_type_get_types(); $node_types = node_type_get_types();
$body_types = array();
foreach ($node_types as $type => $info) {
if ($info->has_body) {
$body_types[] = $type;
}
}
if (!isset($context['total'])) { if (!isset($context['total'])) {
// Initial invocation. // Initial invocation.
...@@ -437,7 +476,6 @@ function node_update_7005(&$context) { ...@@ -437,7 +476,6 @@ function node_update_7005(&$context) {
$query = db_select('node', 'n'); $query = db_select('node', 'n');
$query->join('node_revision', 'nr', 'n.vid = nr.vid'); $query->join('node_revision', 'nr', 'n.vid = nr.vid');
$query->condition('n.type', $body_types, 'IN');
$context['total'] = $query->countQuery()->execute()->fetchField(); $context['total'] = $query->countQuery()->execute()->fetchField();
} }
else { else {
...@@ -450,10 +488,9 @@ function node_update_7005(&$context) { ...@@ -450,10 +488,9 @@ function node_update_7005(&$context) {
$query = db_select('node', 'n'); $query = db_select('node', 'n');
$nr = $query->innerJoin('node_revision', 'nr', 'n.vid = nr.vid'); $nr = $query->innerJoin('node_revision', 'nr', 'n.vid = nr.vid');
$revisions = $query $revisions = $query
->fields('n', array('type')) ->fields('n', array('type', 'status', 'comment', 'promote', 'moderate', 'sticky'))
->fields($nr) ->fields($nr)
->condition('nr.vid', $context['last'], '>') ->condition('nr.vid', $context['last'], '>')
->condition('n.type', $body_types, 'IN')
->orderBy('nr.vid', 'ASC') ->orderBy('nr.vid', 'ASC')
->execute(); ->execute();
...@@ -488,6 +525,19 @@ function node_update_7005(&$context) { ...@@ -488,6 +525,19 @@ function node_update_7005(&$context) {
field_sql_storage_field_storage_write('node', $node, FIELD_STORAGE_INSERT, array()); field_sql_storage_field_storage_write('node', $node, FIELD_STORAGE_INSERT, array());
} }
// Migrate the status columns to the {node_revision} table.
db_update('node_revision')
->fields(array(
'vid' => $revision->vid,
'status' => $revision->status,
'comment' => $revision->comment,
'promote' => $revision->promote,
'moderate' => $revision->moderate,
'sticky' => $revision->sticky,
))
->condition('vid', $revision->vid)
->execute();
$context['last'] = $revision->vid; $context['last'] = $revision->vid;
$context['count'] += 1; $context['count'] += 1;
...@@ -519,14 +569,12 @@ function node_update_7005(&$context) { ...@@ -519,14 +569,12 @@ function node_update_7005(&$context) {
/** /**
* Remove column min_word_count. * Remove column min_word_count.
*/ */
function node_update_7006() { function node_update_7007() {
$ret = array(); $ret = array();
db_drop_field($ret, 'node_type', 'min_word_count'); db_drop_field($ret, 'node_type', 'min_word_count');
return $ret; return $ret;
} }
/** /**
* @} End of "defgroup updates-6.x-to-7.x" * @} End of "defgroup updates-6.x-to-7.x"
* The next series of updates should start at 8000. * The next series of updates should start at 8000.
......
...@@ -750,9 +750,11 @@ function node_load_multiple($nids = array(), $conditions = array(), $reset = FAL ...@@ -750,9 +750,11 @@ function node_load_multiple($nids = array(), $conditions = array(), $reset = FAL
// Add fields from the {node} table. // Add fields from the {node} table.
$node_fields = drupal_schema_fields_sql('node'); $node_fields = drupal_schema_fields_sql('node');
// vid and title are provided by node_revision, so remove them. // The columns vid, title, status, comment, promote, moderate, and sticky
unset($node_fields['vid']); // are all provided by node_revision, so remove them.
unset($node_fields['title']); foreach (array('vid', 'title', 'status', 'comment', 'promote', 'moderate', 'sticky') as $column) {
unset($node_fields[$column]);
}
$query->fields('n', $node_fields); $query->fields('n', $node_fields);
// Add all fields from the {node_revision} table. // Add all fields from the {node_revision} table.
......
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