You are here

function globallink_update_7201 in GlobalLink Connect for Drupal 7.7

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

Implements hook_update_N().

Version 2.0.1 updates.

File

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

Code

function globallink_update_7201() {
  $keys = array_keys($_SESSION);
  foreach ($keys as $key) {
    if (stristr($key, 'globallink') !== FALSE) {
      unset($_SESSION[$key]);
    }
  }
  if (!module_exists('field_collection')) {
    return;
  }
  db_truncate('globallink_field_config')
    ->execute();
  $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':
        case 'field_collection':
          break;
        default:
          $translatable = 1;
          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' => $translatable,
          ))
            ->execute();
      }
    }
    if (module_exists('field_collection')) {
      globallink_insert_field_collections($node_type->type);
    }
  }
  return t('GlobalLink module has been successfully upgraded to version 2.0.1');
}