View source
<?php
function date_install() {
drupal_load('module', 'content');
content_notify('install', 'date');
}
function date_uninstall() {
drupal_load('module', 'content');
content_notify('uninstall', 'date');
}
function date_enable() {
drupal_load('module', 'content');
content_notify('enable', 'date');
}
function date_disable() {
drupal_load('module', 'content');
content_notify('disable', 'date');
}
function date_update_last_removed() {
return 5210;
}
function date_update_6000() {
include_once drupal_get_path('module', 'content') . '/content.install';
if ($abort = content_check_update('date')) {
return $abort;
}
drupal_load('module', 'content');
$ret = array();
$result = db_query("SELECT field_name, global_settings from {" . content_field_tablename() . "} where type LIKE 'date_%'");
while ($field = db_fetch_array($result)) {
$field_settings = unserialize($field['global_settings']);
$granularity = array_filter($field_settings['granularity']);
$field_settings['granularity'] = $granularity;
db_query("UPDATE {" . content_field_tablename() . "} SET global_settings = '%s' WHERE field_name = '%s'", serialize($field_settings), $field['field_name']);
}
content_clear_type_cache();
return $ret;
}
function date_update_6001() {
include_once drupal_get_path('module', 'content') . '/content.install';
if ($abort = content_check_update('date')) {
return $abort;
}
drupal_load('module', 'content');
$ret = array();
if (db_result(db_query("SELECT COUNT(*) FROM {" . content_instance_tablename() . "} WHERE widget_type = 'date_js'"))) {
$replace = module_exists('date_popup') ? 'date_popup' : 'date_text';
$result = db_query("SELECT field_name, type_name, widget_type from {" . content_instance_tablename() . "} where widget_type = 'date_js'");
while ($widget = db_fetch_array($result)) {
db_query("UPDATE {" . content_instance_tablename() . "} SET widget_type = '{$replace}' WHERE field_name = '%s' AND type_name = '%s'", $widget['field_name'], $widget['type_name']);
}
drupal_set_message(t('All date fields using the jscalendar widget have been changed to use the text widget instead, since the jscalendar widget is no longer supported. Enable the Date Popup module to make a jQuery popup calendar available and edit the field settings to select it.'));
content_clear_type_cache();
}
return $ret;
}
function date_update_6002() {
include_once drupal_get_path('module', 'content') . '/content.install';
if ($abort = content_check_update('date')) {
return $abort;
}
drupal_load('module', 'content');
$ret = array();
$types = content_types();
$repeating_fields = array();
foreach ($types as $type) {
foreach ($type['fields'] as $field_name => $field) {
if (!empty($field['repeat'])) {
$repeating_fields[] = $field_name;
}
}
}
if (count($repeating_fields)) {
$replace = array(
'date_select' => 'date_select_repeat',
'date_text' => 'date_text_repeat',
'date_popup' => 'date_popup_repeat',
);
$result = db_query("SELECT * from {" . content_instance_tablename() . "} WHERE widget_type IN('date_select', 'date_text', 'date_popup') AND field_name IN('" . implode("','", $repeating_fields) . "')");
while ($widget = db_fetch_array($result)) {
db_query("UPDATE {" . content_field_tablename() . "} SET multiple = 1 WHERE field_name = '%s'", $widget['field_name']);
db_query("UPDATE {" . content_instance_tablename() . "} SET widget_type = '" . $replace[$widget['widget_type']] . "' WHERE field_name = '%s' AND type_name = '%s'", $widget['field_name'], $widget['type_name']);
}
drupal_set_message(t('All repeating date fields have been updated to use the new repeating widgets.'));
content_clear_type_cache();
}
return $ret;
}
function date_update_6003() {
$ret = array();
drupal_load('module', 'content');
$fields = content_fields();
foreach ($fields as $field) {
if (strstr($field['type'], 'date') && !empty($field['repeat'])) {
$db_info = content_database_info($field);
$table = $db_info['table'];
$column = $field['field_name'] . '_rrule';
$result = db_query("SELECT DISTINCT nid, vid, {$column} FROM {" . $table . "} WHERE {$column} <> ''");
while ($row = db_fetch_array($result)) {
$ret[] = update_sql("UPDATE {" . $table . "} SET {$column}='" . $row[$column] . "' WHERE nid=" . $row['nid'] . " AND vid=" . $row['vid']);
}
}
}
return $ret;
}
function date_update_6004() {
$ret = array();
drupal_load('module', 'content');
$fields = content_fields();
foreach ($fields as $field) {
if (strstr($field['type'], 'date') && !empty($field['tz_handling']) && $field['tz_handling'] == 'none') {
$row = db_result(db_query("SELECT global_settings FROM {" . content_field_tablename() . "} WHERE field_name='" . $field['field_name'] . "'"));
$settings = unserialize($row);
$settings['timezone_db'] = '';
$settings = serialize($settings);
db_query("UPDATE {" . content_field_tablename() . "} SET global_settings='%s' WHERE field_name='%s'", $settings, $field['field_name']);
}
}
drupal_set_message(t("The database has been updated to correct the stored timezone for fields using timezone 'none'."));
content_clear_type_cache();
return $ret;
}
function date_update_6005() {
include_once drupal_get_path('module', 'content') . '/content.install';
if ($abort = content_check_update('date')) {
return $abort;
}
if (!db_table_exists('date_format') && !db_table_exists('date_formats') || !db_table_exists('date_format_types')) {
drupal_set_message(t('Some updates are still pending. Please return to <a href="@update-php">update.php</a> and run the remaining updates.', array(
'@update-php' => base_path() . 'update.php?op=selection',
)), 'error', FALSE);
$ret['#abort'] = array(
'success' => FALSE,
'query' => t('Some updates are still pending.<br/>Please re-run the update script.'),
);
return $ret;
}
drupal_load('module', 'content');
$ret = array();
$new_map = array(
'short' => 'short',
'medium' => 'medium',
'long' => 'long',
'time' => 'time',
'time_timezone' => 'time_timezone',
'iso' => 'iso',
'timestamp' => 'timestamp',
'ical' => 'ical',
'feed' => 'feed',
);
date_install_create_format(NULL, t('Time'), 'time', date_limit_format(variable_get('date_format_short', 'm/d/Y - H:i'), array(
'hour',
'minute',
'second',
)));
date_install_create_format(NULL, t('Time with timezone'), 'time_timezone', date_limit_format(variable_get('date_format_short', 'm/d/Y - H:i') . ' e', array(
'hour',
'minute',
'second',
'timezone',
)));
date_install_create_format(NULL, t('iCal'), 'ical', 'Ymd\\THis');
date_install_create_format(NULL, t('Timestamp'), 'timestamp', 'U');
date_install_create_format(NULL, t('Feed'), 'feed', 'D, j M Y H:i:s O');
date_install_create_format(NULL, t('ISO'), 'iso', DATE_FORMAT_ISO);
$result = db_query("SELECT field_name, global_settings from {" . content_field_tablename() . "} where type='date' OR type='datestamp' OR type='datetime'");
while ($field = db_fetch_array($result)) {
$field_settings = unserialize($field['global_settings']);
$field_name = $field['field_name'];
$default = !empty($field_settings['output_format_custom']) ? $field_settings['output_format_custom'] : $field_settings['output_format_date'];
$short = !empty($field_settings['output_format_custom_short']) ? $field_settings['output_format_custom_short'] : $field_settings['output_format_date_short'];
$med = !empty($field_settings['output_format_custom_medium']) ? $field_settings['output_format_custom_medium'] : $field_settings['output_format_date_medium'];
$long = !empty($field_settings['output_format_custom_long']) ? $field_settings['output_format_custom_long'] : $field_settings['output_format_date_long'];
$system_short = variable_get('date_format_short', 'm/d/Y - H:i');
$system_med = variable_get('date_format_medium', 'D, m/d/Y - H:i');
$system_long = variable_get('date_format_long', 'l, F j, Y - H:i');
$new_setting = 'default_format';
$map = $new_map;
if ($system_short != $short) {
$name = $field_name . '_short';
date_install_create_format($field, NULL, $name, $short);
$map['short'] = $name;
if ($default == $short) {
$field_settings[$new_setting] = $name;
$map['default'] = $name;
}
}
if ($system_med != $med) {
$name = $field_name . '_medium';
date_install_create_format($field, NULL, $name, $med);
$map['medium'] = $name;
if ($default == $med) {
$field_settings[$new_setting] = $name;
$map['default'] = $name;
}
}
if ($system_long != $long) {
$name = $field_name . '_long';
date_install_create_format($field, NULL, $name, $long);
$map['long'] = $name;
if ($default == $long) {
$field_settings[$new_setting] = $name;
$map['default'] = $name;
}
}
if (empty($field_settings[$new_setting])) {
if ($default == $system_med) {
$field_settings[$new_setting] = 'medium';
$map['default'] = 'medium';
}
elseif ($default == $system_long) {
$field_settings[$new_setting] = 'long';
$map['default'] = 'long';
}
elseif ($default == $system_short) {
$field_settings[$new_setting] = 'short';
$map['default'] = 'short';
}
else {
$name = $field_name . '_default';
date_install_create_format($field, NULL, $name, $default);
$field_settings[$new_setting] = $name;
$map['default'] = $name;
}
}
variable_set('date_format_map_' . $field['field_name'], $map);
$ret[] = array(
'success' => TRUE,
'query' => t('Field %field formats were converted to custom formats.', array(
'%field' => $field_name,
)),
);
foreach ($map as $key => $value) {
if (in_array($key, array(
'default',
'short',
'medium',
'long',
))) {
$ret[] = array(
'success' => TRUE,
'query' => t("The old format type %from_format for field %field was converted to the new format type %to_format.", array(
'%field' => $field_name,
'%from_format' => $key,
'%to_format' => $value,
)),
);
}
}
unset($field_settings['output_format_date']);
unset($field_settings['output_format_custom']);
unset($field_settings['output_format_date_short']);
unset($field_settings['output_format_custom_short']);
unset($field_settings['output_format_date_medium']);
unset($field_settings['output_format_custom_medium']);
unset($field_settings['output_format_date_long']);
unset($field_settings['output_format_custom_long']);
db_query("UPDATE {" . content_field_tablename() . "} SET global_settings = '%s' WHERE field_name = '%s'", serialize($field_settings), $field_name);
$result2 = db_query("SELECT * FROM {" . content_instance_tablename() . "} WHERE field_name = '{$field_name}'");
while ($instance = db_fetch_array($result2)) {
$display_settings = unserialize($instance['display_settings']);
foreach ($display_settings as $key => $setting) {
if ($key != 'label' && array_key_exists($display_settings[$key]['format'], $map)) {
$display_settings[$key]['format'] = $map[$display_settings[$key]['format']];
}
}
db_query("UPDATE {" . content_instance_tablename() . "} SET display_settings = '%s' WHERE field_name = '%s' AND type_name = '%s'", serialize($display_settings), $field_name, $instance['type_name']);
$ret[] = array(
'success' => TRUE,
'query' => t("The display settings for field %field in content type %type_name were updated.", array(
'%field' => $field_name,
'%type_name' => $instance['type_name'],
)),
);
}
}
content_clear_type_cache();
drupal_set_message(t('Date display formats are now included with the system date and time settings. Please visit <a href="@date-time-page">the Date and time format page</a> to see the new format types.', array(
'@date-time-page' => url('admin/settings/date-time/formats'),
)));
return $ret;
}
function date_install_create_format($field, $title, $name, $format) {
if (empty($name) || empty($format)) {
return;
}
$fields = content_fields();
if (empty($title)) {
$type = str_replace($field['field_name'] . '_', '', $name);
$field = $fields[$field['field_name']];
$title = $field['widget']['label'];
}
variable_set('date_format_' . $name, $format);
db_query("INSERT INTO {date_format_types} (type, title, locked) VALUES('%s', '%s', 0)", $name, $title);
if (!db_result(db_query("SELECT dfid FROM {date_formats} WHERE format='%s' AND type='%s'", $format, $type))) {
db_query("INSERT INTO {date_formats} (format, type, locked) VALUES('%s', '%s', 0)", $format, 'custom');
}
}
function date_db_integrity($name) {
$ret = array();
if (!module_exists('content') || !module_exists('date_api')) {
return $ret;
}
drupal_load('module', 'content');
require_once './' . drupal_get_path('module', 'content') . '/includes/content.admin.inc';
$ret = array();
$fields = content_fields();
foreach ($fields as $field) {
$db_info = content_database_info($field);
if ($field['type'] == 'date' || $field['type'] == 'datestamp') {
$table = $db_info['table'];
$columns_start = $db_info['columns'];
$columns_end = $db_info['columns'];
$columns_start['value']['length'] = 90;
if (!empty($field['todate'])) {
if (!db_column_exists($table, $columns_start['value2']['column'])) {
unset($columns_start['value2']);
}
else {
$columns_start['value2']['length'] = 80;
}
}
if ($field['tz_handling'] == 'date') {
if (!db_column_exists($table, $columns_start['timezone']['column'])) {
unset($columns_start['timezone']);
}
else {
$columns_start['timezone']['length'] = 80;
}
if (!db_column_exists($table, $columns_start['offset']['column'])) {
unset($columns_start['offset']);
}
else {
$columns_start['offset']['length'] = 80;
}
if ($field['todate']) {
if (!db_column_exists($table, $columns_start['offset2']['column'])) {
unset($columns_start['offset2']);
}
else {
$columns_start['offset2']['length'] = 80;
}
}
}
if (!empty($field['repeat'])) {
if (!db_column_exists($table, $columns_start['rrule']['column'])) {
unset($columns_start['rrule']);
}
else {
$columns_start['rrule']['length'] = 80;
}
}
$start_field = $field;
$start_field['columns'] = $columns_start;
$end_field = $field;
$end_field['columns'] = $columns_end;
content_alter_db($start_field, $end_field);
$message = 'Date database integrity check. Updated table ' . $table . ' to set all columns to accept NULL values.';
$ret[] = array(
'success' => TRUE,
'query' => $message,
);
}
}
content_clear_type_cache();
return $ret;
}