You are here

function date_db_integrity in Date 5

Same name and namespace in other branches
  1. 5.2 date/date.install \date_db_integrity()
  2. 6.2 date/date.install \date_db_integrity()
  3. 6 date/date.install \date_db_integrity()
1 call to date_db_integrity()
date_update_5102 in ./date.install
DB integrity update, supercedes most previous db integrity updates.

File

./date.install, line 340

Code

function date_db_integrity($name) {
  $ret = array();
  include_once drupal_get_path('module', 'content') . '/content.module';
  include_once drupal_get_path('module', 'content') . '/content_admin.inc';
  include_once drupal_get_path('module', 'date') . '/date.module';
  $fields = content_fields();
  foreach ($fields as $field) {
    $db_info = content_database_info($field);
    if ($field['type'] == 'date' || $field['type'] == 'datestamp') {
      $table = $db_info['table'];

      // start with the new column patterns.
      $columns_start = date_columns($field);
      $columns_end = date_columns($field);

      // alter the start column values to invalid values to force the new columns to be reset.
      $columns_start['value']['length'] = 90;
      if ($field['todate']) {
        $columns_start['value2']['length'] = 80;
      }
      if ($field['tz_handling'] == 'date') {
        $columns_start['timezone']['length'] = 80;
        $columns_start['offset']['length'] = 80;
      }
      content_alter_db_field($field, $columns_start, $field, $columns_end);
      $message = 'Date database integrity check. Updated table ' . $table . ' to set all columns to accept NULL values.';
      $ret[] = array(
        'success' => TRUE,
        'query' => $message,
      );
    }
  }
  drupal_set_message(t('All date module fields were updated to allow empty (NULL) values.'));
  content_clear_type_cache();
  return $ret;
}