You are here

function context_update_6301 in Context 6.3

Update 6301: Update schema.

File

./context.install, line 192

Code

function context_update_6301() {

  // Install CTools.
  drupal_install_modules(array(
    'ctools',
  ));
  $schema = array(
    'fields' => array(
      'name' => array(
        'description' => 'The primary identifier for a context.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'description' => array(
        'description' => 'Description for this context.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'tag' => array(
        'description' => 'Tag for this context.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'conditions' => array(
        'description' => 'Serialized storage of all context condition settings.',
        'type' => 'text',
        'serialize' => TRUE,
      ),
      'reactions' => array(
        'description' => 'Serialized storage of all context reaction settings.',
        'type' => 'text',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  $ret = array();
  if (db_table_exists('context')) {
    $result = db_query("SELECT * FROM {context}");

    // Migrate old contexts into new table.
    $contexts = array();
    while ($context = db_fetch_object($result)) {
      $data = unserialize($context->data);
      unset($context->data);
      foreach ($data as $k => $v) {
        $context->{$k} = $v;
      }
      $contexts["{$context->namespace}-{$context->attribute}-{$context->value}"] = $context;
    }

    // Drop the existing context table and create one using the new schema.
    db_drop_table($ret, 'context');
    db_create_table($ret, 'context', $schema);

    // Migrate objects.
    context_migrate_api_3($ret, $contexts);
  }
  return $ret;
}