summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEarl Miles2011-06-14 19:35:21 (GMT)
committer Earl Miles2011-06-14 19:35:21 (GMT)
commit37a4f648ae4c18c9ff1d8d8a5f68b51bb51a0634 (patch)
treea60ce80c2638e1a2d15662849c871b09f15268af
parent20663e66d216a6d6cc1b0769e9d19f89e7a86a37 (diff)
Issue #1175846: Automatic relationship updating code was breaking views that had tables move.
-rw-r--r--includes/admin.inc3
-rw-r--r--includes/view.inc23
-rw-r--r--views.module22
3 files changed, 39 insertions, 9 deletions
diff --git a/includes/admin.inc b/includes/admin.inc
index fca62a4..7c5c418 100644
--- a/includes/admin.inc
+++ b/includes/admin.inc
@@ -1962,6 +1962,9 @@ function views_ui_import_validate($form, &$form_state) {
form_set_error('', t('A view by that name already exists; please choose a different name'));
}
+ // Make sure base table gets set properly if it got moved.
+ $view->update();
+
$view->init_display();
$broken = FALSE;
diff --git a/includes/view.inc b/includes/view.inc
index fa78345..78429b8 100644
--- a/includes/view.inc
+++ b/includes/view.inc
@@ -65,7 +65,7 @@ class view extends views_db_object {
* @var string
*/
var $current_display;
-
+
/**
* Where the $query object will reside:
*
@@ -99,6 +99,20 @@ class view extends views_db_object {
}
/**
+ * 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.
+ */
+ 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);
+ }
+
+
+ /**
* Returns a list of the sub-object types used by this view. These types are
* stored on the display, and are used in the build process.
*/
@@ -400,7 +414,8 @@ class view extends views_db_object {
// For each relationship we have, make sure we mark the base it provides as
// available.
foreach ($this->display_handler->get_option('relationships') as $id => $options) {
- $data = views_fetch_data($options['table']);
+ $options['table'] = views_move_table($options['table']);
+ $data = views_fetch_data($options['table'], FALSE);
$base_tables[$data[$options['field']]['relationship']['base']] = TRUE;
}
@@ -410,7 +425,9 @@ class view extends views_db_object {
$types = views_object_types();
foreach ($types as $key => $info) {
foreach ($this->display_handler->get_option($info['plural']) as $id => $options) {
- $data = views_fetch_data($options['table']);
+ $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']));
diff --git a/views.module b/views.module
index bdc3a16..66d6459 100644
--- a/views.module
+++ b/views.module
@@ -1379,17 +1379,27 @@ function views_get_view($name, $reset = FALSE) {
ctools_include('export');
$view = ctools_export_crud_load('views_view', $name);
if ($view) {
- // When views are converted automatically the base_table should be renamed
- // to have a working query.
- $data = views_fetch_data($view->base_table, FALSE);
- if (isset($data['moved to'])) {
- $view->base_table = $data['moved to'];
- }
+ $view->update();
return $view->clone_view();
}
}
/**
+ * Find the real location of at able.
+ *
+ * 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;
+}
+
+/**
* Export callback to load the view subrecords, which are the displays.
*/
function views_load_display_records(&$views) {