You are here

function globallink_update_7200 in GlobalLink Connect for Drupal 7.7

Same name and namespace in other branches
  1. 7.5 globallink.install \globallink_update_7200()
  2. 7.6 globallink.install \globallink_update_7200()

Implements hook_update_N().

Version 2.0 updates.

File

./globallink.install, line 2182
Installation file for GlobalLink module.

Code

function globallink_update_7200() {
  variable_set('globallink_pd_max_target', 99999);
  $keys = array_keys($_SESSION);
  foreach ($keys as $key) {
    if (stristr($key, 'globallink') !== FALSE) {
      unset($_SESSION[$key]);
    }
  }
  $last_modified = array(
    'description' => 'Last Modified Date for Source Node',
    'type' => 'int',
    'length' => 14,
    'unsigned' => TRUE,
    'not null' => FALSE,
  );
  db_add_field('globallink_core', 'last_modified', $last_modified);
  $changed = array(
    'description' => 'Boolean Flag indicating whether source node has changed',
    'type' => 'int',
    'length' => 1,
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field('globallink_core', 'changed', $changed);
  $schema = array();
  $schema['globallink_field_config'] = array(
    'description' => 'GlobalLink Field Config Table',
    'fields' => array(
      'fid' => array(
        'description' => 'The row ID',
        'type' => 'serial',
        'unsigned' => FALSE,
        'not null' => TRUE,
      ),
      'content_type' => array(
        'description' => 'The content type for the field',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
      ),
      'entity_type' => array(
        'description' => 'The entity type for the field',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'bundle' => array(
        'description' => 'The node type for this field',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'field_name' => array(
        'description' => 'The field_name for this field',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'field_type' => array(
        'description' => 'The field_type for this field',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'field_label' => array(
        'description' => 'The field_label for this field',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'field_format' => array(
        'description' => 'The field_format for this field',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'translatable' => array(
        'description' => 'Is this field translatable?',
        'type' => 'int',
        'length' => 1,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'fid',
    ),
    'indexes' => array(
      'field_name' => array(
        'field_name',
      ),
    ),
  );
  db_create_table('globallink_field_config', $schema['globallink_field_config']);
  $node_types = node_type_get_types();
  foreach ($node_types as $node_type) {
    if (!translation_supported_type($node_type->type)) {
      continue;
    }
    $field_arr = field_info_instances(GLOBALLINK_ENTITY_TYPE_NODE, $node_type->type);
    $keys = array_keys($field_arr);
    db_insert('globallink_field_config')
      ->fields(array(
      'content_type' => $node_type->type,
      'entity_type' => GLOBALLINK_ENTITY_TYPE_NODE,
      'bundle' => $node_type->type,
      'field_name' => 'title',
      'field_type' => 'text',
      'field_label' => 'Title',
      'translatable' => 1,
    ))
      ->execute();
    if (module_exists('metatag')) {
      db_insert('globallink_field_config')
        ->fields(array(
        'content_type' => $node_type->type,
        'entity_type' => GLOBALLINK_ENTITY_TYPE_NODE,
        'bundle' => $node_type->type,
        'field_name' => 'metatags',
        'field_type' => 'text',
        'field_label' => 'Meta tags',
        'translatable' => 1,
      ))
        ->execute();
    }
    foreach ($keys as $field_name) {
      $field = field_info_field($field_name);
      switch ($field['type']) {
        case 'list_boolean':
        case 'image':
        case 'file':
        case 'taxonomy_term_reference':
          break;
        case 'field_collection':
          if (!module_exists('field_collection')) {
            break;
          }
          db_insert('globallink_field_config')
            ->fields(array(
            'content_type' => $node_type->type,
            'entity_type' => GLOBALLINK_ENTITY_TYPE_NODE,
            'bundle' => $node_type->type,
            'field_name' => $field_name,
            'field_type' => $field['type'],
            'field_label' => $field_arr[$field_name]['label'],
            'translatable' => 1,
          ))
            ->execute();
          $field_info = field_info_instances('field_collection_item');
          if (!isset($field_info) || !isset($field_info[$field_name])) {
            break;
          }
          $fc_item = $field_info[$field_name];
          foreach ($fc_item as $fc_name => $fc) {
            $fc_info = field_info_field($fc_name);
            switch ($fc_info['type']) {
              case 'list_boolean':
              case 'image':
              case 'file':
              case 'taxonomy_term_reference':
              case 'field_collection':
                break;
              default:
                db_insert('globallink_field_config')
                  ->fields(array(
                  'content_type' => $node_type->type,
                  'entity_type' => 'field_collection_item',
                  'bundle' => $fc['bundle'],
                  'field_name' => $fc_name,
                  'field_type' => $fc_info['type'],
                  'field_label' => $fc['label'],
                  'translatable' => 1,
                ))
                  ->execute();
            }
          }
          break;
        default:
          db_insert('globallink_field_config')
            ->fields(array(
            'content_type' => $node_type->type,
            'entity_type' => GLOBALLINK_ENTITY_TYPE_NODE,
            'bundle' => $node_type->type,
            'field_name' => $field_name,
            'field_type' => $field['type'],
            'field_label' => $field_arr[$field_name]['label'],
            'translatable' => 1,
          ))
            ->execute();
          break;
      }
    }
  }
  return t('GlobalLink module has been successfully upgraded to version 2.0');
}