Projet

Général

Profil

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

root / drupal7 / sites / all / modules / link / link.install @ bad4e148

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
  variable_del('link_default_protocol');
40
}
41

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

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

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

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

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

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

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

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

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