View source
<?php
function date_api_set_variables() {
variable_get('date_max_year', 4000);
variable_get('date_min_year', 1);
variable_get('date_php_min_year', 1901);
variable_set('date_api_version', '5.2');
if (version_compare(PHP_VERSION, '5.2', '<') && !module_exists('date_php4')) {
module_enable(array(
'date_php4',
));
}
if (!module_exists('date_timezone')) {
module_enable(array(
'date_timezone',
));
}
variable_get('date_default_timezone_name', NULL);
}
function date_api_schema() {
$schema['date_format_types'] = array(
'description' => 'For storing configured date format types.',
'fields' => array(
'type' => array(
'description' => 'The date format type, e.g. medium.',
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
),
'title' => array(
'description' => 'The human readable name of the format type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'locked' => array(
'description' => 'Whether or not this is a system provided format.',
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
),
'primary key' => array(
'type',
),
);
$schema['date_formats'] = array(
'description' => 'For storing configured date formats.',
'fields' => array(
'dfid' => array(
'description' => 'The date format identifier.',
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
),
'format' => array(
'description' => 'The date format string.',
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'type' => array(
'description' => 'The date format type, e.g. medium.',
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
),
'locked' => array(
'description' => 'Whether or not this format can be modified.',
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
),
'primary key' => array(
'dfid',
),
'unique keys' => array(
'formats' => array(
'format',
'type',
),
),
);
$schema['date_format_locale'] = array(
'description' => 'For storing configured date formats for each locale.',
'fields' => array(
'format' => array(
'description' => 'The date format string.',
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'type' => array(
'description' => 'The date format type, e.g. medium.',
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
),
'language' => array(
'description' => 'A {languages}.language for this format to be used with.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
),
),
'primary key' => array(
'type',
'language',
),
);
return $schema;
}
function date_api_schema_alter(&$schema) {
$schema['users']['fields']['timezone_name'] = array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
'description' => t('Per-user timezone name.'),
);
}
function date_api_install() {
drupal_install_schema('date_api');
date_api_set_variables();
$ret = array();
db_add_field($ret, "users", "timezone_name", array(
'type' => 'varchar',
'length' => 50,
'not null' => TRUE,
'default' => '',
));
global $db_type;
if ($db_type == 'mysql' || $db_type == 'mysqli') {
$sql = "ALTER TABLE {date_formats} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
$ret[] = update_sql($sql);
$sql = "ALTER TABLE {date_format_locale} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
$ret[] = update_sql($sql);
}
return $ret;
}
function date_api_enable() {
drupal_get_schema('', TRUE);
if (db_table_exists('date_format_types')) {
date_formats_rebuild();
}
date_api_set_variables();
}
function date_api_uninstall() {
$ret = array();
db_drop_field($ret, "users", "timezone_name");
cache_clear_all('date_timezone_identifiers_list', 'cache');
$variables = array(
'date_api_version',
'date_min_year',
'date_max_year',
'date_php_min_year',
'date_db_tz_support',
'date_api_use_iso8601',
);
foreach ($variables as $variable) {
variable_del($variable);
}
if (db_table_exists('views_display')) {
$displays = array(
'date_nav',
);
db_query("DELETE FROM {views_display} WHERE display_plugin IN ('" . implode("','", $displays) . "')");
db_query("DELETE FROM {cache_views}");
}
drupal_uninstall_schema('date_api');
return $ret;
}
function date_api_requirements($phase) {
$requirements = array();
$t = get_t();
switch ($phase) {
case 'runtime':
$tz_name = variable_get('date_default_timezone_name', NULL);
$error = FALSE;
if (version_compare(PHP_VERSION, '5.2', '<') && !module_exists('date_php4')) {
$error = TRUE;
$severity = REQUIREMENT_ERROR;
$value = $t('The Date API module requires the <a href="@link">Date PHP4 module</a> for PHP versions less than 5.2.', array(
'@link' => url('admin/build/modules'),
));
}
if ($error) {
$requirements['date_php4'] = array(
'title' => $t('Date API requirements'),
'value' => $value,
'severity' => $severity,
);
}
break;
case 'install':
break;
}
return $requirements;
}
function date_api_update_last_removed() {
return 5201;
}
function date_api_update_6000() {
$ret = array();
if (module_exists('views') && drupal_get_installed_schema_version('views', TRUE) < 6000) {
$ret = array();
drupal_set_message(t('date module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates.', array(
'@update-php' => base_path() . 'update.php?op=selection',
)), 'warning', FALSE);
$ret['#abort'] = array(
'success' => FALSE,
'query' => t('date.module has updates, but cannot be updated until views.module is updated first.'),
);
return $ret;
}
date_api_set_variables();
return $ret;
}
function date_api_update_6001() {
$ret = array();
if (module_exists('views') && drupal_get_installed_schema_version('views', TRUE) < 6000) {
$ret = array();
drupal_set_message(t('date module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates.', array(
'@update-php' => base_path() . 'update.php?op=selection',
)), 'warning', FALSE);
$ret['#abort'] = array(
'success' => FALSE,
'query' => t('date.module has updates, but cannot be updated until views.module is updated first.'),
);
return $ret;
}
if (db_table_exists('cache_content')) {
db_query('DELETE FROM {cache_content}');
}
if (db_table_exists('cache_views')) {
db_query('DELETE FROM {cache_views}');
}
if (db_table_exists('views_object_cache')) {
db_query('DELETE FROM {views_object_cache}');
}
db_query("DELETE FROM {cache} where cid LIKE 'theme_registry%'");
return $ret;
}
function date_api_update_6002() {
$ret = array();
if (module_exists('views') && drupal_get_installed_schema_version('views', TRUE) < 6000) {
$ret = array();
drupal_set_message(t('date module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates.', array(
'@update-php' => base_path() . 'update.php?op=selection',
)), 'warning', FALSE);
$ret['#abort'] = array(
'success' => FALSE,
'query' => t('date.module has updates, but cannot be updated until views.module is updated first.'),
);
return $ret;
}
$schema['date_format_types'] = array(
'fields' => array(
'type' => array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
),
'title' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'locked' => array(
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
),
'primary key' => array(
'type',
),
);
$schema['date_format'] = array(
'fields' => array(
'dfid' => array(
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
),
'format' => array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'type' => array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
),
'locked' => array(
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
),
'primary key' => array(
'dfid',
),
'unique keys' => array(
'format' => array(
'format',
'type',
),
),
);
$schema['date_format_locale'] = array(
'fields' => array(
'format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
),
'type' => array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
),
'language' => array(
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
),
),
'primary key' => array(
'type',
'language',
),
);
db_create_table($ret, 'date_format_types', $schema['date_format_types']);
db_create_table($ret, 'date_format', $schema['date_format']);
db_create_table($ret, 'date_format_locale', $schema['date_format_locale']);
return $ret;
}
function date_api_update_6003() {
$ret = array();
db_change_field($ret, 'date_format_types', 'type', 'type', array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
));
db_change_field($ret, 'date_format', 'type', 'type', array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
));
db_change_field($ret, 'date_format', 'format', 'format', array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
));
db_change_field($ret, 'date_format_locale', 'type', 'type', array(
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
));
db_change_field($ret, 'date_format_locale', 'format', 'format', array(
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
));
db_drop_unique_key($ret, 'date_format', 'format');
db_add_unique_key($ret, 'date_format', 'format', array(
'format',
'type',
));
return $ret;
}
function date_api_update_6004() {
$ret = array();
$schema['date_formats'] = array(
'description' => 'For storing configured date formats.',
'fields' => array(
'dfid' => array(
'description' => 'The date format identifier.',
'type' => 'serial',
'not null' => TRUE,
'unsigned' => TRUE,
),
'format' => array(
'description' => 'The date format string.',
'type' => 'varchar',
'length' => 100,
'not null' => TRUE,
),
'type' => array(
'description' => 'The date format type, e.g. medium.',
'type' => 'varchar',
'length' => 200,
'not null' => TRUE,
),
'locked' => array(
'description' => 'Whether or not this format can be modified.',
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
),
'primary key' => array(
'dfid',
),
'unique keys' => array(
'formats' => array(
'format',
'type',
),
),
);
if (!db_table_exists('date_format')) {
db_create_table($ret, 'date_formats', $schema['date_formats']);
date_formats_rebuild();
}
else {
db_drop_unique_key($ret, 'date_format', 'format');
if (db_table_exists('date_formats')) {
db_drop_table($ret, 'date_format');
}
else {
db_rename_table($ret, 'date_format', 'date_formats');
db_add_unique_key($ret, 'date_formats', 'formats', array(
'format',
'type',
));
}
}
return $ret;
}
function date_api_update_6005() {
global $db_type;
$ret = array();
if ($db_type == 'mysql' || $db_type == 'mysqli') {
$sql = "ALTER TABLE {date_formats} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
$ret[] = update_sql($sql);
$sql = "ALTER TABLE {date_format_locale} CHANGE format format VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL";
$ret[] = update_sql($sql);
}
return $ret;
}
function date_api_update_6006() {
global $db_type;
$ret = array();
if ($db_type == 'pgsql' && db_table_exists('date_format_dfid_seq')) {
$sql = "ALTER TABLE {date_format}_dfid_seq RENAME TO {date_formats}_dfid_seq";
$ret[] = update_sql($sql);
}
return $ret;
}