Commit c72f39ad authored by catch's avatar catch

Issue #2057401 by plach, socketwench, kfritsche: Fixed Make the node entity...

Issue #2057401 by plach, socketwench, kfritsche: Fixed Make the node entity database schema sensible.
parent f4c5be06
......@@ -525,6 +525,8 @@ function drupal_write_record($table, &$record, $primary_keys = array()) {
* The converted value.
*/
function drupal_schema_get_field_value(array $info, $value) {
// Preserve legal NULL values.
if (isset($value) || !empty($info['not null'])) {
if ($info['type'] == 'int' || $info['type'] == 'serial') {
$value = (int) $value;
}
......@@ -534,6 +536,7 @@ function drupal_schema_get_field_value(array $info, $value) {
else {
$value = (string) $value;
}
}
return $value;
}
......
......@@ -318,7 +318,7 @@ protected function buildQuery($ids, $revision_id = FALSE) {
if ($this->revisionKey) {
// Add all fields from the {entity_revision} table.
$entity_revision_fields = drupal_map_assoc(drupal_schema_fields_sql($this->entityInfo['revision_table']));
// The id field is provided by entity, so remove it.
// The ID field is provided by entity, so remove it.
unset($entity_revision_fields[$this->idKey]);
// Remove all fields from the base table that are also fields by the same
......@@ -331,7 +331,7 @@ protected function buildQuery($ids, $revision_id = FALSE) {
}
$query->fields('revision', $entity_revision_fields);
// Compare revision id of the base and revision table, if equal then this
// Compare revision ID of the base and revision table, if equal then this
// is the default revision.
$query->addExpression('base.' . $this->revisionKey . ' = revision.' . $this->revisionKey, 'isDefaultRevision');
}
......
......@@ -76,6 +76,7 @@ public function testAggregatorItemView() {
// Add a image to ensure that the sanitizing can be tested below.
$values['author'] = $this->randomName() . '<img src="http://example.com/example.png" \>"';
$values['link'] = 'http://drupal.org/node/' . mt_rand(1000, 10000);
$values['guid'] = $this->randomString();
$aggregator_item = $this->itemStorageController->create($values);
$aggregator_item->save();
......
......@@ -31,7 +31,7 @@ public static function getInfo() {
function setUp() {
parent::setUp();
$this->installSchema('node', array('node', 'node_access', 'node_field_data', 'node_field_revision'));
$this->installSchema('node', array('node', 'node_access', 'node_field_data', 'node_field_revision', 'node_revision'));
$this->installSchema('file', array('file_managed', 'file_usage'));
// Add text formats.
......
......@@ -71,7 +71,7 @@ function testViewsData() {
$this->assertTrue(isset($data[$revision_table]));
// The node field should join against node.
$this->assertTrue(isset($data[$current_table]['table']['join']['node']));
$this->assertTrue(isset($data[$revision_table]['table']['join']['node_field_revision']));
$this->assertTrue(isset($data[$revision_table]['table']['join']['node_revision']));
$expected_join = array(
'left_field' => 'nid',
......@@ -88,7 +88,7 @@ function testViewsData() {
array('field' => 'deleted', 'value' => 0, 'numeric' => TRUE),
),
);
$this->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_field_revision']);
$this->assertEqual($expected_join, $data[$revision_table]['table']['join']['node_revision']);
}
}
......@@ -422,7 +422,7 @@ display:
provider: views
langcode:
id: langcode
table: node
table: node_revision
field: langcode
operator: in
value: { }
......
......@@ -34,7 +34,8 @@
* },
* base_table = "node",
* data_table = "node_field_data",
* revision_table = "node_field_revision",
* revision_table = "node_revision",
* revision_data_table = "node_field_revision",
* uri_callback = "node_uri",
* fieldable = TRUE,
* translatable = TRUE,
......@@ -396,11 +397,6 @@ public static function baseFieldDefinitions($entity_type) {
'description' => t('A boolean indicating whether the node should be displayed at the top of lists in which it appears.'),
'type' => 'boolean_field',
);
$properties['translate'] = array(
'label' => t('Translate'),
'description' => t('A boolean indicating whether this translation page needs to be updated.'),
'type' => 'boolean_field',
);
$properties['revision_timestamp'] = array(
'label' => t('Revision timestamp'),
'description' => t('The time that the current revision was created.'),
......
......@@ -21,7 +21,7 @@ class UidRevision extends Uid {
public function query($group_by = FALSE) {
$this->ensureMyTable();
$placeholder = $this->placeholder();
$this->query->addWhereExpression(0, "$this->tableAlias.revision_uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_field_revision} nfr WHERE nfr.revision_uid = $placeholder AND nfr.nid = $this->tableAlias.nid) > 0)", array($placeholder => $this->argument));
$this->query->addWhereExpression(0, "$this->tableAlias.revision_uid = $placeholder OR ((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nfr.revision_uid = $placeholder AND nr.nid = $this->tableAlias.nid) > 0)", array($placeholder => $this->argument));
}
}
......@@ -57,7 +57,7 @@ public static function create(ContainerInterface $container, array $configuratio
public function titleQuery() {
$titles = array();
$results = $this->database->query('SELECT npr.vid, npr.nid, npr.title FROM {node_field_revision} npr WHERE npr.vid IN (:vids)', array(':vids' => $this->value))->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
$results = $this->database->query('SELECT nr.vid, nr.nid, npr.title FROM {node_revision} nr WHERE nr.vid IN (:vids)', array(':vids' => $this->value))->fetchAllAssoc('vid', PDO::FETCH_ASSOC);
$nids = array();
foreach ($results as $result) {
$nids[] = $result['nid'];
......
......@@ -28,7 +28,7 @@ class RevisionLink extends Link {
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->additional_fields['node_vid'] = array('table' => 'node_field_revision', 'field' => 'vid');
$this->additional_fields['node_vid'] = array('table' => 'node_revision', 'field' => 'vid');
}
public function access() {
......
......@@ -27,7 +27,7 @@ public function query($group_by = FALSE) {
$args = array_values($this->value);
$this->query->addWhereExpression($this->options['group'], "$this->tableAlias.uid IN($placeholder) OR
((SELECT COUNT(DISTINCT vid) FROM {node_field_revision} nfr WHERE nfr.revision_uid IN ($placeholder) AND nfr.nid = $this->tableAlias.nid) > 0)", array($placeholder => $args),
((SELECT COUNT(DISTINCT vid) FROM {node_revision} nr WHERE nr.revision_uid IN ($placeholder) AND nr.nid = $this->tableAlias.nid) > 0)", array($placeholder => $args),
$args);
}
......
......@@ -20,7 +20,7 @@
*
* @ViewsWizard(
* id = "node_revision",
* base_table = "node_field_revision",
* base_table = "node_revision",
* title = @Translation("Content revisions")
* )
*/
......@@ -36,7 +36,7 @@ class NodeRevision extends WizardPluginBase {
*/
protected $pathField = array(
'id' => 'vid',
'table' => 'node_field_revision',
'table' => 'node_revision',
'field' => 'vid',
'exclude' => TRUE,
'alter' => array(
......@@ -97,7 +97,7 @@ protected function defaultDisplayOptions() {
/* Field: Content revision: Created date */
$display_options['fields']['timestamp']['id'] = 'timestamp';
$display_options['fields']['timestamp']['table'] = 'node_field_revision';
$display_options['fields']['timestamp']['table'] = 'node_revision';
$display_options['fields']['timestamp']['field'] = 'timestamp';
$display_options['fields']['timestamp']['provider'] = 'node';
$display_options['fields']['timestamp']['alter']['alter_text'] = 0;
......
......@@ -26,7 +26,7 @@ public static function getInfo() {
public function setUp() {
parent::setUp();
$this->installSchema('node', array('node', 'node_field_data', 'node_field_revision'));
$this->installSchema('node', array('node', 'node_field_data', 'node_field_revision', 'node_revision'));
}
/**
......
......@@ -32,6 +32,7 @@ public static function getInfo() {
public function setUp() {
parent::setUp();
$this->installSchema('node', 'node');
$this->installSchema('node', 'node_revision');
$this->installSchema('node', 'node_field_data');
$this->installSchema('node', 'node_field_revision');
$this->installSchema('user', array('users'));
......
......@@ -134,14 +134,14 @@ function testRevisions() {
'%title' => $nodes[1]->getTitle(),
)),
'Revision deleted.');
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid',
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid',
array(':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()))->fetchField() == 0,
'Revision not found.');
// Set the revision timestamp to an older date to make sure that the
// confirmation message correctly displays the stored revision date.
$old_revision_date = REQUEST_TIME - 86400;
db_update('node_field_revision')
db_update('node_revision')
->condition('vid', $nodes[2]->getRevisionId())
->fields(array(
'revision_timestamp' => $old_revision_date,
......
......@@ -114,12 +114,12 @@ function testRevisions() {
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
array('%revision-date' => format_date($nodes[1]->getRevisionCreationTime()),
'@type' => 'Basic page', '%title' => $nodes[1]->label())), 'Revision deleted.');
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_field_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()))->fetchField() == 0, 'Revision not found.');
$this->assertTrue(db_query('SELECT COUNT(vid) FROM {node_revision} WHERE nid = :nid and vid = :vid', array(':nid' => $node->id(), ':vid' => $nodes[1]->getRevisionId()))->fetchField() == 0, 'Revision not found.');
// Set the revision timestamp to an older date to make sure that the
// confirmation message correctly displays the stored revision date.
$old_revision_date = REQUEST_TIME - 86400;
db_update('node_field_revision')
db_update('node_revision')
->condition('vid', $nodes[2]->getRevisionId())
->fields(array(
'revision_timestamp' => $old_revision_date,
......
......@@ -34,7 +34,7 @@ public static function getInfo() {
*/
public function setUp() {
parent::setUp();
$this->installSchema('node', array('node', 'node_field_data', 'node_field_revision'));
$this->installSchema('node', array('node', 'node_field_data', 'node_field_revision', 'node_revision'));
// Create a node type for testing.
$type = entity_create('node_type', array('type' => 'page', 'name' => 'page'));
......
......@@ -53,8 +53,8 @@ public function testNodeRevisionRelationship() {
$node_revision->save();
$column_map = array(
'vid' => 'vid',
'node_field_revision_nid' => 'node_field_revision_nid',
'node_node_field_revision_nid' => 'node_node_field_revision_nid',
'node_revision_nid' => 'node_revision_nid',
'node_node_revision_nid' => 'node_node_revision_nid',
);
// Here should be two rows.
......@@ -63,13 +63,13 @@ public function testNodeRevisionRelationship() {
$resultset_nid = array(
array(
'vid' => '1',
'node_field_revision_nid' => '1',
'node_node_field_revision_nid' => '1',
'node_revision_nid' => '1',
'node_node_revision_nid' => '1',
),
array(
'vid' => '2',
'node_field_revision_nid' => '1',
'node_node_field_revision_nid' => '1',
'node_revision_nid' => '1',
'node_node_revision_nid' => '1',
),
);
$this->assertIdenticalResultset($view_nid, $resultset_nid, $column_map);
......@@ -80,8 +80,8 @@ public function testNodeRevisionRelationship() {
$resultset_vid = array(
array(
'vid' => '2',
'node_field_revision_nid' => '1',
'node_node_field_revision_nid' => '1',
'node_revision_nid' => '1',
'node_node_revision_nid' => '1',
),
);
$this->assertIdenticalResultset($view_vid, $resultset_vid, $column_map);
......
This diff is collapsed.
......@@ -1124,7 +1124,7 @@ function node_last_changed($nid, $langcode = NULL) {
*/
function node_revision_list(EntityInterface $node) {
$revisions = array();
$result = db_query('SELECT nfr.vid, nfr.title, nfr.log, nfr.revision_uid AS uid, n.vid AS current_vid, nfr.revision_timestamp, u.name FROM {node_field_revision} nfr LEFT JOIN {node} n ON n.vid = nfr.vid INNER JOIN {users} u ON u.uid = nfr.revision_uid WHERE nfr.nid = :nid AND nfr.default_langcode = 1 ORDER BY nfr.vid DESC', array(':nid' => $node->id()));
$result = db_query('SELECT nr.vid, nfr.title, nr.log, nr.revision_uid AS uid, n.vid AS current_vid, nr.revision_timestamp, u.name FROM {node_field_revision} nfr JOIN {node_revision} nr ON nr.vid = nfr.vid LEFT JOIN {node} n ON n.vid = nfr.vid INNER JOIN {users} u ON u.uid = nr.revision_uid WHERE nfr.nid = :nid AND nfr.default_langcode = 1 ORDER BY nfr.vid DESC', array(':nid' => $node->id()));
foreach ($result as $revision) {
$revisions[$revision->vid] = $revision;
}
......@@ -2139,7 +2139,7 @@ function node_file_download_access($field, EntityInterface $entity, File $file)
*/
function node_language_delete($language) {
// On nodes with this language, unset the language.
db_update('node')
db_update('node_revision')
->fields(array('langcode' => ''))
->condition('langcode', $language->id)
->execute();
......
......@@ -198,25 +198,6 @@ function node_views_data() {
),
);
if (module_exists('language')) {
$data['node']['langcode'] = array(
'title' => t('Language'),
'help' => t('The language the content is in.'),
'field' => array(
'id' => 'node_language',
),
'filter' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
'sort' => array(
'id' => 'standard',
),
);
}
if (\Drupal::moduleHandler()->moduleExists('content_translation')) {
$data['node']['translation_link'] = array(
'title' => t('Translation link'),
......@@ -419,15 +400,14 @@ function node_views_data() {
),
);
$data['node_field_revision']['table']['entity type'] = 'node';
$data['node_revision']['table']['entity type'] = 'node';
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
$data['node_field_revision']['table']['group'] = t('Content revision');
$data['node_field_revision']['table']['wizard_id'] = 'node_revision';
$data['node_revision']['table']['group'] = t('Content revision');
$data['node_revision']['table']['wizard_id'] = 'node_revision';
// Advertise this table as a possible base table.
$data['node_field_revision']['table']['base'] = array(
$data['node_revision']['table']['base'] = array(
'field' => 'vid',
'title' => t('Content revision'),
'help' => t('Content revision is a history of changes to content.'),
......@@ -437,25 +417,14 @@ function node_views_data() {
);
// For other base tables, explain how we join.
$data['node_field_revision']['table']['join'] = array(
$data['node_revision']['table']['join'] = array(
'node' => array(
'left_field' => 'vid',
'field' => 'vid',
),
);
$data['node_field_revision']['revision_uid'] = array(
'title' => t('User'),
'help' => t('Relate a content revision to the user who created the revision.'),
'relationship' => array(
'id' => 'standard',
'base' => 'users',
'base field' => 'uid',
'label' => t('revision user'),
),
);
$data['node_field_revision']['nid'] = array(
$data['node_revision']['nid'] = array(
'title' => t('Nid'),
'help' => t('The revision NID of the content revision.'),
'field' => array(
......@@ -480,7 +449,7 @@ function node_views_data() {
),
);
$data['node_field_revision']['vid'] = array(
$data['node_revision']['vid'] = array(
'title' => t('Vid'),
'help' => t('The revision ID of the content revision.'),
'field' => array(
......@@ -505,6 +474,61 @@ function node_views_data() {
),
);
if (\Drupal::moduleHandler()->moduleExists('language')) {
$data['node_revision']['langcode'] = array(
'title' => t('Language'),
'help' => t('The language the content is in.'),
'field' => array(
'id' => 'node_language',
),
'filter' => array(
'id' => 'language',
),
'argument' => array(
'id' => 'language',
),
'sort' => array(
'id' => 'standard',
),
);
}
$data['node_revision']['log'] = array(
'title' => t('Log message'),
'help' => t('The log message entered when the revision was created.'),
'field' => array(
'id' => 'xss',
),
'filter' => array(
'id' => 'string',
),
);
$data['node_revision']['revision_uid'] = array(
'title' => t('User'),
'help' => t('Relate a content revision to the user who created the revision.'),
'relationship' => array(
'id' => 'standard',
'base' => 'users',
'base field' => 'uid',
'label' => t('revision user'),
),
);
$data['node_field_revision']['table']['entity type'] = 'node';
// Define the base group of this table. Fields that don't have a group defined
// will go into this field by default.
$data['node_field_revision']['table']['group'] = t('Content revision');
$data['node_field_revision']['table']['wizard_id'] = 'node_field_revision';
// For other base tables, explain how we join.
$data['node_field_revision']['table']['join'] = array(
'node' => array(
'left_field' => 'vid',
'field' => 'vid',
),
);
$data['node_field_revision']['status'] = array(
'title' => t('Published'),
'help' => t('Whether or not the content is published.'),
......@@ -544,17 +568,6 @@ function node_views_data() {
),
);
$data['node_field_revision']['log'] = array(
'title' => t('Log message'),
'help' => t('The log message entered when the revision was created.'),
'field' => array(
'id' => 'xss',
),
'filter' => array(
'id' => 'string',
),
);
$data['node_field_revision']['changed'] = array(
'title' => t('Updated date'),
'help' => t('The date the node was last updated.'),
......@@ -569,7 +582,7 @@ function node_views_data() {
),
);
$data['node_field_revision']['link_to_revision'] = array(
$data['node_revision']['link_to_revision'] = array(
'field' => array(
'title' => t('Link to revision'),
'help' => t('Provide a simple link to the revision.'),
......@@ -578,7 +591,7 @@ function node_views_data() {
),
);
$data['node_field_revision']['revert_revision'] = array(
$data['node_revision']['revert_revision'] = array(
'field' => array(
'title' => t('Link to revert revision'),
'help' => t('Provide a simple link to revert to the revision.'),
......@@ -587,7 +600,7 @@ function node_views_data() {
),
);
$data['node_field_revision']['delete_revision'] = array(
$data['node_revision']['delete_revision'] = array(
'field' => array(
'title' => t('Link to delete revision'),
'help' => t('Provide a simple link to delete the content revision.'),
......
id: test_node_revision_nid
base_table: node_field_revision
base_table: node_revision
core: 8
display:
default:
......@@ -7,7 +7,7 @@ display:
relationships:
nid:
id: nid
table: node_field_revision
table: node_revision
field: nid
required: true
plugin_id: standard
......@@ -15,13 +15,13 @@ display:
fields:
vid:
id: vid
table: node_field_revision
table: node_revision
field: vid
plugin_id: standard
provider: views
nid_1:
id: nid_1
table: node_field_revision
table: node_revision
field: nid
plugin_id: standard
provider: views
......@@ -35,7 +35,7 @@ display:
arguments:
nid:
id: nid
table: node_field_revision
table: node_revision
field: nid
plugin_id: node_nid
provider: node
......
id: test_node_revision_vid
base_table: node_field_revision
base_table: node_revision
core: 8
display:
default:
......@@ -7,7 +7,7 @@ display:
relationships:
vid:
id: vid
table: node_field_revision
table: node_revision
field: vid
required: true
plugin_id: standard
......@@ -15,13 +15,13 @@ display:
fields:
vid:
id: vid
table: node_field_revision
table: node_revision
field: vid
plugin_id: standard
provider: views
nid_1:
id: nid_1
table: node_field_revision
table: node_revision
field: nid
plugin_id: standard
provider: views
......@@ -35,7 +35,7 @@ display:
arguments:
nid:
id: nid
table: node_field_revision
table: node_revision
field: nid
plugin_id: node_nid
provider: node
......
......@@ -21,7 +21,7 @@ abstract class NormalizerTestBase extends DrupalUnitTestBase {
protected function setUp() {
parent::setUp();
$this->installSchema('entity_test', array('entity_test_mulrev', 'entity_test_mulrev_property_revision', 'entity_test_mulrev_property_data'));
$this->installSchema('entity_test', array('entity_test_mulrev', 'entity_test_mulrev_revision', 'entity_test_mulrev_property_revision', 'entity_test_mulrev_property_data'));
$this->installSchema('user', array('users', 'users_roles'));
$this->installSchema('system', array('url_alias'));
$this->installConfig(array('field'));
......
......@@ -31,6 +31,7 @@ public function setUp() {
'entity_test_rev',
'entity_test_rev_revision',
'entity_test_mulrev',
'entity_test_mulrev_revision',
'entity_test_mulrev_property_data',
'entity_test_mulrev_property_revision'
));
......
......@@ -44,7 +44,7 @@ public static function getInfo() {
public function setUp() {
parent::setUp();
$this->installSchema('user', array('users_data'));
$this->installSchema('node', array('node', 'node_field_data', 'node_field_revision', 'node_access'));
$this->installSchema('node', array('node', 'node_revision', 'node_field_data', 'node_field_revision', 'node_access'));
$this->installSchema('comment', array('comment', 'comment_entity_statistics'));
}
......
......@@ -37,13 +37,14 @@ public static function getInfo() {
public function setUp() {
parent::setUp();
$this->installSchema('user', array('users_data'));
$this->installSchema('node', array('node', 'node_field_data', 'node_field_revision', 'node_access'));
$this->installSchema('node', array('node', 'node_revision', 'node_field_data', 'node_field_revision', 'node_access'));
$this->installSchema('entity_test', array(
'entity_test_mul',
'entity_test_mul_property_data',
'entity_test_rev',
'entity_test_rev_revision',
'entity_test_mulrev',
'entity_test_mulrev_revision',
'entity_test_mulrev_property_data',
'entity_test_mulrev_property_revision'
));
......
......@@ -57,7 +57,7 @@ public static function getInfo() {
function setUp() {