You are here

function draggableviews_update_6401 in DraggableViews 7

Same name and namespace in other branches
  1. 6.3 draggableviews.install \draggableviews_update_6401()

Alter schema to add arguments field

File

./draggableviews.install, line 150
Draggableviews defines a new database schema for saving the collapsed/expand state of views.

Code

function draggableviews_update_6401() {
  $ret = array();
  db_drop_primary_key('draggableviews_structure');
  db_add_field('draggableviews_structure', 'view_name', array(
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => '',
  ));

  // Update code.
  $result = db_query('SELECT vid FROM {draggableviews_structure}');
  while ($row = db_fetch_object($result)) {
    $view = db_fetch_object(db_query('SELECT name FROM {views_view} WHERE vid = :vid', array(
      ':vid' => $row->vid,
    )));

    // TODO Please review the conversion of this statement to the D7 database API syntax.

    /* db_query("UPDATE {draggableviews_structure} SET view_name='%s' WHERE vid=%d", $view->name, $row->vid) */
    db_update('draggableviews_structure')
      ->fields(array(
      'view_name' => $view->name,
    ))
      ->condition('vid', $row->vid)
      ->execute();
  }
  db_drop_field('draggableviews_structure', 'vid');
  db_add_primary_key('draggableviews_structure', array(
    'nid',
    'view_name',
    'delta',
    'args',
  ));
  db_drop_primary_key('draggableviews_collapsed');
  db_add_field('draggableviews_collapsed', 'view_name', array(
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => '',
  ));

  // Update code.
  $result = db_query('SELECT vid FROM {draggableviews_collapsed}');
  while ($row = db_fetch_object($result)) {
    $view = db_fetch_object(db_query('SELECT name FROM {views_view} WHERE vid = :vid', array(
      ':vid' => $row->vid,
    )));

    // TODO Please review the conversion of this statement to the D7 database API syntax.

    /* db_query("UPDATE {draggableviews_collapsed} SET view_name='%s' WHERE vid=%d", $view->name, $row->vid) */
    db_update('draggableviews_collapsed')
      ->fields(array(
      'view_name' => $view->name,
    ))
      ->condition('vid', $row->vid)
      ->execute();
  }
  db_drop_field('draggableviews_collapsed', 'vid');
  db_add_primary_key('draggableviews_collapsed', array(
    'uid',
    'parent_nid',
    'view_name',
  ));

  // hook_update_N() no longer returns a $ret array. Instead, return
  // nothing or a translated string indicating the update ran successfully.
  // See http://drupal.org/node/224333#update_sql.
  return t('TODO Add a descriptive string here to show in the UI.');
}