Commit 0bdc693c authored by dawehner's avatar dawehner Committed by tim.plunkett

Issue #1758828 by dawehner: Remove fix_missing_relationships().

parent 1851a1cf
......@@ -928,8 +928,6 @@ function views_ui_edit_form($form, &$form_state, $view, $display_id = NULL) {
$form['#markup'] = t('Invalid display id @display', array('@display' => $display_id));
return $form;
}
$view->fixMissingRelationships();
}
$form['#attached']['js'][] = drupal_get_path('module', 'ctools') . '/js/collapsible-div.js';
......
......@@ -43,25 +43,4 @@ protected function setUp() {
$this->nodes[] = $this->drupalCreateNode(array('uid' => 1));
}
/**
* Add a view which has no explicit relationship to the author and check the result.
*
* @todo: Remove the following comment once the relationship is required.
* One day a view will require the relationship so it should still work
*/
public function testRelationship() {
$view = $this->createViewFromConfig('test_user_relationship');
$this->executeView($view);
$expected = array();
for ($i = 0; $i <= 1; $i++) {
$expected[$i] = array(
'node_title' => $this->nodes[$i]->label(),
'users_uid' => $this->nodes[$i]->uid,
'users_name' => $this->users[$i]->name,
);
}
$this->assertIdenticalResultset($view, $expected);
}
}
......@@ -707,99 +707,11 @@ public function initStyle() {
return TRUE;
}
/**
* Attempt to discover if the view has handlers missing relationships.
*
* This will try to add relationships automatically if it can, and will
* remove the handlers if it cannot.
*/
public function fixMissingRelationships() {
if (isset($this->relationships_fixed)) {
return;
}
$this->relationships_fixed = TRUE;
// Go through all of our handler types and test them to see if they
// are missing relationships. Missing relationships can cause fatally
// broken Views.
$base_tables = array(
$this->base_table => TRUE,
'#global' => TRUE,
);
// For each relationship we have, make sure we mark the base it provides as
// available.
foreach ($this->display_handler->getOption('relationships') as $id => $options) {
$options['table'] = views_move_table($options['table']);
$data = views_fetch_data($options['table'], FALSE);
if (isset($data[$options['field']]['relationship']['base'])) {
$base_tables[$data[$options['field']]['relationship']['base']] = TRUE;
}
}
$base_tables = array_keys($base_tables);
$missing_base_tables = array();
$types = View::viewsHandlerTypes();
foreach ($types as $key => $info) {
foreach ($this->display_handler->getOption($info['plural']) as $id => $options) {
$options['table'] = views_move_table($options['table']);
$data = views_fetch_data($options['table'], FALSE);
$valid_bases = array($options['table']);
if (isset($data['table']['join'])) {
$valid_bases = array_merge($valid_bases, array_keys($data['table']['join']));
}
// If the base table is missing, record it so we can try to fix it.
if (!array_intersect($valid_bases, $base_tables)) {
$missing_base_tables[$options['table']][] = array('type' => $key, 'id' => $id);
}
}
}
if (!empty($missing_base_tables)) {
// This will change handlers, so make sure any existing handlers get
// tossed.
$this->display_handler->handlers = array();
$this->relationships_changed = TRUE;
$this->changed = TRUE;
// Try to fix it.
foreach ($missing_base_tables as $table => $handlers) {
$data = views_fetch_data($table);
$relationship = NULL;
// Does the missing base table have a default relationship we can
// throw in?
if (isset($data['table']['default_relationship'][$this->base_table])) {
// Create the relationship.
$info = $data['table']['default_relationship'][$this->base_table];
$relationship_options = isset($info['options']) ? $info['options'] : array();
$relationship = $this->addItem($this->current_display, 'relationship', $info['table'], $info['field'], $relationship_options);
}
foreach ($handlers as $handler) {
$options = $this->display_handler->getOption($types[$handler['type']]['plural']);
if ($relationship) {
$options[$handler['id']]['relationship'] = $relationship;
}
else {
unset($options[$handler['id']]);
}
$this->display_handler->setOption($types[$handler['type']]['plural'], $options);
}
}
}
}
/**
* Acquire and attach all of the handlers.
*/
public function initHandlers() {
if (empty($this->inited)) {
$this->fixMissingRelationships();
foreach (View::viewsHandlerTypes() as $key => $info) {
$this->_initHandler($key, $info);
}
......
......@@ -23,15 +23,6 @@ function comment_views_data() {
);
$data['comment']['table']['entity type'] = 'comment';
// Provide a "default relationship" to keep older views from choking.
$data['comment']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'cid',
),
);
// ----------------------------------------------------------------
// Fields
// subject
......
......@@ -32,14 +32,6 @@ function node_views_data() {
);
$data['node']['table']['entity type'] = 'node';
$data['node']['table']['default_relationship'] = array(
'node_revision' => array(
'table' => 'node_revision',
'field' => 'vid',
),
);
// ----------------------------------------------------------------
// node table -- fields
// nid
......@@ -453,13 +445,6 @@ function node_views_data() {
),
);
$data['node_revision']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'nid',
),
);
// uid field for node revision
$data['node_revision']['uid'] = array(
'title' => t('User'),
......
......@@ -26,14 +26,6 @@ function taxonomy_views_data() {
),
);
// Provide a "default relationship" to keep older views from choking.
$data['taxonomy_vocabulary']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'term_node_tid',
),
);
// vocabulary name
$data['taxonomy_vocabulary']['name'] = array(
'title' => t('Name'), // The item it appears as on the UI,
......@@ -129,14 +121,6 @@ function taxonomy_views_data() {
),
);
// Provide a "default relationship" to keep older views from choking.
$data['taxonomy_term_data']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'term_node_tid',
),
);
// tid field
$data['taxonomy_term_data']['tid'] = array(
'title' => t('Term ID'),
......@@ -356,14 +340,6 @@ function taxonomy_views_data() {
),
);
// Provide a "default relationship" to keep older views from choking.
$data['taxonomy_term_hierarchy']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'term_node_tid',
),
);
$data['taxonomy_term_hierarchy']['parent'] = array(
'title' => t('Parent term'),
'help' => t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'),
......
......@@ -26,21 +26,6 @@ function user_views_data() {
);
$data['users']['table']['entity type'] = 'user';
$data['users']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'uid',
),
'node_revision' => array(
'table' => 'node_revision',
'field' => 'uid',
),
'file' => array(
'table' => 'file',
'field' => 'uid',
),
);
// uid
$data['users']['uid'] = array(
'title' => t('Uid'),
......@@ -373,17 +358,6 @@ function user_views_data() {
),
);
$data['users_roles']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'uid',
),
'node_revision' => array(
'table' => 'node_revision',
'field' => 'uid',
),
);
$data['users_roles']['rid'] = array(
'title' => t('Roles'),
'help' => t('Roles that a user belongs to.'),
......@@ -422,17 +396,6 @@ function user_views_data() {
),
);
$data['role']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'uid',
),
'node_revision' => array(
'table' => 'node_revision',
'field' => 'uid',
),
);
// permission table
$data['role_permission']['table']['group'] = t('User');
$data['role_permission']['table']['join'] = array(
......@@ -468,17 +431,6 @@ function user_views_data() {
),
);
$data['authmap']['table']['default_relationship'] = array(
'node' => array(
'table' => 'node',
'field' => 'uid',
),
'node_revision' => array(
'table' => 'node_revision',
'field' => 'uid',
),
);
$data['authmap']['aid'] = array(
'title' => t('Authmap ID'),
'help' => t('The Authmap ID.'),
......
......@@ -117,18 +117,20 @@ display:
query:
type: views_query
relationships:
nid:
field: nid
id: nid
table: comments
cid:
field: cid
id: cid
table: node
pid:
field: pid
id: pid
table: comments
table: comment
relationship: cid
uid:
field: uid
id: uid
table: comments
table: comment
relationship: cid
row_plugin: fields
sorts:
last_comment_name:
......
api_version: '3.0'
base_table: node
core: '8'
description: ''
disabled: '0'
display:
default:
display_options:
access:
type: perm
cache:
type: none
exposed_form:
type: basic
fields:
name:
alter:
absolute: '0'
alter_text: '0'
ellipsis: '1'
external: '0'
html: '0'
make_link: '0'
nl2br: '0'
replace_spaces: '0'
strip_tags: '0'
trim: '0'
trim_whitespace: '0'
word_boundary: '1'
element_default_classes: '1'
element_label_colon: '1'
empty_zero: '0'
field: name
hide_alter_empty: '0'
hide_empty: '0'
id: name
link_to_user: '1'
overwrite_anonymous: '0'
table: users
title:
alter:
absolute: '0'
alter_text: '0'
ellipsis: '0'
html: '0'
make_link: '0'
strip_tags: '0'
trim: '0'
word_boundary: '0'
empty_zero: '0'
field: title
hide_empty: '0'
id: title
label: ''
link_to_node: '1'
table: node
uid:
alter:
absolute: '0'
alter_text: '0'
ellipsis: '1'
external: '0'
html: '0'
make_link: '0'
nl2br: '0'
replace_spaces: '0'
strip_tags: '0'
trim: '0'
trim_whitespace: '0'
word_boundary: '1'
element_default_classes: '1'
element_label_colon: '1'
empty_zero: '0'
field: uid
hide_alter_empty: '0'
hide_empty: '0'
id: uid
link_to_user: '1'
table: users
pager:
options:
items_per_page: '10'
type: full
query:
options:
query_comment: '0'
type: views_query
row_options:
default_field_elements: '1'
hide_empty: '0'
row_plugin: fields
style_plugin: default
title: test_user_relationship
display_plugin: default
display_title: Master
id: default
position: '0'
human_name: test_user_relationship
name: test_user_relationship
tag: default
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