You are here

function ccl_update_7102 in Custom Contextual Links 7

Same name and namespace in other branches
  1. 8 ccl.install \ccl_update_7102()

Adjust table for modular plugin system.

File

./ccl.install, line 75
Provides install, upgrade and un-install functions for ccl.

Code

function ccl_update_7102() {

  // First add new options field.
  $options_field = array(
    'description' => 'The options for this specific link.',
    'type' => 'blob',
    'not null' => TRUE,
    'size' => 'big',
    'initial' => serialize(array()),
  );
  db_add_field('ccl', 'options', $options_field);
  $rows = db_select('ccl', 'c')
    ->fields('c')
    ->execute();
  foreach ($rows as $row) {
    $default = array(
      'node_options' => '',
      'node_type' => '',
      'node_id' => '',
      'block_global' => '',
      'block_select' => '',
    );
    if ($row->type == 'block' && $row->global) {
      $default['block_global'] = 1;
    }
    elseif ($row->type == 'block' && !$row->global) {
      $default['block_select'] = $row->block;
    }
    elseif ($row->type == 'node' && $row->global) {
      $default['node_options'] = 'global';
    }
    elseif ($row->type == 'node' && !$row->global && !$row->nid) {
      $default['node_options'] = 'ct';
      $default['node_type'] = $row->ct;
    }
    else {
      $default['node_options'] = 'node';
      $default['node_id'] = $row->nid;
    }
    db_update('ccl')
      ->fields(array(
      'options' => serialize($default),
    ))
      ->condition('clid', $row->clid)
      ->execute();
  }
  db_drop_field('ccl', 'global');
  db_drop_field('ccl', 'ct');
  db_drop_field('ccl', 'nid');
  db_drop_field('ccl', 'block');
  module_enable(array(
    'ccl_blocks',
  ));
}