function date_update_7201 in Date 7.3
Add the 'all_day' column to date fields.
1 call to date_update_7201()
- DateUpdatesTestCase::testUpdate7201 in tests/
DateUpdatesTestCase.test - Test update 7200.
1 string reference to 'date_update_7201'
- DateUpdatesTestCase::testUpdate7201 in tests/
DateUpdatesTestCase.test - Test update 7200.
File
- ./
date.install, line 333 - Install, update and uninstall functions for the Date module.
Code
function date_update_7201() {
// Get all fields provided by the Data module.
$query = db_select('field_config', 'f')
->fields('f', array(
'id',
'field_name',
'data',
))
->condition('f.type', array(
'datetime',
'date',
'datestamp',
));
// Complete the query.
$fields = $query
->execute()
->fetchAllAssoc('id');
foreach ($fields as $id => $info) {
$field_info = field_info_field($info->field_name);
// Add indexes only for SQL storage fields.
if ($field_info['storage']['type'] != 'field_sql_storage') {
continue;
}
// The database tables that have these fields.
$tables = array(
key($field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT']),
key($field_info['storage']['details']['sql']['FIELD_LOAD_REVISION']),
);
// Turns a field named "field_event_date" into a database column named
// "field_event_date_all_day".
$field_name = $info->field_name . '_all_day';
// The field specification taken from hook_field_schema().
$spec = array(
'type' => 'int',
'size' => 'tiny',
'not null' => FALSE,
'sortable' => FALSE,
'views' => FALSE,
);
// Add a column to the database in this table for the new "is_all_day"
// element. The first item is for the field_data table for this field, the
// second item is for the field_revision table.
foreach ($tables as $table_name) {
if (!db_field_exists($table_name, $field_name)) {
db_add_field($table_name, $field_name, $spec);
drupal_set_message(t("Added the new 'all_day' column to the @field_name field.", array(
'@field_name' => $info->field_name,
)));
}
else {
drupal_set_message(t("The 'all_day' column already existed on the @field_name field.", array(
'@field_name' => $info->field_name,
)));
}
}
}
}