You are here

function radioactivity_update_2 in Radioactivity 5

File

./radioactivity.install, line 165

Code

function radioactivity_update_2() {
  $ret = array();

  // views update
  if (module_exists('views')) {
    views_invalidate_cache();
    $ret[] = array(
      'success' => TRUE,
      'query' => t('Views cache cleared'),
    );
    $view_upgraded = FALSE;

    // list views
    $result = db_query("SELECT vid, name FROM {view_view} ORDER BY NAME");
    while ($row = db_fetch_object($result)) {

      // get the view object
      $view = views_load_view($row->vid);
      $view = _radioactivity_upgrade_view($view);
      if ($view) {
        $success = _views_save_view($view) == $row->vid;
        $ret[] = array(
          'success' => $success,
          'query' => t('Upgraded view %name(%vid)', array(
            '%name' => $row->name,
            '%vid' => $row->vid,
          )),
        );
        $view_upgraded = TRUE;
      }
    }
    if (!$view_upgraded) {
      $ret[] = array(
        'success' => TRUE,
        'query' => t('No views needed upgrading'),
      );
    }
  }
  else {
    $ret[] = array(
      'success' => TRUE,
      'query' => t('Views not enabled, so skipping views upgrade'),
    );
  }
  return $ret;
}