Projet

Général

Profil

Paste
Télécharger (4,01 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / link / link.install @ 8e7483ab

1
<?php
2

    
3
/**
4
 * @file
5
 * Install file for the link module.
6
 */
7

    
8
/**
9
 * Upgrade notes.
10
 *
11
 * Things we need to make sure work when upgrading from Drupal 6 to Drupal 7:.
12
 */
13

    
14
/**
15
 * Implements hook_install().
16
 */
17
function link_install() {
18
  // Notify the user they may want to install token.
19
  if (!module_exists('token')) {
20
    $t = get_t();
21
    drupal_set_message($t('If you install the <a href="!url" target="blank">Token</a>, static title can use any other entity field as its value.', array(
22
      '!url' => 'http://drupal.org/project/token',
23
    )));
24
  }
25
}
26

    
27
/**
28
 * Removes unused link_extra_domains variable.
29
 */
30
function link_update_7002() {
31
  variable_del('link_extra_domains');
32
}
33

    
34
/**
35
 * Implements hook_uninstall().
36
 */
37
function link_uninstall() {
38
  variable_del('link_allowed_domains');
39
}
40

    
41
/**
42
 * Implements hook_field_schema().
43
 */
44
function link_field_schema($field) {
45
  return array(
46
    'columns' => array(
47
      'url' => array(
48
        'type' => 'varchar',
49
        // Maximum URLs length.
50
        'length' => 2048,
51
        'not null' => FALSE,
52
        'sortable' => TRUE,
53
      ),
54
      'title' => array(
55
        'type' => 'varchar',
56
        'length' => 255,
57
        'not null' => FALSE,
58
        'sortable' => TRUE,
59
      ),
60
      'attributes' => array(
61
        'type' => 'text',
62
        'size' => 'medium',
63
        'not null' => FALSE,
64
      ),
65
    ),
66
  );
67
}
68

    
69
/**
70
 * Implements hook_update_last_removed().
71
 */
72
function link_update_last_removed() {
73
  return 6001;
74
}
75

    
76
/**
77
 * Implements hook_update_N().
78
 *
79
 * Handles moving settings data from field_config.data to
80
 * field_config_instance.data.
81
 */
82
function link_update_7000() {
83

    
84
  // For each field that is a link field, we need to copy the settings from the
85
  // general field level down to the instance.
86
  $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
87
  foreach ($result as $field) {
88

    
89
    $field_data = unserialize($field->data);
90

    
91
    $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
92
    foreach ($instances as $instance) {
93
      // If this field has been updated already, we want to skip it.
94
      $instance_data = unserialize($instance->data);
95
      $update_instance = FALSE;
96
      if (!isset($instance_data['settings']['title'])) {
97
        foreach ($field_data['settings'] as $key => $value) {
98
          if (!isset($instance_data['settings'][$key])) {
99
            $instance_data['settings'][$key] = $value;
100
            $update_instance = TRUE;
101
          }
102
        }
103
        if ($update_instance) {
104
          // Update the database.
105
          db_update('field_config_instance')
106
            ->fields(array('data' => serialize($instance_data)))
107
            ->condition('id', $instance->id)
108
            ->execute();
109
        }
110
      }
111
    }
112
  }
113

    
114
  return t("Instance settings have been set with the data from the field settings.");
115
}
116

    
117
/**
118
 * Renames all displays from foobar to link_foobar.
119
 */
120
function link_update_7001() {
121
  // Update the display type for each link field type.
122
  $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
123
  foreach ($result as $field) {
124

    
125
    $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field->id));
126
    foreach ($instances as $instance) {
127
      // If this field has been updated already, we want to skip it.
128
      $instance_data = unserialize($instance->data);
129
      $update_instance = FALSE;
130
      foreach ($instance_data['display'] as $display_name => $display_data) {
131
        if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
132
          $instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
133
          $update_instance = TRUE;
134
        }
135
      }
136
      if ($update_instance) {
137
        db_update('field_config_instance')
138
          ->fields(array('data' => serialize($instance_data)))
139
          ->condition('id', $instance->id)
140
          ->execute();
141
      }
142
    }
143
  }
144
}