Commit fb4926ca authored by tim.plunkett's avatar tim.plunkett

Issue #1808810 by tim.plunkett: Remove handling of moved tables.

parent a2ae3f8e
......@@ -44,17 +44,6 @@ function _views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) {
}
}
if (isset($cache[$table])) {
if (isset($cache[$table]['moved to']) && $move) {
$moved_table = $cache[$table]['moved to'];
if (!empty($recursion_protection[$table])) {
// recursion detected!
return NULL;
}
$recursion_protection[$table] = TRUE;
$data = _views_fetch_data($moved_table);
$recursion_protection = array();
return $data;
}
return $cache[$table];
}
}
......
......@@ -27,19 +27,6 @@ public function setUp() {
drupal_theme_rebuild();
}
public function viewsData() {
$data = parent::viewsData();
$data['views_test_data_previous'] = array();
$data['views_test_data_previous']['id']['field']['moved to'] = array('views_test_data', 'id');
$data['views_test_data_previous']['id']['filter']['moved to'] = array('views_test_data', 'id');
$data['views_test_data']['age_previous']['field']['moved to'] = array('views_test_data', 'age');
$data['views_test_data']['age_previous']['sort']['moved to'] = array('views_test_data', 'age');
$data['views_test_data_previous']['name_previous']['field']['moved to'] = array('views_test_data', 'name');
$data['views_test_data_previous']['name_previous']['argument']['moved to'] = array('views_test_data', 'name');
return $data;
}
public function test_views_trim_text() {
// Test unicode, @see http://drupal.org/node/513396#comment-2839416
$text = array(
......@@ -115,29 +102,9 @@ function testviews_get_handler() {
}
}
// Test the automatic conversion feature.
// Test the automatic table renaming.
$handler = views_get_handler('views_test_data_previous', 'id', 'field');
$this->assertInstanceHandler($handler, 'views_test_data', 'id', 'field');
$handler = views_get_handler('views_test_data_previous', 'id', 'filter');
$this->assertInstanceHandler($handler, 'views_test_data', 'id', 'filter');
// Test the automatic field renaming.
$handler = views_get_handler('views_test_data', 'age_previous', 'field');
$this->assertInstanceHandler($handler, 'views_test_data', 'age', 'field');
$handler = views_get_handler('views_test_data', 'age_previous', 'sort');
$this->assertInstanceHandler($handler, 'views_test_data', 'age', 'sort');
// Test the automatic table and field renaming.
$handler = views_get_handler('views_test_data_previous', 'name_previous', 'field');
$this->assertInstanceHandler($handler, 'views_test_data', 'name', 'field');
$handler = views_get_handler('views_test_data_previous', 'name_previous', 'argument');
$this->assertInstanceHandler($handler, 'views_test_data', 'name', 'argument');
// Test the override handler feature.
$handler = views_get_handler('views_test_data', 'job', 'filter', 'string');
$this->assertEqual('Drupal\\views\\Plugin\\views\\filter\\String', get_class($handler));
$handler = views_get_handler('views_test_data', 'job', 'filter', 'standard');
$this->assertEqual('Drupal\\views\\Plugin\\views\\filter\\Standard', get_class($handler));
}
/**
......
<?php
/**
* @file
* Definition of Drupal\views\Tests\UpgradeTestCase.
*/
namespace Drupal\views\Tests;
/**
* Tests the upgrade path of all conversions.
*
* You can find all conversions by searching for "moved to".
*/
class UpgradeTestCase extends ViewTestBase {
/**
* Modules to enable.
*
* To import a view the user needs use PHP for settings rights, so enable php
* module.
*
* @var array
*/
public static $modules = array('views_ui', 'block', 'php');
public static function getInfo() {
return array(
'name' => 'Upgrade path',
'description' => 'Tests the upgrade path of modules which were changed.',
'group' => 'Views',
);
}
protected function setUp() {
parent::setUp();
$this->enableViewsTestModule();
}
function viewsData() {
$data = parent::viewsData();
$data['views_test_data']['old_field_1']['moved to'] = array('views_test_data', 'id');
$data['views_test_data']['old_field_2']['field']['moved to'] = array('views_test_data', 'name');
$data['views_test_data']['old_field_3']['filter']['moved to'] = array('views_test_data', 'age');
// @todo Test this scenario, too.
$data['views_old_table_2']['old_field']['moved to'] = array('views_test_data', 'job');
$data['views_old_table']['moved to'] = 'views_test_data';
return $data;
}
function debugField($field) {
$keys = array('id', 'table', 'field', 'actualField', 'original_field', 'realField');
$info = array();
foreach ($keys as $key) {
$info[$key] = $field->{$key};
}
debug($info, NULL, TRUE);
}
/**
* Tests the moved to parameter in general.
*/
public function testMovedTo() {
// Test moving on field lavel.
$view = $this->createViewFromConfig('test_views_move_to_field');
$view->storage->update();
$view->build();
// $this->assertEqual('old_field_1', $view->field['old_field_1']->options['id'], "Id shouldn't change during conversion");
// $this->assertEqual('id', $view->field['old_field_1']->field, 'The field should change during conversion');
$this->assertEqual('id', $view->field['old_field_1']->realField);
$this->assertEqual('views_test_data', $view->field['old_field_1']->table);
$this->assertEqual('old_field_1', $view->field['old_field_1']->original_field, 'The field should have stored the original_field');
// Test moving on handler lavel.
$view = $this->createViewFromConfig('test_views_move_to_handler');
$view->storage->update();
$view->build();
// $this->assertEqual('old_field_2', $view->field['old_field_2']->options['id']);
$this->assertEqual('name', $view->field['old_field_2']->realField);
$this->assertEqual('views_test_data', $view->field['old_field_2']->table);
// $this->assertEqual('old_field_3', $view->filter['old_field_3']->options['id']);
$this->assertEqual('age', $view->filter['old_field_3']->realField);
$this->assertEqual('views_test_data', $view->filter['old_field_3']->table);
// Test moving on table level.
$view = $this->createViewFromConfig('test_views_move_to_table');
$view->storage->update();
$view->build();
$this->assertEqual('views_test_data', $view->storage->base_table, 'Make sure that view->base_table gets automatically converted.');
// $this->assertEqual('id', $view->field['id']->field, 'If we move a whole table fields of this table should work, too.');
$this->assertEqual('id', $view->field['id']->realField, 'To run the query right the realField has to be set right.');
$this->assertEqual('views_test_data', $view->field['id']->table);
}
}
......@@ -222,19 +222,6 @@ public function getHumanName() {
return $human_name;
}
/**
* Perform automatic updates when loading or importing a view.
*
* Over time, some things about Views or Drupal data has changed.
* this attempts to do some automatic updates that must happen
* to ensure older views will at least try to work.
*/
public function update() {
// When views are converted automatically the base_table should be renamed
// to have a working query.
$this->base_table = views_move_table($this->base_table);
}
/**
* Adds a new display handler to the view, automatically creating an ID.
*
......
......@@ -157,7 +157,6 @@ function comment_views_data() {
// Langcode field
if (module_exists('language')) {
$data['comment']['language']['moved to'] = array('comment', 'langcode');
$data['comment']['langcode'] = array(
'title' => t('Language'),
'help' => t('The language the comment is in.'),
......
......@@ -215,7 +215,6 @@ function node_views_data() {
// Language field
if (module_exists('language')) {
$data['node']['language']['moved to'] = array('node', 'langcode');
$data['node']['langcode'] = array(
'title' => t('Language'),
'help' => t('The language the content is in.'),
......@@ -464,6 +463,7 @@ function node_views_data() {
'help' => t('The revision NID of the content revision.'),
// Information for displaying the nid.
'field' => array(
'id' => 'standard',
'click sortable' => TRUE,
),
// Information for accepting a nid as an argument.
......@@ -495,6 +495,7 @@ function node_views_data() {
'help' => t('The revision ID of the content revision.'),
// Information for displaying the vid
'field' => array(
'id' => 'standard',
'click sortable' => TRUE,
),
// Information for accepting a vid as an argument
......
......@@ -135,7 +135,6 @@ function user_views_data() {
);
// language
$data['users']['language']['moved to'] = array('users', 'langcode');
$data['users']['langcode'] = array(
'title' => t('Language'), // The item it appears as on the UI,
'help' => t('Language of the user'),
......
......@@ -1288,57 +1288,11 @@ function views_include_handlers($reset = FALSE) {
* An instance of a handler object. May be views_handler_broken.
*/
function views_get_handler($table, $field, $type, $override = NULL) {
static $recursion_protection = array();
// Get the plugin manager for this type.
$manager = drupal_container()->get("plugin.manager.views.$type");
$data = views_fetch_data($table, FALSE);
$handler = NULL;
// Support conversion on table level.
if (isset($data['moved to'])) {
$moved = array($data['moved to'], $field);
}
// Support conversion on datafield level.
if (isset($data[$field]['moved to'])) {
$moved = $data[$field]['moved to'];
}
// Support conversion on handler level.
if (isset($data[$field][$type]['moved to'])) {
$moved = $data[$field][$type]['moved to'];
}
if (isset($data[$field][$type]) || !empty($moved)) {
if (!empty($moved)) {
list($moved_table, $moved_field) = $moved;
if (!empty($recursion_protection[$moved_table][$moved_field])) {
// recursion detected!
return NULL;
}
$recursion_protection[$moved_table][$moved_field] = TRUE;
$handler = views_get_handler($moved_table, $moved_field, $type, $override);
$recursion_protection = array();
if ($handler) {
// store these values so we know what we were originally called.
$handler->original_table = $table;
$handler->original_field = $field;
if (empty($handler->actualTable)) {
$handler->actualTable = $moved_table;
$handler->actualField = $moved_field;
}
}
return $handler;
}
// @fixme: temporary.
// Set up a default handler, if both handler and id is not specified.
if (empty($data[$field][$type]['handler']) && empty($data[$field][$type]['id'])) {
$data[$field][$type]['id'] = 'standard';
}
if ($override) {
$data[$field][$type]['override handler'] = $override;
}
if (isset($data[$field][$type])) {
$definition = $data[$field][$type];
foreach (array('group', 'title', 'title short', 'help', 'real field', 'real table') as $key) {
if (!isset($definition[$key])) {
......@@ -1354,8 +1308,7 @@ function views_get_handler($table, $field, $type, $override = NULL) {
}
// @todo This is crazy. Find a way to remove the override functionality.
$manager = drupal_container()->get("plugin.manager.views.$type");
$plugin_id = !empty($definition['override handler']) ? $definition['override handler'] : $definition['id'];
$plugin_id = $override ?: $definition['id'];
// Try to use the overridden handler.
try {
return $manager->createInstance($plugin_id, $definition);
......@@ -1373,7 +1326,7 @@ function views_get_handler($table, $field, $type, $override = NULL) {
// Finally, use the 'broken' handler.
debug(t("Missing handler: @table @field @type", array('@table' => $table, '@field' => $field, '@type' => $type)));
return views_get_plugin($type, 'broken');
return $manager->createInstance('broken');
}
/**
......@@ -1715,28 +1668,10 @@ function views_view_is_disabled($view) {
function views_get_view($name) {
$view = entity_load('view', $name);
if ($view) {
$view->update();
$view = $view->getExecutable();
// @figure out whether it makes sense to clone this here.
return $view->cloneView();
return $view->getExecutable();
}
}
/**
* Find the real location of a table.
*
* If a table has moved, find the new name of the table so that we can
* change its name directly in options where necessary.
*/
function views_move_table($table) {
$data = views_fetch_data($table, FALSE);
if (isset($data['moved to'])) {
$table = $data['moved to'];
}
return $table;
}
// ------------------------------------------------------------------
// Views form (View with form elements)
......
......@@ -2600,10 +2600,6 @@ function views_fetch_fields($base, $type, $grouping = FALSE) {
$skip_bases[$field][$key][$base_name] = TRUE;
}
}
// Don't show old fields. The real field will be added right.
if (isset($info[$key]['moved to'])) {
continue;
}
foreach (array('title', 'group', 'help', 'base', 'aliases') as $string) {
// First, try the lowest possible level
if (!empty($info[$key][$string])) {
......
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