You are here

function context_update_6001 in Context 6

Same name and namespace in other branches
  1. 6.3 context.install \context_update_6001()
  2. 6.2 context.install \context_update_6001()

Update script for context that installs the context schema and migrates any existing context data from deprecated context_ui tables.

File

./context.install, line 70

Code

function context_update_6001() {
  $ret = array();
  if (!db_table_exists('context')) {
    drupal_install_schema('context');
  }
  if (db_table_exists('context_ui')) {

    // Clear the schema cache and rebuild
    drupal_get_schema(NULL, TRUE);

    // Migrate existing contexts to context table
    $result = db_query("SELECT * FROM {context_ui}");
    while ($context = db_fetch_object($result)) {

      // Load setters
      $setter_result = db_query("SELECT * FROM {context_ui_setter} WHERE cid = %d", $context->cid);
      while ($row = db_fetch_object($setter_result)) {
        $context->{$row->type}[$row->id] = $row->id;
      }

      // Load getters
      $getter_result = db_query("SELECT * FROM {context_ui_getter} WHERE cid = %d", $context->cid);
      while ($row = db_fetch_object($getter_result)) {
        $context->{$row->type} = unserialize($row->data);
      }

      // Load blocks
      $block_result = db_query("SELECT module, delta, region, weight FROM {context_ui_block} WHERE cid = %d", $context->cid);
      while ($block = db_fetch_object($block_result)) {
        if (!isset($context->block)) {
          $context->block = array();
        }
        $block->bid = $block->module . "_" . $block->delta;
        $context->block[$block->bid] = $block;
      }

      // Clear out identifier
      unset($context->cid);
      context_save_context($context);
    }
  }
  return $ret;
}