You are here

function system_update_6005 in Drupal 6

Add language to url_alias table and modify indexes.

Related topics

File

modules/system/system.install, line 1280

Code

function system_update_6005() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_add_column($ret, 'url_alias', 'language', 'varchar(12)', array(
        'default' => "''",
        'not null' => TRUE,
      ));

      // As of system.install:1.85 (before the new language
      // subsystem), new installs got a unique key named
      // url_alias_dst_key on url_alias.dst.  Unfortunately,
      // system_update_162 created a unique key inconsistently named
      // url_alias_dst_idx on url_alias.dst (keys should have the _key
      // suffix, indexes the _idx suffix).  Therefore, sites installed
      // before system_update_162 have a unique key with a different
      // name than sites installed after system_update_162().  Now, we
      // want to drop the unique key on dst which may have either one
      // of two names and create a new unique key on (dst, language).
      // There is no way to know which key name exists so we have to
      // drop both, causing an SQL error.  Thus, we just hide the
      // error and only report the update_sql results that work.
      $err = error_reporting(0);
      $ret1 = update_sql('DROP INDEX {url_alias}_dst_idx');
      if ($ret1['success']) {
        $ret[] = $ret1;
      }
      $ret1 = array();
      db_drop_unique_key($ret, 'url_alias', 'dst');
      foreach ($ret1 as $r) {
        if ($r['success']) {
          $ret[] = $r;
        }
      }
      error_reporting($err);
      $ret[] = update_sql('CREATE UNIQUE INDEX {url_alias}_dst_language_idx ON {url_alias}(dst, language)');
      break;
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {url_alias} ADD language varchar(12) NOT NULL default ''");
      $ret[] = update_sql("ALTER TABLE {url_alias} DROP INDEX dst");
      $ret[] = update_sql("ALTER TABLE {url_alias} ADD UNIQUE dst_language (dst, language)");
      break;
  }
  return $ret;
}