You are here

function context_ui_update_6001 in Context 6

File

context_ui/context_ui.install, line 181

Code

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

  // Double check ... it's possible that these updates have
  // been run if a user's been keeping up with CVS : (
  if (!db_table_exists('context_ui_getter')) {
    $schema = context_ui_schema();

    // Add the ui_getter table
    db_create_table($ret, 'context_ui_getter', $schema['context_ui_getter']);

    // Move getters to the getter table
    $result = db_query("SELECT * FROM {context_ui_item} WHERE type IN ('menu', 'css_injector')");
    while ($row = db_fetch_object($result)) {
      $row->data = $row->id;
      unset($row->id);
      drupal_write_record('context_ui_getter', $row);
    }
    $ret[] = update_sql("DELETE FROM {context_ui_item} WHERE type IN ('menu', 'css_injector')");

    // Rename ui_item to ui_setter and update keys
    db_rename_table($ret, 'context_ui_item', 'context_ui_setter');
    db_drop_unique_key($ret, 'context_ui_setter', 'key1');
    _db_create_keys_sql(array(
      'unique keys' => $schema['context_ui_setter']['unique keys'],
    ));

    // Update cid field
    db_drop_primary_key($ret, 'context_ui');
    db_change_field($ret, 'context_ui', 'cid', 'cid', $schema['context_ui']['fields']['cid'], array(
      'primary key' => $schema['context_ui']['primary key'],
    ));

    // Update status field
    db_drop_unique_key($ret, 'context_ui', 'key1');
    db_change_field($ret, 'context_ui', 'status', 'status', $schema['context_ui']['fields']['status'], array(
      'unique keys' => $schema['context_ui']['unique keys'],
    ));
  }
  return $ret;
}