diff --git a/includes/admin.inc b/includes/admin.inc index fca62a4c3eb3b33748ce86833c425977b01ffda7..7c5c418ba17e39edf225bf3d615df8aad9330cab 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 fa783452a83be22874e931b92156e6761d09b2c6..78429b85b59920d3a3637b49a9198ff1eef4f88a 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: * @@ -98,6 +98,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 bdc3a16417a68807933652bdbdb2dd0c82e07bd1..66d6459d7b0dcd0ed094fe9335fe6a86d9098392 100644 --- a/views.module +++ b/views.module @@ -1379,16 +1379,26 @@ 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. */