Additional default views loaded on update

Created on 9 May 2017, over 7 years ago
Updated 26 January 2023, almost 2 years ago

I recently updated a site to 7.x-1.7 and had a user complain about some changes, seems this "What Links Here" and "View" tabs started appearing on all of the pages on the site. Turns out that these were associated with a default view (backlinks) that was defined at some point in the views module but had never been properly defined/added to the site. I don't work directly with Drupal too often and I was unfamiliar with these additional views, so it took a while to properly figure out what had happened. Hopefully this issue will help some others out in similar situations, although I'm sure most have updated by now. If not - it would be a good idea to get a list of your enabled vs disabled views, and disable the views that you don't want running after this update. The backlinks view for example directly affects every page on your site.

In the update function in views_pdf 1.7, it saves every view that's returned from views_get_all_views(), which merges in default view definitions for views which had not yet been on the site. It would likely be better to only save views that get altered in the code. For example, the update function looks like this:

function views_pdf_update_7101() {
  $views = views_get_all_views();

  foreach ($views as $key => $view) {
    foreach ($view->display as $key => $display) {
      if($display->display_plugin == 'pdf') {
        if(isset($display->display_options['pager'])) {
          if (!isset($display->display_options['defaults']['pager']))  {
            $display->display_options['defaults']['pager'] = FALSE;
          }
          if (!isset($display->display_options['defaults']['pager_options'])) {
            $display->display_options['defaults']['pager_options'] = FALSE;
          }
        }
      }
    }
    views_save_view($view);
  }
}

It might help to flag the view to determine if it should be saved or not, instead of simply saving each one of them - the merged default views do not have pdf plugins set and would otherwise be skipped.

function views_pdf_update_7101() {
  $views = views_get_all_views();

  foreach ($views as $key => $view) {
    $save = FALSE; // Flag to test if view should be saved or not
    foreach ($view->display as $key => $display) {
      if($display->display_plugin == 'pdf') {
        if(isset($display->display_options['pager'])) {
          if (!isset($display->display_options['defaults']['pager']))  {
            $display->display_options['defaults']['pager'] = FALSE;
            $save = TRUE;
          }
          if (!isset($display->display_options['defaults']['pager_options'])) {
            $display->display_options['defaults']['pager_options'] = FALSE;
            $save = TRUE;
          }
        }
      }
    }
    if($save) // Only save altered views
      views_save_view($view);
  }
}

Unfortunately, simply saving one of these merged default views saves them in an enabled state, rather than disabled as would be expected. Testing against backups, this did prevent the enabling of these additional default views that we had not previously had enabled on our site.

My apologies if this information comes out with poor formatting, or is otherwise nonsensical, I do not often post on drupal.org.

πŸ› Bug report
Status

Closed: outdated

Version

1.7

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024