1.20.x views.install views_update_1001()

Convert available database views to configuration files.

Related topics

File

modules/views/views.install, line 43
Contains install and update functions for Views.

Code

function views_update_1001() {
  if (db_table_exists('views_view')) {
    $views = db_query("SELECT * FROM {views_view}");
    foreach ($views as $view) {
      $view = (array) $view;
      $view['display'] = array();
      if (empty($view['human_name'])) {
        $view['human_name'] = $view['name'];
      }
      $displays = db_query("SELECT * FROM {views_display} WHERE vid = :vid ORDER BY position ASC", array(':vid' => $view['vid']));
      foreach ($displays as $display) {
        $display = (array) $display;
        $display['display_options'] = unserialize($display['display_options']);
        $id = $display['id'];
        unset($display['id']);
        unset($display['vid']);
        unset($display['position']);
        $view['display'][$id] = $display;
      }
      unset($view['vid']);
      $config = config('views.view.' . $view['name']);
      $config->setData($view);
      $config->save();
    }
  }
}