Projet

Général

Profil

Paste
Télécharger (3,57 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2

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

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

    
13
/**
14
 * Implements hook_field_schema().
15
 */
16
function link_field_schema($field) {
17
  return array(
18
    'columns' => array(
19
      'url' => array(
20
        'type' => 'varchar',
21
        // Maximum URLs length.
22
        'length' => 2048,
23
        'not null' => FALSE,
24
        'sortable' => TRUE,
25
      ),
26
      'title' => array(
27
        'type' => 'varchar',
28
        'length' => 255,
29
        'not null' => FALSE,
30
        'sortable' => TRUE,
31
      ),
32
      'attributes' => array(
33
        'type' => 'text',
34
        'size' => 'medium',
35
        'not null' => FALSE,
36
      ),
37
    ),
38
  );
39
}
40

    
41
/**
42
 * Implements hook_update_last_removed().
43
 */
44
function link_update_last_removed() {
45
  return 6001;
46
}
47

    
48
/**
49
 * Handles moving settings data from field_config.data to field_config_instance.data.
50
 */
51
function link_update_7000() {
52
  
53
  // For each field that is a link field, we need to copy the settings from the general field level down to the instance.
54
  //$field_data = array();
55
  $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
56
  foreach ($result as $field) {
57
    $field_id = $field->id;
58
    $name = $field->field_name;
59
    $field_data = unserialize($field->data);
60
    
61
    $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
62
    foreach ($instances as $instance) {
63
      // If this field has been updated already, we want to skip it.
64
      $instance_data = unserialize($instance->data);
65
      $update_instance = FALSE;
66
      if (!isset($instance_data['settings']['title'])) {
67
        foreach ($field_data['settings'] as $key => $value) {
68
          if (!isset($instance_data['settings'][$key])) {
69
            $instance_data['settings'][$key] = $value;
70
            $update_instance = TRUE;
71
          }
72
        }
73
        if ($update_instance) {
74
          // update the database.
75
          $num_updated = db_update('field_config_instance')
76
            ->fields(array('data' => serialize($instance_data)))
77
            ->condition('id', $instance->id)
78
            ->execute();
79
        }
80
      }
81
    }
82
  }
83
  
84
  return t("Instance settings have been set with the data from the field settings.");
85
}
86

    
87
/**
88
 * Renames all displays from foobar to link_foobar
89
 */
90
function link_update_7001() {
91
  // Update the display type for each link field type.
92
  $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE module = 'link' AND type = 'link_field'");
93
  foreach ($result as $field) {
94
    $field_id = $field->id;
95
    $name = $field->field_name;
96
    $field_data = unserialize($field->data);
97
    
98
    $instances = db_query("SELECT id, data FROM {field_config_instance} WHERE field_id = :field_id", array(':field_id' => $field_id));
99
    foreach ($instances as $instance) {
100
      // If this field has been updated already, we want to skip it.
101
      $instance_data = unserialize($instance->data);
102
      $update_instance = FALSE;
103
      foreach ($instance_data['display'] as $display_name => $display_data) {
104
        if ($display_data['type'] && (0 !== strpos($display_data['type'], 'link_'))) {
105
          $instance_data['display'][$display_name]['type'] = 'link_' . $display_data['type'];
106
          $update_instance = TRUE;
107
        }
108
      }
109
      if ($update_instance) {
110
        db_update('field_config_instance')
111
          ->fields(array('data' => serialize($instance_data)))
112
          ->condition('id', $instance->id)
113
          ->execute();
114
      }
115
    }
116
  }
117
}