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
|
|
23
|
case 'datetime':
|
24
|
$db_columns['value'] = array(
|
25
|
'type' => 'datetime',
|
26
|
'mysql_type' => 'datetime',
|
27
|
'pgsql_type' => 'timestamp without time zone',
|
28
|
'sqlite_type' => 'varchar',
|
29
|
'sqlsrv_type' => 'smalldatetime',
|
30
|
'not null' => FALSE,
|
31
|
'sortable' => TRUE,
|
32
|
'views' => TRUE,
|
33
|
);
|
34
|
break;
|
35
|
|
36
|
default:
|
37
|
$db_columns['value'] = array(
|
38
|
'type' => 'varchar',
|
39
|
'length' => 20,
|
40
|
'not null' => FALSE,
|
41
|
'sortable' => TRUE,
|
42
|
'views' => TRUE,
|
43
|
);
|
44
|
break;
|
45
|
}
|
46
|
|
47
|
// If a second date is needed for 'End date', make a copy of the first one.
|
48
|
if (!empty($field['settings']['todate'])) {
|
49
|
$db_columns['value2'] = $db_columns['value'];
|
50
|
|
51
|
// We don't want Field API to create additional columns, just the first.
|
52
|
// We modify them our own way in views data.
|
53
|
$db_columns['value2']['views'] = FALSE;
|
54
|
}
|
55
|
// Timezone and offset columns are used only if date-specific dates are used.
|
56
|
if (isset($field['settings']['tz_handling']) && $field['settings']['tz_handling'] == 'date') {
|
57
|
$db_columns['timezone'] = array(
|
58
|
'type' => 'varchar',
|
59
|
'length' => 50,
|
60
|
'not null' => FALSE,
|
61
|
'sortable' => TRUE,
|
62
|
'views' => FALSE,
|
63
|
);
|
64
|
$db_columns['offset'] = array(
|
65
|
'type' => 'int',
|
66
|
'not null' => FALSE,
|
67
|
'sortable' => TRUE,
|
68
|
'views' => FALSE,
|
69
|
);
|
70
|
if (!empty($field['settings']['todate'])) {
|
71
|
$db_columns['offset2'] = array(
|
72
|
'type' => 'int',
|
73
|
'not null' => FALSE,
|
74
|
'sortable' => TRUE,
|
75
|
'views' => FALSE
|
76
|
);
|
77
|
}
|
78
|
}
|
79
|
if (isset($field['settings']['repeat']) && $field['settings']['repeat'] == 1) {
|
80
|
$db_columns['rrule'] = array(
|
81
|
'type' => 'text',
|
82
|
'not null' => FALSE,
|
83
|
'sortable' => FALSE,
|
84
|
'views' => FALSE,
|
85
|
);
|
86
|
}
|
87
|
return array('columns' => $db_columns);
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* Implements hook_update_last_removed().
|
92
|
*/
|
93
|
function date_update_last_removed() {
|
94
|
return 6005;
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Get rid of the individual formatters for each format type.
|
99
|
*
|
100
|
* These are now settings in the default formatter.
|
101
|
*/
|
102
|
function date_update_7000() {
|
103
|
$instances = field_info_instances();
|
104
|
foreach ($instances as $entity_type => $entities) {
|
105
|
foreach ($entities as $bundle => $fields) {
|
106
|
foreach ($fields as $field_name => $instance) {
|
107
|
if (in_array($instance['widget']['type'], array('date_popup'))) {
|
108
|
$changed = FALSE;
|
109
|
foreach ($instance['display'] as $context => $display) {
|
110
|
if ($display['type'] != 'date_default' && $display['type'] != 'date_interval' && $display['type'] != 'hidden') {
|
111
|
$instance['display'][$context]['type'] = 'date_default';
|
112
|
$instance['display'][$context]['settings']['format_type'] = str_replace('date_', '', $display['type']);
|
113
|
$changed = TRUE;
|
114
|
}
|
115
|
}
|
116
|
if ($changed) {
|
117
|
field_update_instance($instance);
|
118
|
}
|
119
|
}
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* Get rid of the separate widgets for repeating dates.
|
127
|
*
|
128
|
* The code now handles repeating dates correctly using the regular widgets.
|
129
|
*/
|
130
|
function date_update_7001() {
|
131
|
$query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC));
|
132
|
$query->join('field_config', 'fc', 'fc.id = fci.field_id');
|
133
|
$query->fields('fci');
|
134
|
$query->condition(db_or()->condition('fc.type', 'date')->condition('fc.type', 'datestamp')->condition('fc.type', 'datetime'));
|
135
|
$results = $query->execute();
|
136
|
|
137
|
foreach ($results as $record) {
|
138
|
$instance = unserialize($record['data']);
|
139
|
if (in_array($instance['widget']['type'], array(
|
140
|
'date_popup_repeat',
|
141
|
'date_text_repeat',
|
142
|
'date_select_repeat'
|
143
|
))) {
|
144
|
$instance['widget']['type'] = str_replace('_repeat', '', $instance['widget']['type']);
|
145
|
db_update('field_config_instance')
|
146
|
->fields(array(
|
147
|
'data' => serialize($instance),
|
148
|
))
|
149
|
->condition('field_name', $record['field_name'])
|
150
|
->condition('entity_type', $record['entity_type'])
|
151
|
->condition('bundle', $record['bundle'])
|
152
|
->execute();
|
153
|
}
|
154
|
}
|
155
|
field_cache_clear();
|
156
|
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');
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* Add a notification about the new Date All Day module, and enable it.
|
161
|
*/
|
162
|
function date_update_7002() {
|
163
|
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."));
|
164
|
module_enable(array('date_all_day'));
|
165
|
}
|
166
|
|
167
|
/**
|
168
|
* Adds a notification about the new Date Repeat Field module, and enable it.
|
169
|
*/
|
170
|
function date_update_7003() {
|
171
|
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."));
|
172
|
if (module_exists('date_repeat')) {
|
173
|
module_enable(array('date_repeat_field'));
|
174
|
}
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* Date text widgets should always use an increment of 1.
|
179
|
*/
|
180
|
function date_update_7004() {
|
181
|
|
182
|
// Select date fields.
|
183
|
$query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC));
|
184
|
$query->join('field_config', 'fc', 'fc.id = fci.field_id');
|
185
|
$query->fields('fci');
|
186
|
$query->condition(db_or()->condition('fc.type', 'date')->condition('fc.type', 'datestamp')->condition('fc.type', 'datetime'));
|
187
|
$results = $query->execute();
|
188
|
|
189
|
// Find the ones that use the date_text widget.
|
190
|
foreach ($results as $record) {
|
191
|
$instance = unserialize($record['data']);
|
192
|
if (in_array($instance['widget']['type'], array('date_text'))) {
|
193
|
$instance['widget']['settings']['increment'] = 1;
|
194
|
db_update('field_config_instance')
|
195
|
->fields(array(
|
196
|
'data' => serialize($instance),
|
197
|
))
|
198
|
->condition('field_name', $record['field_name'])
|
199
|
->condition('entity_type', $record['entity_type'])
|
200
|
->condition('bundle', $record['bundle'])
|
201
|
->execute();
|
202
|
}
|
203
|
}
|
204
|
field_cache_clear();
|
205
|
drupal_set_message(t('Date text widgets have been updated to use an increment of 1.'));
|
206
|
}
|