Projet

Général

Profil

Paste
Télécharger (6,87 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / date.install @ 87dbc3bf

1
<?php
2

    
3
/**
4
 * @file
5
 * Install, update and uninstall functions for the Date module.
6
 */
7

    
8
/**
9
 * Implements hook_field_schema().
10
 */
11
function date_field_schema($field) {
12
  $db_columns = array();
13
  switch ($field['type']) {
14
    case 'datestamp':
15
      $db_columns['value'] = array(
16
        'type' => 'int',
17
        'not null' => FALSE,
18
        'sortable' => TRUE,
19
        'views' => TRUE,
20
      );
21
      break;
22
    case 'datetime':
23
      $db_columns['value'] = array(
24
        'type' => 'datetime',
25
        'mysql_type' => 'datetime',
26
        'pgsql_type' => 'timestamp without time zone',
27
        'sqlite_type' => 'varchar',
28
        'sqlsrv_type' => 'smalldatetime',
29
        'not null' => FALSE,
30
        'sortable' => TRUE,
31
        'views' => TRUE,
32
      );
33
      break;
34
    default:
35
      $db_columns['value'] = array(
36
        'type' => 'varchar',
37
        'length' => 20,
38
        'not null' => FALSE,
39
        'sortable' => TRUE,
40
        'views' => TRUE,
41
      );
42
      break;
43
  }
44

    
45
  // If a second date is needed for 'End date', make a copy of the first one.
46
  if (!empty($field['settings']['todate'])) {
47
    $db_columns['value2'] = $db_columns['value'];
48

    
49
    // We don't want Field API to create additional columns, just the first.
50
    // We modify them our own way in views data.
51
    $db_columns['value2']['views'] = FALSE;
52
  }
53
  // Timezone and offset columns are used only if date-specific dates are used.
54
  if (isset($field['settings']['tz_handling']) && $field['settings']['tz_handling'] == 'date') {
55
    $db_columns['timezone'] = array(
56
      'type' => 'varchar',
57
      'length' => 50,
58
      'not null' => FALSE,
59
      'sortable' => TRUE,
60
      'views' => FALSE,
61
    );
62
    $db_columns['offset'] = array(
63
      'type' => 'int',
64
      'not null' => FALSE,
65
      'sortable' => TRUE,
66
      'views' => FALSE,
67
    );
68
    if (!empty($field['settings']['todate'])) {
69
      $db_columns['offset2'] = array('type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE);
70
    }
71
  }
72
  if (isset($field['settings']['repeat']) && $field['settings']['repeat'] == 1) {
73
    $db_columns['rrule'] = array(
74
      'type' => 'text',
75
      'not null' => FALSE,
76
      'sortable' => FALSE,
77
      'views' => FALSE,
78
    );
79
  }
80
  return array('columns' => $db_columns);
81
}
82

    
83
/**
84
 * Implements hook_update_last_removed().
85
 */
86
function date_update_last_removed() {
87
  return 6005;
88
}
89

    
90
/**
91
 * Get rid of the individual formatters for each format type,
92
 * these are now settings in the default formatter.
93
 */
94
function date_update_7000() {
95
  $instances = field_info_instances();
96
  foreach ($instances as $entity_type => $entities) {
97
    foreach ($entities as $bundle => $fields) {
98
      foreach ($fields as $field_name => $instance) {
99
        if (in_array($instance['widget']['type'], array('date_popup'))) {
100
          $changed = FALSE;
101
          foreach ($instance['display'] as $context => $display) {
102
            if ($display['type'] != 'date_default' && $display['type'] != 'date_interval' && $display['type'] != 'hidden') {
103
              $instance['display'][$context]['type'] = 'date_default';
104
              $instance['display'][$context]['settings']['format_type'] = str_replace('date_', '', $display['type']);
105
              $changed = TRUE;
106
            }
107
          }
108
          if ($changed) {
109
            field_update_instance($instance);
110
          }
111
        }
112
      }
113
    }
114
  }
115
}
116

    
117
/**
118
 * Get rid of the separate widgets for repeating dates. The code now handles
119
 * repeating dates correctly using the regular widgets.
120
 */
121
function date_update_7001() {
122
  $query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC));
123
  $query->join('field_config', 'fc', 'fc.id = fci.field_id');
124
  $query->fields('fci');
125
  $query->condition(db_or()->condition('fc.type', 'date')->condition('fc.type', 'datestamp')->condition('fc.type', 'datetime'));
126
  $results = $query->execute();
127

    
128
  foreach ($results as $record) {
129
    $instance = unserialize($record['data']);
130
    if (in_array($instance['widget']['type'], array('date_popup_repeat', 'date_text_repeat', 'date_select_repeat'))) {
131
      $instance['widget']['type'] = str_replace('_repeat', '', $instance['widget']['type']);
132
      db_update('field_config_instance')
133
        ->fields(array(
134
          'data' => serialize($instance),
135
        ))
136
        ->condition('field_name', $record['field_name'])
137
        ->condition('entity_type', $record['entity_type'])
138
        ->condition('bundle', $record['bundle'])
139
        ->execute();
140
    }
141
  }
142
  field_cache_clear();
143
  drupal_set_message(t('The widgets for repeating dates have changed. Please check the Display Fields page for each content type that has repeating date fields and confirm that the right widget has been selected.'), 'warning');
144
}
145

    
146
/**
147
 * Add a notification about the new Date All Day module, and enable it.
148
 */
149
function date_update_7002() {
150
  drupal_set_message(t("The <em>All Day</em> functionality has been moved into a separate module. This new module provides the option to add an <em>All Day</em> checkbox to toggle time on and off for date fields. It also contains the theme that displays the <em>All Day</em> text on fields that have no time. For consistency with prior code, it has been automatically enabled. If you don't want the <em>All Day</em> functionality you can disable this module."));
151
  module_enable(array('date_all_day'));
152
}
153

    
154
/**
155
 * Adds a notification about the new Date Repeat Field module, and enable it.
156
 */
157
function date_update_7003() {
158
  drupal_set_message(t("The <em>Date Repeat</em> integration for Date fields is being moved into a separate module. For consistency with prior code, it has been automatically enabled if the Date Repeat API module is enabled. If you don't use <em>Date Repeat</em> functionality in your fields, you can disable this module."));
159
  if (module_exists('date_repeat')) {
160
    module_enable(array('date_repeat_field'));
161
  }
162
}
163

    
164
/**
165
 * Date text widgets should always use an increment of 1.
166
 */
167
function date_update_7004() {
168

    
169
  // Select date fields.
170
  $query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC));
171
  $query->join('field_config', 'fc', 'fc.id = fci.field_id');
172
  $query->fields('fci');
173
  $query->condition(db_or()->condition('fc.type', 'date')->condition('fc.type', 'datestamp')->condition('fc.type', 'datetime'));
174
  $results = $query->execute();
175

    
176
  // Find the ones that use the date_text widget.
177
  foreach ($results as $record) {
178
    $instance = unserialize($record['data']);
179
    if (in_array($instance['widget']['type'], array('date_text'))) {
180
      $instance['widget']['settings']['increment'] = 1;
181
      db_update('field_config_instance')
182
        ->fields(array(
183
          'data' => serialize($instance),
184
        ))
185
        ->condition('field_name', $record['field_name'])
186
        ->condition('entity_type', $record['entity_type'])
187
        ->condition('bundle', $record['bundle'])
188
        ->execute();
189
    }
190
  }
191
  field_cache_clear();
192
  drupal_set_message(t('Date text widgets have been updated to use an increment of 1.'));
193
}
194