Batch Revert Views

Isn't it a pain when you have dozens of Views setup and they are all marked as "overridden" because you just pulled in an updated feature file from somewhere. Features doesn't always notice when the Views on your site aren't up to date.

The following snippet (which you should use with caution) will batch "delete" (or Revert, once the view is in code) all Views which are marked as Overridden. This took a few seconds to run on our development machine.


$views = views_get_all_views();

foreach ($views as $view) {
  if ($view->disabled) continue;

  if ($view->type == t('Overridden')) {
    $view->delete();
    views_object_cache_clear('view', $view->name);
  }
}

I ran this from the Devel PHP page (http://www.example.com/devel/php). It essentially does the same as the view module does when you individually revert views, but this does it without confirming on ALL VIEWS MARKED AS Overridden. I cannot stress enough - use at your own risk, and backup your database first!