date_api.install in Date 5.2
Same filename and directory in other branches
File
date_api.installView source
<?php
function date_api_set_variables() {
/**
* Set absolute minimum and maximum year for dates on this site.
*
* There is actually no maximum and minimum year in PHP 5, but a date with
* a year less than 0 would result in negative ISO and DATETIME dates,
* like -1250-01-01T00:00:00, which probably won't make sense or work
* correctly anywhere.
*
* The odd construct of using variable_get() instead of variable_set()
* is so we don't accidentally write over an existing value. If
* no value is set, variable_get() will set it.
*/
variable_get('date_max_year', 4000);
variable_get('date_min_year', 1);
variable_get('date_php_min_year', 1901);
/**
* Set an API version in a way that other modules can test for compatibility.
*/
variable_set('date_api_version', '5.2');
if (version_compare(PHP_VERSION, '5.2', '<') && !module_exists('date_php4')) {
module_enable(array(
'date_php4',
));
}
// The timezone module was originally going to be optional
// but too many things break without it.
if (!module_exists('date_timezone')) {
module_enable(array(
'date_timezone',
));
}
/**
* NULL is used for the default setting of date_default_timezone_name
* to have a way to tell that no site timezone name has been implemented.
* Otherwise, many functions would use 'UTC' incorrectly and
* produce unreliable and odd results. This way functions can test for a
* value and not use this if it is empty.
*
* The odd construct of using variable_get() instead of variable_set()
* is so we don't accidentally write over an existing value. If
* no value is set, variable_get() will set it to NULL.
*/
variable_get('date_default_timezone_name', NULL);
}
/**
* Implementation of hook_install().
*/
function date_api_install() {
$ret = array();
date_api_set_variables();
$ret = db_query("ALTER TABLE {users} ADD timezone_name varchar(50) NOT NULL default ''");
return $ret;
}
function date_api_enable() {
date_api_set_variables();
}
/**
* Implementation of hook_uninstall().
*/
function date_api_uninstall() {
$ret = array();
$ret[] = db_query("ALTER TABLE {users} DROP 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',
);
foreach ($variables as $variable) {
variable_del($variable);
}
return $ret;
}
/**
* Implementation of hook_requirements().
* Make sure Date PHP4 is installed if running less than PHP 5.2.
*/
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 !link for PHP versions less than 5.2.', array(
'!link' => l($t('Date PHP4 module'), 'admin/build/modules'),
));
}
if ($error) {
$requirements['date_php4'] = array(
'title' => $t('Date API requirements'),
'value' => $value,
'severity' => $severity,
);
}
break;
case 'install':
break;
}
return $requirements;
}
/**
* Implementation of hook_update().
*/
function date_api_update_5000() {
$ret = array();
$ret[] = update_sql("ALTER TABLE {users} ADD timezone_name varchar(50) NOT NULL default ''");
return $ret;
}
/**
* Make sure all the appropriate modules get enabled.
*/
function date_api_update_5200() {
$ret = array();
return $ret;
}
/**
* Make sure all the appropriate modules get enabled.
* Repeated again just to be sure they are set.
*/
function date_api_update_5201() {
$ret = array();
date_api_set_variables();
return $ret;
}
Functions
Name![]() |
Description |
---|---|
date_api_enable | |
date_api_install | Implementation of hook_install(). |
date_api_requirements | Implementation of hook_requirements(). Make sure Date PHP4 is installed if running less than PHP 5.2. |
date_api_set_variables | |
date_api_uninstall | Implementation of hook_uninstall(). |
date_api_update_5000 | Implementation of hook_update(). |
date_api_update_5200 | Make sure all the appropriate modules get enabled. |
date_api_update_5201 | Make sure all the appropriate modules get enabled. Repeated again just to be sure they are set. |