You are here

locale.install in Drupal 5

Same filename and directory in other branches
  1. 6 modules/locale/locale.install
  2. 7 modules/locale/locale.install

File

modules/locale/locale.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function locale_install() {

  // locales_source.source and locales_target.target are not used as binary
  // fields; non-MySQL database servers need to ensure the field type is text
  // and that LIKE produces a case-sensitive comparison.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {locales_meta} (\n        locale varchar(12) NOT NULL default '',\n        name varchar(64) NOT NULL default '',\n        enabled int NOT NULL default '0',\n        isdefault int NOT NULL default '0',\n        plurals int NOT NULL default '0',\n        formula varchar(128) NOT NULL default '',\n        PRIMARY KEY (locale)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {locales_source} (\n        lid int NOT NULL auto_increment,\n        location varchar(255) NOT NULL default '',\n        source blob NOT NULL,\n        PRIMARY KEY (lid),\n        KEY source (source(30))\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {locales_target} (\n        lid int NOT NULL default '0',\n        translation blob NOT NULL,\n        locale varchar(12) NOT NULL default '',\n        plid int NOT NULL default '0',\n        plural int NOT NULL default '0',\n        KEY lid (lid),\n        KEY lang (locale),\n        KEY plid (plid),\n        KEY plural (plural)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {locales_meta} (\n        locale varchar(12) NOT NULL default '',\n        name varchar(64) NOT NULL default '',\n        enabled int NOT NULL default '0',\n        isdefault int NOT NULL default '0',\n        plurals int NOT NULL default '0',\n        formula varchar(128) NOT NULL default '',\n        PRIMARY KEY (locale)\n      )");
      db_query("CREATE TABLE {locales_source} (\n        lid serial,\n        location varchar(255) NOT NULL default '',\n        source text NOT NULL,\n        PRIMARY KEY (lid)\n      )");
      db_query("CREATE TABLE {locales_target} (\n        lid int NOT NULL default '0',\n        translation text NOT NULL,\n        locale varchar(12) NOT NULL default '',\n        plid int NOT NULL default '0',\n        plural int NOT NULL default '0'\n      )");
      db_query("CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)");
      db_query("CREATE INDEX {locales_target}_locale_idx ON {locales_target} (locale)");
      db_query("CREATE INDEX {locales_target}_plid_idx ON {locales_target} (plid)");
      db_query("CREATE INDEX {locales_target}_plural_idx ON {locales_target} (plural)");
      db_query("CREATE INDEX {locales_source}_source_idx ON {locales_source} (source)");
      break;
  }
  db_query("INSERT INTO {locales_meta} (locale, name, enabled, isdefault) VALUES ('en', 'English', '1', '1')");
}

/**
 * Implementation of hook_uninstall().
 */
function locale_uninstall() {
  db_query('DROP TABLE {locales_meta}');
  db_query('DROP TABLE {locales_source}');
  db_query('DROP TABLE {locales_target}');
}

/**
 * Neutralize unsafe language names in the database.
 */
function locale_update_1() {
  $ret = array();
  $matches = db_result(db_query("SELECT 1 FROM {locales_meta} WHERE name LIKE '%<%' OR name LIKE '%>%'"));
  if ($matches) {
    $ret[] = update_sql("UPDATE {locales_meta} SET name = REPLACE(name, '<', '')");
    $ret[] = update_sql("UPDATE {locales_meta} SET name = REPLACE(name, '>', '')");
    drupal_set_message('The language name in English of all the existing custom languages of your site have been sanitized for security purposes. Visit the <a href="' . url('admin/settings/language') . '">Languages</a> page to check these and fix them if necessary.', 'warning');
  }

  // Check if some langcode values contain potentially dangerous characters and
  // warn the user if so. These are not fixed since they are referenced in other
  // tables (e.g. {node}).
  if (db_result(db_query("SELECT 1 FROM {locales_meta} WHERE locale LIKE '%<%' OR locale LIKE '%>%' OR locale LIKE '%\"%' OR locale LIKE '%\\\\\\%'"))) {
    drupal_set_message('Some of your custom language code values contain invalid characters. You should examine the <a href="' . url('admin/settings/language') . '">Languages</a> page. These must be fixed manually.', 'error');
  }
  return $ret;
}

Functions

Namesort descending Description
locale_install Implementation of hook_install().
locale_uninstall Implementation of hook_uninstall().
locale_update_1 Neutralize unsafe language names in the database.