'int', 'size' => 'big', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE, ); break; case 'datetime': $db_columns['value'] = array( 'type' => 'datetime', 'mysql_type' => 'datetime', 'pgsql_type' => 'timestamp without time zone', 'sqlite_type' => 'varchar', 'sqlsrv_type' => 'smalldatetime', 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE, ); break; default: $db_columns['value'] = array( 'type' => 'varchar', 'length' => 20, 'not null' => FALSE, 'sortable' => TRUE, 'views' => TRUE, ); } // If a second date is needed for 'End date', make a copy of the first one. if (!empty($field['settings']['todate'])) { $db_columns['value2'] = $db_columns['value']; // We don't want Field API to create additional columns, just the first. // We modify them our own way in views data. $db_columns['value2']['views'] = FALSE; // Create a compound index on value and value2 and an index on value2. $indexes = array( 'value' => array('value', 'value2'), 'value2' => array('value2'), ); } else { // Otherwise just an index on value. $indexes = array('value' => array('value')); } // Timezone and offset columns are used only if date-specific dates are used. if (isset($field['settings']['tz_handling']) && $field['settings']['tz_handling'] == 'date') { $db_columns['timezone'] = array( 'type' => 'varchar', 'length' => 50, 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE, ); $db_columns['offset'] = array( 'type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE, ); if (!empty($field['settings']['todate'])) { $db_columns['offset2'] = array( 'type' => 'int', 'not null' => FALSE, 'sortable' => TRUE, 'views' => FALSE, ); } } if (isset($field['settings']['repeat']) && $field['settings']['repeat'] == 1) { $db_columns['rrule'] = array( 'type' => 'text', 'not null' => FALSE, 'sortable' => FALSE, 'views' => FALSE, ); } return array('columns' => $db_columns, 'indexes' => $indexes); } /** * Implements hook_update_last_removed(). */ function date_update_last_removed() { return 6005; } /** * Get rid of the individual formatters for each format type. * * These are now settings in the default formatter. */ function date_update_7000() { $instances = field_info_instances(); foreach ($instances as $entity_type => $entities) { foreach ($entities as $bundle => $fields) { foreach ($fields as $field_name => $instance) { if (in_array($instance['widget']['type'], array('date_popup'))) { $changed = FALSE; foreach ($instance['display'] as $context => $display) { if ($display['type'] != 'date_default' && $display['type'] != 'date_interval' && $display['type'] != 'hidden') { $instance['display'][$context]['type'] = 'date_default'; $instance['display'][$context]['settings']['format_type'] = str_replace('date_', '', $display['type']); $changed = TRUE; } } if ($changed) { field_update_instance($instance); } } } } } } /** * Get rid of the separate widgets for repeating dates. * * The code now handles repeating dates correctly using the regular widgets. */ function date_update_7001() { $query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC)); $query->join('field_config', 'fc', 'fc.id = fci.field_id'); $query->fields('fci'); $query->condition(db_or()->condition('fc.type', 'date')->condition('fc.type', 'datestamp')->condition('fc.type', 'datetime')); $results = $query->execute(); $allowed_types = array( 'date_popup_repeat', 'date_text_repeat', 'date_select_repeat', ); foreach ($results as $record) { $instance = unserialize($record['data']); if (in_array($instance['widget']['type'], $allowed_types)) { $instance['widget']['type'] = str_replace('_repeat', '', $instance['widget']['type']); db_update('field_config_instance') ->fields(array( 'data' => serialize($instance), )) ->condition('field_name', $record['field_name']) ->condition('entity_type', $record['entity_type']) ->condition('bundle', $record['bundle']) ->execute(); } } field_cache_clear(); 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'); } /** * Add a notification about the new Date All Day module, and enable it. */ function date_update_7002() { drupal_set_message(t("The All Day functionality has been moved into a separate module. This new module provides the option to add an All Day checkbox to toggle time on and off for date fields. It also contains the theme that displays the All Day text on fields that have no time. For consistency with prior code, it has been automatically enabled. If you don't want the All Day functionality you can disable this module.")); module_enable(array('date_all_day')); } /** * Adds a notification about the new Date Repeat Field module, and enable it. */ function date_update_7003() { drupal_set_message(t("The Date Repeat 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 Date Repeat functionality in your fields, you can disable this module.")); if (module_exists('date_repeat')) { module_enable(array('date_repeat_field')); } } /** * Date text widgets should always use an increment of 1. */ function date_update_7004() { // Select date fields. $query = db_select('field_config_instance', 'fci', array('fetch' => PDO::FETCH_ASSOC)); $query->join('field_config', 'fc', 'fc.id = fci.field_id'); $query->fields('fci'); $query->condition(db_or()->condition('fc.type', 'date')->condition('fc.type', 'datestamp')->condition('fc.type', 'datetime')); $results = $query->execute(); // Find the ones that use the date_text widget. foreach ($results as $record) { $instance = unserialize($record['data']); if (in_array($instance['widget']['type'], array('date_text'))) { $instance['widget']['settings']['increment'] = 1; db_update('field_config_instance') ->fields(array( 'data' => serialize($instance), )) ->condition('field_name', $record['field_name']) ->condition('entity_type', $record['entity_type']) ->condition('bundle', $record['bundle']) ->execute(); } } field_cache_clear(); drupal_set_message(t('Date text widgets have been updated to use an increment of 1.')); } /** * Revisited: Date text widgets should always use an increment of 1. */ function date_update_7005() { // @see https://www.drupal.org/node/1355256 date_update_7004(); } /** * Add date value indexes to existed field tables. */ function date_update_7006() { // 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')); // Special handling for the Encrypt module. if (module_exists('field_encrypt')) { $query->condition('f.data', '%' . db_like(' field_encrypt";a:1:{s:7:"encrypt";i:0 ') . '%', 'LIKE'); } // 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; } $tables = array( key($field_info['storage']['details']['sql']['FIELD_LOAD_CURRENT']), key($field_info['storage']['details']['sql']['FIELD_LOAD_REVISION']), ); $data = unserialize($info->data); $field_name = $info->field_name . '_value'; $field_name2 = $info->field_name . '_value2'; // Build indexes. $indexes = $data['indexes'] = array(); if (!empty($data['settings']['todate'])) { $indexes[$field_name] = array($field_name, $field_name2); $indexes[$field_name2] = array($field_name2); $data['indexes']['value'] = array('value', 'value2'); $data['indexes']['value2'] = array('value2'); } else { $indexes[$field_name] = array($field_name); $data['indexes']['value'] = array('value'); } // Add missed indexes to tables. foreach ($indexes as $name => $index) { foreach ($tables as $table) { if (!db_index_exists($table, $name)) { db_add_index($table, $name, $index); } } } // Fix date fields storage 'field_config' indexes. db_update('field_config') ->fields(array('data' => serialize($data))) ->condition('id', $id) ->execute(); } } /** * Update datestamp field schema to use 'big' integers. */ function date_update_7007() { $fields = field_read_fields(array('type' => 'datestamp')); foreach ($fields as $field_name => $field) { foreach (array_intersect_key($field['columns'], drupal_map_assoc(array('value', 'value2'))) as $column_name => $schema) { $schema['size'] = 'big'; $column = $field_name . '_' . $column_name; if (db_table_exists('field_data_' . $field_name)) { db_change_field('field_data_' . $field_name, $column, $column, $schema); } if (db_table_exists('field_revision_' . $field_name)) { db_change_field('field_revision_' . $field_name, $column, $column, $schema); } } } } /** * The date_migrate_example module was renamed. */ function date_update_7200() { db_delete('system')->condition('name', 'date_migrate_example')->execute(); }