| 1 |
<?php
|
| 2 |
// $Id: country_code.install,v 1.16 2008/10/28 22:23:48 nedjo Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Installation file for the country code module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
define('COUNTRY_CODE_MINIMUM_PHP', '5.1.0');
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of hook_install().
|
| 13 |
*/
|
| 14 |
function country_code_install() {
|
| 15 |
// Create tables.
|
| 16 |
drupal_install_schema('country_code');
|
| 17 |
// Set module weight higher than that of i18n module, which contains a conflicting
|
| 18 |
// hook_translation_link_alter() implementation.
|
| 19 |
$weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'i18n'"));
|
| 20 |
db_query("UPDATE {system} SET weight = %d WHERE name = 'country_code' AND type = 'module'", $weight ? $weight + 5 : 15);
|
| 21 |
}
|
| 22 |
|
| 23 |
/**
|
| 24 |
* Implementation of hook_enable().
|
| 25 |
*
|
| 26 |
* Add the site default country to the country_code_country table.
|
| 27 |
*/
|
| 28 |
function country_code_enable() {
|
| 29 |
$country = variable_get('site_country_default_country', '');
|
| 30 |
if (!empty($country)) {
|
| 31 |
$existing = country_code_country_load($country);
|
| 32 |
// Can't use drupal_write_record() here.
|
| 33 |
if ($existing) {
|
| 34 |
if ($existing['enabled'] == 0) {
|
| 35 |
$result = db_query("UPDATE {country_code_country} SET enabled = 1 WHERE country = '%s'", $country);
|
| 36 |
variable_set('country_code_count', variable_get('country_code_count', 0) + 1);
|
| 37 |
}
|
| 38 |
}
|
| 39 |
else {
|
| 40 |
$result = db_query("INSERT INTO {country_code_country} (country, enabled) VALUES('%s', 1)", $country);
|
| 41 |
variable_set('country_code_count', variable_get('country_code_count', 0) + 1);
|
| 42 |
}
|
| 43 |
}
|
| 44 |
}
|
| 45 |
|
| 46 |
/**
|
| 47 |
* Implementation of hook_schema().
|
| 48 |
*/
|
| 49 |
function country_code_schema() {
|
| 50 |
$schema = array();
|
| 51 |
$schema['country_code_country'] = array(
|
| 52 |
'description' => t('List of all available countries in the system.'),
|
| 53 |
'fields' => array(
|
| 54 |
'country' => array(
|
| 55 |
'type' => 'varchar',
|
| 56 |
'length' => 12,
|
| 57 |
'not null' => TRUE,
|
| 58 |
'default' => '',
|
| 59 |
'description' => t("Country code, e.g. 'us' or 'br'."),
|
| 60 |
),
|
| 61 |
'enabled' => array(
|
| 62 |
'type' => 'int',
|
| 63 |
'not null' => TRUE,
|
| 64 |
'default' => 0,
|
| 65 |
'description' => t('Whether the country is enabled.'),
|
| 66 |
),
|
| 67 |
),
|
| 68 |
'primary key' => array('country'),
|
| 69 |
);
|
| 70 |
|
| 71 |
return $schema;
|
| 72 |
}
|
| 73 |
|
| 74 |
function country_code_update_1() {
|
| 75 |
$return = array();
|
| 76 |
|
| 77 |
db_drop_table($return, 'country_code_country_language');
|
| 78 |
|
| 79 |
return $return;
|
| 80 |
}
|
| 81 |
|
| 82 |
function country_code_update_2() {
|
| 83 |
$return = array();
|
| 84 |
// Set module weight higher than that of i18n module, which contains a conflicting
|
| 85 |
// hook_translation_link_alter() implementation.
|
| 86 |
$weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'i18n'"));
|
| 87 |
$return[] = update_sql("UPDATE {system} SET weight = " . ($weight ? $weight + 5 : 15) . " WHERE name = 'country_code' AND type = 'module'");
|
| 88 |
return $return;
|
| 89 |
}
|
| 90 |
/**
|
| 91 |
* Implementation of hook_uninstall().
|
| 92 |
*/
|
| 93 |
function country_code_uninstall() {
|
| 94 |
// Remove tables.
|
| 95 |
drupal_uninstall_schema('country_code');
|
| 96 |
// Delete variables.
|
| 97 |
$variables = array(
|
| 98 |
'country_code_browser_language',
|
| 99 |
'country_code_count',
|
| 100 |
'country_code_external',
|
| 101 |
'country_code_fallback',
|
| 102 |
'country_code_country_default',
|
| 103 |
'country_code_user_country',
|
| 104 |
'country_code_user_language',
|
| 105 |
);
|
| 106 |
foreach ($variables as $variable) {
|
| 107 |
variable_del($variable);
|
| 108 |
}
|
| 109 |
}
|
| 110 |
|
| 111 |
/**
|
| 112 |
* Implementation of hook_disable().
|
| 113 |
*
|
| 114 |
* Reset the language_negotiation variable to LANGUAGE_NEGOTIATION_NONE.
|
| 115 |
*/
|
| 116 |
function country_code_disable() {
|
| 117 |
if (variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_COUNTRY_CODE) {
|
| 118 |
variable_set('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
|
| 119 |
drupal_set_message(t("Your language negotiation setting has been returned to the default value of 'none'."));
|
| 120 |
}
|
| 121 |
}
|
| 122 |
|
| 123 |
/**
|
| 124 |
* Implementation of hook_requirements().
|
| 125 |
*
|
| 126 |
* Country code uses array_intersect_key(), not available before PHP 5.
|
| 127 |
*/
|
| 128 |
function country_code_requirements($phase) {
|
| 129 |
$requirements = array();
|
| 130 |
// Ensure translations don't break at install time.
|
| 131 |
$t = get_t();
|
| 132 |
|
| 133 |
// Test PHP version.
|
| 134 |
$requirements['php'] = array(
|
| 135 |
'title' => $t('PHP'),
|
| 136 |
'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/logs/status/php') : phpversion(),
|
| 137 |
);
|
| 138 |
if (version_compare(phpversion(), COUNTRY_CODE_MINIMUM_PHP) < 0) {
|
| 139 |
$requirements['php']['description'] = $t('Your PHP installation is too old. Country code requires at least PHP %version.', array('%version' => COUNTRY_CODE_MINIMUM_PHP));
|
| 140 |
$requirements['php']['severity'] = REQUIREMENT_ERROR;
|
| 141 |
}
|
| 142 |
|
| 143 |
return $requirements;
|
| 144 |
}
|
| 145 |
|