[ Index ]
 

Code source de Drupal 5.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/modules/system/ -> system.install (source)

   1  <?php
   2  // $Id: system.install,v 1.69.2.6 2007/10/16 06:20:39 drumm Exp $
   3  
   4  define('DRUPAL_MINIMUM_PHP',    '4.3.3');
   5  define('DRUPAL_MINIMUM_MYSQL',  '3.23.17'); // If using MySQL
   6  define('DRUPAL_MINIMUM_PGSQL',  '7.3');  // If using PostgreSQL
   7  
   8  /**
   9   * Test and report Drupal installation requirements.
  10   */
  11  function system_requirements($phase) {
  12    $requirements = array();
  13    // Ensure translations don't break at install time
  14    $t = get_t();
  15  
  16    // Report Drupal version
  17    if ($phase == 'runtime') {
  18      $requirements['drupal'] = array(
  19        'title' => $t('Drupal'),
  20        'value' => VERSION,
  21        'severity' => REQUIREMENT_INFO,
  22        'weight' => -10,
  23      );
  24    }
  25  
  26    // Web server information.
  27    $software = $_SERVER['SERVER_SOFTWARE'];
  28    $requirements['webserver'] = array(
  29      'title' => $t('Web server'),
  30      'value' => $software,
  31    );
  32  
  33    // Test PHP version
  34    $requirements['php'] = array(
  35      'title' => $t('PHP'),
  36      'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/logs/status/php') : phpversion(),
  37    );
  38    if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) {
  39      $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP));
  40      $requirements['php']['severity'] = REQUIREMENT_ERROR;
  41    }
  42  
  43    // Test DB version
  44    global $db_type;
  45    if (function_exists('db_status_report')) {
  46      $requirements += db_status_report($phase);
  47    }
  48  
  49    // Test settings.php file writability
  50    if ($phase == 'runtime') {
  51      if (!drupal_verify_install_file(conf_path() .'/settings.php', FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE)) {
  52        $requirements['settings.php'] = array(
  53          'value' => $t('Not protected'),
  54          'severity' => REQUIREMENT_ERROR,
  55          'description' => $t('The file %file is not protected from modifications and poses a security risk. You must change the file\'s permissions to be non-writable.', array('%file' => conf_path() .'/settings.php')),
  56        );
  57      }
  58      else {
  59        $requirements['settings.php'] = array(
  60          'value' => $t('Protected'),
  61        );
  62      }
  63      $requirements['settings.php']['title'] = $t('Configuration file');
  64    }
  65  
  66    // Report cron status
  67    if ($phase == 'runtime') {
  68      $cron_last = variable_get('cron_last', NULL);
  69  
  70      if (is_numeric($cron_last)) {
  71        $requirements['cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(time() - $cron_last)));
  72      }
  73      else {
  74        $requirements['cron'] = array(
  75          'description' => $t('Cron has not run. It appears cron jobs have not been setup on your system. Please check the help pages for <a href="@url">configuring cron jobs</a>.', array('@url' => 'http://drupal.org/cron')),
  76          'severity' => REQUIREMENT_ERROR,
  77          'value' => $t('Never run'),
  78        );
  79      }
  80  
  81      $requirements['cron']['description'] .= ' '. t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/logs/status/run-cron')));
  82  
  83      $requirements['cron']['title'] = $t('Cron maintenance tasks');
  84    }
  85  
  86    // Test files directory
  87    if ($phase == 'runtime') {
  88      $directory = file_directory_path();
  89      $is_writable = is_writable($directory);
  90      $is_directory = is_dir($directory);
  91      if (!$is_writable || !$is_directory) {
  92        if (!$is_directory) {
  93          $error = $t('The directory %directory does not exist.', array('%directory' => $directory));
  94        }
  95        else {
  96          $error = $t('The directory %directory is not writable.', array('%directory' => $directory));
  97        }
  98        $requirements['file system'] = array(
  99          'value' => $t('Not writable'),
 100          'severity' => REQUIREMENT_ERROR,
 101          'description' => $error .' '. $t('You may need to set the correct directory at the <a href="@admin-file-system">file system settings page</a> or change the current directory\'s permissions so that it is writable.', array('@admin-file-system' => url('admin/settings/file-system'))),
 102        );
 103      }
 104      else {
 105        if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PUBLIC) {
 106          $requirements['file system'] = array(
 107            'value' => $t('Writable (<em>public</em> download method)'),
 108          );
 109        }
 110        else {
 111          $requirements['file system'] = array(
 112            'value' => $t('Writable (<em>private</em> download method)'),
 113          );
 114        }
 115      }
 116      $requirements['file system']['title'] = $t('File system');
 117    }
 118  
 119    // See if updates are available in update.php.
 120    if ($phase == 'runtime') {
 121      $requirements['update'] = array(
 122        'title' => $t('Database schema'),
 123        'severity' => REQUIREMENT_OK,
 124        'value' => $t('Up to date'),
 125      );
 126  
 127      // Check installed modules.
 128      foreach (module_list() as $module) {
 129        $updates = drupal_get_schema_versions($module);
 130        if ($updates !== FALSE) {
 131          $default = drupal_get_installed_schema_version($module);
 132          if (max($updates) > $default) {
 133            $requirements['update']['severity'] = REQUIREMENT_ERROR;
 134            $requirements['update']['value'] = $t('Out of date');
 135            $requirements['update']['description'] = $t('Some modules have database schema updates to install. You should run the <a href="@update">database update script</a> immediately.', array('@update' => base_path() .'update.php'));
 136            break;
 137          }
 138        }
 139      }
 140    }
 141  
 142    // Test Unicode library
 143    include_once  './includes/unicode.inc';
 144    $requirements = array_merge($requirements, unicode_requirements());
 145  
 146    return $requirements;
 147  }
 148  
 149  
 150  /**
 151   * Implementation of hook_install().
 152   */
 153  function system_install() {
 154    switch ($GLOBALS['db_type']) {
 155      case 'mysql':
 156      case 'mysqli':
 157        db_query("CREATE TABLE {access} (
 158          aid int NOT NULL auto_increment,
 159          mask varchar(255) NOT NULL default '',
 160          type varchar(255) NOT NULL default '',
 161          status tinyint NOT NULL default '0',
 162          PRIMARY KEY (aid)
 163        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 164  
 165        db_query("CREATE TABLE {authmap} (
 166          aid int unsigned NOT NULL auto_increment,
 167          uid int NOT NULL default '0',
 168          authname varchar(128) NOT NULL default '',
 169          module varchar(128) NOT NULL default '',
 170          PRIMARY KEY (aid),
 171          UNIQUE KEY authname (authname)
 172        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 173  
 174        db_query("CREATE TABLE {blocks} (
 175          module varchar(64) DEFAULT '' NOT NULL,
 176          delta varchar(32) NOT NULL default '0',
 177          theme varchar(255) NOT NULL default '',
 178          status tinyint DEFAULT '0' NOT NULL,
 179          weight tinyint DEFAULT '0' NOT NULL,
 180          region varchar(64) DEFAULT 'left' NOT NULL,
 181          custom tinyint DEFAULT '0' NOT NULL,
 182          throttle tinyint DEFAULT '0' NOT NULL,
 183          visibility tinyint DEFAULT '0' NOT NULL,
 184          pages text NOT NULL,
 185          title varchar(64) DEFAULT '' NOT NULL
 186        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 187  
 188        db_query("CREATE TABLE {boxes} (
 189          bid int NOT NULL auto_increment,
 190          body longtext,
 191          info varchar(128) NOT NULL default '',
 192          format int NOT NULL default '0',
 193          PRIMARY KEY (bid),
 194          UNIQUE KEY info (info)
 195        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 196  
 197        db_query("CREATE TABLE {cache} (
 198          cid varchar(255) NOT NULL default '',
 199          data longblob,
 200          expire int NOT NULL default '0',
 201          created int NOT NULL default '0',
 202          headers text,
 203          PRIMARY KEY (cid),
 204          INDEX expire (expire)
 205        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 206        db_query("CREATE TABLE {cache_filter} (
 207          cid varchar(255) NOT NULL default '',
 208          data longblob,
 209          expire int NOT NULL default '0',
 210          created int NOT NULL default '0',
 211          headers text,
 212          PRIMARY KEY (cid),
 213          INDEX expire (expire)
 214        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 215        db_query("CREATE TABLE {cache_menu} (
 216          cid varchar(255) NOT NULL default '',
 217          data longblob,
 218          expire int NOT NULL default '0',
 219          created int NOT NULL default '0',
 220          headers text,
 221          PRIMARY KEY (cid),
 222          INDEX expire (expire)
 223        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 224        db_query("CREATE TABLE {cache_page} (
 225          cid varchar(255) BINARY NOT NULL default '',
 226          data longblob,
 227          expire int NOT NULL default '0',
 228          created int NOT NULL default '0',
 229          headers text,
 230          PRIMARY KEY (cid),
 231          INDEX expire (expire)
 232        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 233  
 234        db_query("CREATE TABLE {comments} (
 235          cid int NOT NULL auto_increment,
 236          pid int NOT NULL default '0',
 237          nid int NOT NULL default '0',
 238          uid int NOT NULL default '0',
 239          subject varchar(64) NOT NULL default '',
 240          comment longtext NOT NULL,
 241          hostname varchar(128) NOT NULL default '',
 242          timestamp int NOT NULL default '0',
 243          score mediumint NOT NULL default '0',
 244          status tinyint unsigned NOT NULL default '0',
 245          format int NOT NULL default '0',
 246          thread varchar(255) NOT NULL,
 247          users longtext,
 248          name varchar(60) default NULL,
 249          mail varchar(64) default NULL,
 250          homepage varchar(255) default NULL,
 251          PRIMARY KEY (cid),
 252          KEY lid (nid)
 253        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 254  
 255        db_query("CREATE TABLE {node_comment_statistics} (
 256          nid int unsigned NOT NULL auto_increment,
 257          last_comment_timestamp int NOT NULL default '0',
 258          last_comment_name varchar(60) default NULL,
 259          last_comment_uid int NOT NULL default '0',
 260          comment_count int unsigned NOT NULL default '0',
 261          PRIMARY KEY (nid),
 262          KEY node_comment_timestamp (last_comment_timestamp)
 263        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 264  
 265        db_query("CREATE TABLE {files} (
 266          fid int unsigned NOT NULL default 0,
 267          nid int unsigned NOT NULL default 0,
 268          filename varchar(255) NOT NULL default '',
 269          filepath varchar(255) NOT NULL default '',
 270          filemime varchar(255) NOT NULL default '',
 271          filesize int unsigned NOT NULL default 0,
 272          PRIMARY KEY (fid),
 273          KEY nid (nid)
 274        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 275  
 276        db_query("CREATE TABLE {file_revisions} (
 277          fid int unsigned NOT NULL default 0,
 278          vid int unsigned NOT NULL default 0,
 279          description varchar(255) NOT NULL default '',
 280          list tinyint unsigned NOT NULL default 0,
 281          PRIMARY KEY (fid, vid),
 282          KEY (vid)
 283        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 284  
 285        db_query("CREATE TABLE {filter_formats} (
 286          format int NOT NULL auto_increment,
 287          name varchar(255) NOT NULL default '',
 288          roles varchar(255) NOT NULL default '',
 289          cache tinyint NOT NULL default '0',
 290          PRIMARY KEY (format),
 291          UNIQUE KEY (name)
 292        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 293  
 294        db_query("CREATE TABLE {filters} (
 295          format int NOT NULL default '0',
 296          module varchar(64) NOT NULL default '',
 297          delta tinyint DEFAULT '0' NOT NULL,
 298          weight tinyint DEFAULT '0' NOT NULL,
 299          INDEX (weight)
 300        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 301  
 302        db_query("CREATE TABLE {flood} (
 303          event varchar(64) NOT NULL default '',
 304          hostname varchar(128) NOT NULL default '',
 305          timestamp int NOT NULL default '0'
 306        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 307  
 308        db_query("CREATE TABLE {history} (
 309          uid int NOT NULL default '0',
 310          nid int NOT NULL default '0',
 311          timestamp int NOT NULL default '0',
 312          PRIMARY KEY (uid,nid)
 313        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 314  
 315        db_query("CREATE TABLE {menu} (
 316          mid int unsigned NOT NULL default '0',
 317          pid int unsigned NOT NULL default '0',
 318          path varchar(255) NOT NULL default '',
 319          title varchar(255) NOT NULL default '',
 320          description varchar(255) NOT NULL default '',
 321          weight tinyint NOT NULL default '0',
 322          type int unsigned NOT NULL default '0',
 323          PRIMARY KEY (mid)
 324        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 325  
 326  
 327        db_query("CREATE TABLE {node} (
 328          nid int unsigned NOT NULL auto_increment,
 329          vid int unsigned NOT NULL default '0',
 330          type varchar(32) NOT NULL default '',
 331          title varchar(128) NOT NULL default '',
 332          uid int NOT NULL default '0',
 333          status int NOT NULL default '1',
 334          created int NOT NULL default '0',
 335          changed int NOT NULL default '0',
 336          comment int NOT NULL default '0',
 337          promote int NOT NULL default '0',
 338          moderate int NOT NULL default '0',
 339          sticky int NOT NULL default '0',
 340          PRIMARY KEY  (nid, vid),
 341          UNIQUE KEY vid (vid),
 342          KEY node_type (type(4)),
 343          KEY node_title_type (title, type(4)),
 344          KEY status (status),
 345          KEY uid (uid),
 346          KEY node_moderate (moderate),
 347          KEY node_promote_status (promote, status),
 348          KEY node_created (created),
 349          KEY node_changed (changed),
 350          KEY node_status_type (status, type, nid),
 351          KEY nid (nid)
 352        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 353  
 354        db_query("CREATE TABLE {node_access} (
 355          nid int unsigned NOT NULL default '0',
 356          gid int unsigned NOT NULL default '0',
 357          realm varchar(255) NOT NULL default '',
 358          grant_view tinyint unsigned NOT NULL default '0',
 359          grant_update tinyint unsigned NOT NULL default '0',
 360          grant_delete tinyint unsigned NOT NULL default '0',
 361          PRIMARY KEY (nid,gid,realm)
 362        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 363  
 364        db_query("CREATE TABLE {node_revisions} (
 365          nid int unsigned NOT NULL,
 366          vid int unsigned NOT NULL,
 367          uid int NOT NULL default '0',
 368          title varchar(128) NOT NULL default '',
 369          body longtext NOT NULL,
 370          teaser longtext NOT NULL,
 371          log longtext NOT NULL,
 372          timestamp int NOT NULL default '0',
 373          format int NOT NULL default '0',
 374          PRIMARY KEY  (vid),
 375          KEY nid (nid),
 376          KEY uid (uid)
 377        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 378  
 379        db_query("CREATE TABLE {node_type} (
 380          type varchar(32) NOT NULL,
 381          name varchar(255) NOT NULL default '',
 382          module varchar(255) NOT NULL,
 383          description mediumtext NOT NULL,
 384          help mediumtext NOT NULL,
 385          has_title tinyint unsigned NOT NULL,
 386          title_label varchar(255) NOT NULL default '',
 387          has_body tinyint unsigned NOT NULL,
 388          body_label varchar(255) NOT NULL default '',
 389          min_word_count smallint unsigned NOT NULL,
 390          custom tinyint NOT NULL DEFAULT '0',
 391          modified tinyint NOT NULL DEFAULT '0',
 392          locked tinyint NOT NULL DEFAULT '0',
 393          orig_type varchar(255) NOT NULL default '',
 394          PRIMARY KEY (type)
 395        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 396  
 397        db_query("CREATE TABLE {url_alias} (
 398          pid int unsigned NOT NULL auto_increment,
 399          src varchar(128) NOT NULL default '',
 400          dst varchar(128) NOT NULL default '',
 401          PRIMARY KEY (pid),
 402          UNIQUE KEY dst (dst),
 403          KEY src (src)
 404        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 405  
 406        db_query("CREATE TABLE {permission} (
 407          rid int unsigned NOT NULL default '0',
 408          perm longtext,
 409          tid int unsigned NOT NULL default '0',
 410          KEY rid (rid)
 411        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 412  
 413        db_query("CREATE TABLE {role} (
 414          rid int unsigned NOT NULL auto_increment,
 415          name varchar(64) NOT NULL default '',
 416          PRIMARY KEY (rid),
 417          UNIQUE KEY name (name)
 418        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 419  
 420        db_query("CREATE TABLE {blocks_roles} (
 421          module varchar(64) NOT NULL,
 422          delta varchar(32) NOT NULL,
 423          rid int unsigned NOT NULL,
 424          PRIMARY KEY (module, delta, rid)
 425        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 426  
 427        db_query("CREATE TABLE {sessions} (
 428          uid int unsigned NOT NULL,
 429          sid varchar(64) NOT NULL default '',
 430          hostname varchar(128) NOT NULL default '',
 431          timestamp int NOT NULL default '0',
 432          cache int NOT NULL default '0',
 433          session longtext,
 434          KEY uid (uid),
 435          PRIMARY KEY (sid),
 436          KEY timestamp (timestamp)
 437        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 438  
 439        db_query("CREATE TABLE {sequences} (
 440          name varchar(255) NOT NULL default '',
 441          id int unsigned NOT NULL default '0',
 442          PRIMARY KEY (name)
 443        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 444  
 445        db_query("CREATE TABLE {node_counter} (
 446          nid int NOT NULL default '0',
 447          totalcount bigint unsigned NOT NULL default '0',
 448          daycount mediumint unsigned NOT NULL default '0',
 449          timestamp int unsigned NOT NULL default '0',
 450          PRIMARY KEY (nid),
 451          KEY totalcount (totalcount),
 452          KEY daycount (daycount),
 453          KEY timestamp (timestamp)
 454        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 455  
 456        db_query("CREATE TABLE {system} (
 457          filename varchar(255) NOT NULL default '',
 458          name varchar(255) NOT NULL default '',
 459          type varchar(255) NOT NULL default '',
 460          description varchar(255) NOT NULL default '',
 461          status int NOT NULL default '0',
 462          throttle tinyint DEFAULT '0' NOT NULL,
 463          bootstrap int NOT NULL default '0',
 464          schema_version smallint NOT NULL default -1,
 465          weight int NOT NULL default '0',
 466          PRIMARY KEY (filename),
 467          KEY (weight)
 468        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 469  
 470        db_query("CREATE TABLE {term_data} (
 471          tid int unsigned NOT NULL auto_increment,
 472          vid int unsigned NOT NULL default '0',
 473          name varchar(255) NOT NULL default '',
 474          description longtext,
 475          weight tinyint NOT NULL default '0',
 476          PRIMARY KEY (tid),
 477          KEY vid (vid)
 478        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 479  
 480        db_query("CREATE TABLE {term_hierarchy} (
 481          tid int unsigned NOT NULL default '0',
 482          parent int unsigned NOT NULL default '0',
 483          KEY tid (tid),
 484          KEY parent (parent),
 485          PRIMARY KEY (tid, parent)
 486        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 487  
 488        db_query("CREATE TABLE {term_node} (
 489          nid int unsigned NOT NULL default '0',
 490          tid int unsigned NOT NULL default '0',
 491          KEY nid (nid),
 492          KEY tid (tid),
 493          PRIMARY KEY (tid,nid)
 494        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 495  
 496        db_query("CREATE TABLE {term_relation} (
 497          tid1 int unsigned NOT NULL default '0',
 498          tid2 int unsigned NOT NULL default '0',
 499          KEY tid1 (tid1),
 500          KEY tid2 (tid2)
 501        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 502  
 503        db_query("CREATE TABLE {term_synonym} (
 504          tid int unsigned NOT NULL default '0',
 505          name varchar(255) NOT NULL default '',
 506          KEY tid (tid),
 507          KEY name (name(3))
 508        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 509  
 510        db_query("CREATE TABLE {users} (
 511          uid int unsigned NOT NULL default '0',
 512          name varchar(60) NOT NULL default '',
 513          pass varchar(32) NOT NULL default '',
 514          mail varchar(64) default '',
 515          mode tinyint NOT NULL default '0',
 516          sort tinyint default '0',
 517          threshold tinyint default '0',
 518          theme varchar(255) NOT NULL default '',
 519          signature varchar(255) NOT NULL default '',
 520          created int NOT NULL default '0',
 521          access int NOT NULL default '0',
 522          login int NOT NULL default '0',
 523          status tinyint NOT NULL default '0',
 524          timezone varchar(8) default NULL,
 525          language varchar(12) NOT NULL default '',
 526          picture varchar(255) NOT NULL DEFAULT '',
 527          init varchar(64) default '',
 528          data longtext,
 529          PRIMARY KEY (uid),
 530          UNIQUE KEY name (name),
 531          KEY created (created),
 532          KEY access (access)
 533        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 534  
 535        db_query("CREATE TABLE {users_roles} (
 536          uid int unsigned NOT NULL default '0',
 537          rid int unsigned NOT NULL default '0',
 538          PRIMARY KEY (uid, rid)
 539        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 540  
 541        db_query("CREATE TABLE {variable} (
 542          name varchar(48) NOT NULL default '',
 543          value longtext NOT NULL,
 544          PRIMARY KEY (name)
 545        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 546  
 547        db_query("CREATE TABLE {vocabulary} (
 548          vid int unsigned NOT NULL auto_increment,
 549          name varchar(255) NOT NULL default '',
 550          description longtext,
 551          help varchar(255) NOT NULL default '',
 552          relations tinyint unsigned NOT NULL default '0',
 553          hierarchy tinyint unsigned NOT NULL default '0',
 554          multiple tinyint unsigned NOT NULL default '0',
 555          required tinyint unsigned NOT NULL default '0',
 556          tags tinyint unsigned NOT NULL default '0',
 557          module varchar(255) NOT NULL default '',
 558          weight tinyint NOT NULL default '0',
 559          PRIMARY KEY (vid)
 560        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 561  
 562        db_query("CREATE TABLE {vocabulary_node_types} (
 563          vid int unsigned NOT NULL DEFAULT '0',
 564          type varchar(32) NOT NULL DEFAULT '',
 565          PRIMARY KEY (vid, type)
 566        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 567  
 568        db_query("CREATE TABLE {watchdog} (
 569          wid int NOT NULL auto_increment,
 570          uid int NOT NULL default '0',
 571          type varchar(16) NOT NULL default '',
 572          message longtext NOT NULL,
 573          severity tinyint unsigned NOT NULL default '0',
 574          link varchar(255) NOT NULL default '',
 575          location text NOT NULL,
 576          referer varchar(128) NOT NULL default '',
 577          hostname varchar(128) NOT NULL default '',
 578          timestamp int NOT NULL default '0',
 579          PRIMARY KEY (wid),
 580          KEY (type)
 581        ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
 582  
 583        break;
 584      case 'pgsql':
 585        /* create unsigned types */
 586        db_query("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
 587        db_query("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
 588        db_query("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
 589  
 590        /* create functions */
 591        db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric) RETURNS numeric AS
 592          \'SELECT CASE WHEN (($1 > $2) OR ($2 IS NULL)) THEN $1 ELSE $2 END;\'
 593          LANGUAGE \'sql\''
 594        );
 595        db_query('CREATE OR REPLACE FUNCTION "greatest"(numeric, numeric, numeric) RETURNS numeric AS
 596          \'SELECT greatest($1, greatest($2, $3));\'
 597          LANGUAGE \'sql\''
 598        );
 599        if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'rand'"))) {
 600          db_query('CREATE OR REPLACE FUNCTION "rand"() RETURNS float AS
 601            \'SELECT random();\'
 602            LANGUAGE \'sql\''
 603          );
 604        }
 605  
 606        if (!db_result(db_query("SELECT COUNT(*) FROM pg_proc WHERE proname = 'concat'"))) {
 607          db_query('CREATE OR REPLACE FUNCTION "concat"(text, text) RETURNS text AS
 608            \'SELECT $1 || $2;\'
 609            LANGUAGE \'sql\''
 610          );
 611        }
 612        db_query('CREATE OR REPLACE FUNCTION "if"(boolean, text, text) RETURNS text AS
 613          \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
 614          LANGUAGE \'sql\''
 615        );
 616        db_query('CREATE OR REPLACE FUNCTION "if"(boolean, integer, integer) RETURNS integer AS
 617          \'SELECT CASE WHEN $1 THEN $2 ELSE $3 END;\'
 618          LANGUAGE \'sql\''
 619        );
 620  
 621        /* create tables */
 622        db_query("CREATE TABLE {access} (
 623          aid serial,
 624          mask varchar(255) NOT NULL default '',
 625          type varchar(255) NOT NULL default '',
 626          status smallint NOT NULL default '0',
 627          PRIMARY KEY (aid)
 628        )");
 629  
 630        db_query("CREATE TABLE {authmap} (
 631          aid serial CHECK (aid >= 0),
 632          uid int NOT NULL default '0',
 633          authname varchar(128) NOT NULL default '',
 634          module varchar(128) NOT NULL default '',
 635          PRIMARY KEY (aid),
 636          UNIQUE (authname)
 637        )");
 638  
 639        db_query("CREATE TABLE {blocks} (
 640          module varchar(64) DEFAULT '' NOT NULL,
 641          delta varchar(32) NOT NULL default '0',
 642          theme varchar(255) NOT NULL default '',
 643          status smallint DEFAULT '0' NOT NULL,
 644          weight smallint DEFAULT '0' NOT NULL,
 645          region varchar(64) DEFAULT 'left' NOT NULL,
 646          custom smallint DEFAULT '0' NOT NULL,
 647          throttle smallint DEFAULT '0' NOT NULL,
 648          visibility smallint DEFAULT '0' NOT NULL,
 649          pages text DEFAULT '' NOT NULL,
 650          title varchar(64) DEFAULT '' NOT NULL
 651        )");
 652  
 653        db_query("CREATE TABLE {boxes} (
 654          bid serial,
 655          body text,
 656          info varchar(128) NOT NULL default '',
 657          format smallint NOT NULL default '0',
 658          PRIMARY KEY (bid),
 659          UNIQUE (info)
 660        )");
 661  
 662        db_query("CREATE TABLE {cache} (
 663          cid varchar(255) NOT NULL default '',
 664          data bytea,
 665          expire int NOT NULL default '0',
 666          created int NOT NULL default '0',
 667          headers text,
 668          PRIMARY KEY (cid)
 669        )");
 670        db_query("CREATE TABLE {cache_filter} (
 671          cid varchar(255) NOT NULL default '',
 672          data bytea,
 673          expire int NOT NULL default '0',
 674          created int NOT NULL default '0',
 675          headers text,
 676          PRIMARY KEY (cid)
 677        )");
 678        db_query("CREATE TABLE {cache_menu} (
 679          cid varchar(255) NOT NULL default '',
 680          data bytea,
 681          expire int NOT NULL default '0',
 682          created int NOT NULL default '0',
 683          headers text,
 684          PRIMARY KEY (cid)
 685        )");
 686        db_query("CREATE TABLE {cache_page} (
 687          cid varchar(255) NOT NULL default '',
 688          data bytea,
 689          expire int NOT NULL default '0',
 690          created int NOT NULL default '0',
 691          headers text,
 692          PRIMARY KEY (cid)
 693        )");
 694        db_query("CREATE INDEX {cache}_expire_idx ON {cache} (expire)");
 695        db_query("CREATE INDEX {cache_filter}_expire_idx ON {cache_filter} (expire)");
 696        db_query("CREATE INDEX {cache_menu}_expire_idx ON {cache_menu} (expire)");
 697        db_query("CREATE INDEX {cache_page}_expire_idx ON {cache_page} (expire)");
 698  
 699        db_query("CREATE TABLE {comments} (
 700          cid serial,
 701          pid int NOT NULL default '0',
 702          nid int NOT NULL default '0',
 703          uid int NOT NULL default '0',
 704          subject varchar(64) NOT NULL default '',
 705          comment text NOT NULL,
 706          hostname varchar(128) NOT NULL default '',
 707          timestamp int NOT NULL default '0',
 708          score int NOT NULL default '0',
 709          status smallint_unsigned NOT NULL default '0',
 710          format smallint NOT NULL default '0',
 711          thread varchar(255) NOT NULL,
 712          users text,
 713          name varchar(60) default NULL,
 714          mail varchar(64) default NULL,
 715          homepage varchar(255) default NULL,
 716          PRIMARY KEY (cid)
 717        )");
 718        db_query("CREATE INDEX {comments}_nid_idx ON {comments} (nid)");
 719  
 720        db_query("CREATE TABLE {node_comment_statistics} (
 721          nid serial CHECK (nid >= 0),
 722          last_comment_timestamp int NOT NULL default '0',
 723          last_comment_name varchar(60) default NULL,
 724          last_comment_uid int NOT NULL default '0',
 725          comment_count int_unsigned NOT NULL default '0',
 726          PRIMARY KEY (nid)
 727        )");
 728        db_query("CREATE INDEX {node_comment_statistics}_node_comment_timestamp_idx ON {node_comment_statistics} (last_comment_timestamp)");
 729  
 730        db_query("CREATE TABLE {files} (
 731          fid serial CHECK (fid >= 0),
 732          nid int_unsigned NOT NULL default 0,
 733          filename varchar(255) NOT NULL default '',
 734          filepath varchar(255) NOT NULL default '',
 735          filemime varchar(255) NOT NULL default '',
 736          filesize int_unsigned NOT NULL default 0,
 737          PRIMARY KEY (fid)
 738        )");
 739        db_query("CREATE INDEX {files}_nid_idx ON {files} (nid)");
 740  
 741        db_query("CREATE TABLE {file_revisions} (
 742          fid int_unsigned NOT NULL default 0,
 743          vid int_unsigned NOT NULL default 0,
 744          description varchar(255) NOT NULL default '',
 745          list smallint_unsigned NOT NULL default 0,
 746          PRIMARY KEY (fid, vid)
 747        )");
 748        db_query("CREATE INDEX {file_revisions}_vid_idx ON {file_revisions} (vid)");
 749  
 750        db_query("CREATE TABLE {filter_formats} (
 751          format serial,
 752          name varchar(255) NOT NULL default '',
 753          roles varchar(255) NOT NULL default '',
 754          cache smallint NOT NULL default '0',
 755          PRIMARY KEY (format),
 756          UNIQUE (name)
 757        )");
 758  
 759        db_query("CREATE TABLE {filters} (
 760          format int NOT NULL default '0',
 761          module varchar(64) NOT NULL default '',
 762          delta smallint DEFAULT '0' NOT NULL,
 763          weight smallint DEFAULT '0' NOT NULL
 764        )");
 765        db_query("CREATE INDEX {filters}_weight_idx ON {filters} (weight)");
 766  
 767        db_query("CREATE TABLE {flood} (
 768          event varchar(64) NOT NULL default '',
 769          hostname varchar(128) NOT NULL default '',
 770          timestamp int NOT NULL default '0'
 771        )");
 772  
 773        db_query("CREATE TABLE {history} (
 774          uid int NOT NULL default '0',
 775          nid int NOT NULL default '0',
 776          timestamp int NOT NULL default '0',
 777          PRIMARY KEY (uid,nid)
 778        )");
 779  
 780        db_query("CREATE TABLE {menu} (
 781          mid serial CHECK (mid >= 0),
 782          pid int_unsigned NOT NULL default '0',
 783          path varchar(255) NOT NULL default '',
 784          title varchar(255) NOT NULL default '',
 785          description varchar(255) NOT NULL default '',
 786          weight smallint NOT NULL default '0',
 787          type int_unsigned NOT NULL default '0',
 788          PRIMARY KEY (mid)
 789        )");
 790        db_query("ALTER SEQUENCE {menu}_mid_seq MINVALUE 2 RESTART 2");
 791  
 792        db_query("CREATE TABLE {node} (
 793          nid serial CHECK (nid >= 0),
 794          vid int_unsigned NOT NULL default '0',
 795          type varchar(32) NOT NULL default '',
 796          title varchar(128) NOT NULL default '',
 797          uid int NOT NULL default '0',
 798          status int NOT NULL default '1',
 799          created int NOT NULL default '0',
 800          changed int NOT NULL default '0',
 801          comment int NOT NULL default '0',
 802          promote int NOT NULL default '0',
 803          moderate int NOT NULL default '0',
 804          sticky int NOT NULL default '0',
 805          PRIMARY KEY (nid, vid),
 806          UNIQUE (vid)
 807        )");
 808        db_query("CREATE INDEX {node}_node_type_idx ON {node} (substr (type, 1, 4))");
 809        db_query("CREATE INDEX {node}_node_title_type_idx ON {node} (title, substr(type, 1, 4))");
 810        db_query("CREATE INDEX {node}_status_idx ON {node} (status)");
 811        db_query("CREATE INDEX {node}_uid_idx ON {node} (uid)");
 812        db_query("CREATE INDEX {node}_node_moderate_idx ON {node} (moderate)");
 813        db_query("CREATE INDEX {node}_node_promote_status_idx ON {node} (promote, status)");
 814        db_query("CREATE INDEX {node}_node_created_idx ON {node} (created)");
 815        db_query("CREATE INDEX {node}_node_changed_idx ON {node} (changed)");
 816        db_query("CREATE INDEX {node}_node_status_type_idx ON {node} (status, type, nid)");
 817        db_query("CREATE INDEX {node}_nid_idx ON {node} (nid)");
 818  
 819        db_query("CREATE TABLE {node_access} (
 820          nid int_unsigned NOT NULL default '0',
 821          gid int_unsigned NOT NULL default '0',
 822          realm varchar(255) NOT NULL default '',
 823          grant_view smallint_unsigned NOT NULL default '0',
 824          grant_update smallint_unsigned NOT NULL default '0',
 825          grant_delete smallint_unsigned NOT NULL default '0',
 826          PRIMARY KEY (nid,gid,realm)
 827        )");
 828  
 829        db_query("CREATE TABLE {node_revisions} (
 830          nid int_unsigned NOT NULL,
 831          vid serial CHECK (vid >= 0),
 832          uid int NOT NULL default '0',
 833          title varchar(128) NOT NULL default '',
 834          body text NOT NULL default '',
 835          teaser text NOT NULL default '',
 836          log text NOT NULL default '',
 837          timestamp int NOT NULL default '0',
 838          format int NOT NULL default '0',
 839          PRIMARY KEY (vid)
 840        )");
 841        db_query("CREATE INDEX {node_revisions}_nid_idx ON {node_revisions} (nid)");
 842        db_query("CREATE INDEX {node_revisions}_uid_idx ON {node_revisions} (uid)");
 843  
 844        db_query("CREATE TABLE {node_type} (
 845          type varchar(32) NOT NULL,
 846          name varchar(255) NOT NULL default '',
 847          module varchar(255) NOT NULL,
 848          description text NOT NULL,
 849          help text NOT NULL,
 850          has_title smallint_unsigned NOT NULL,
 851          title_label varchar(255) NOT NULL default '',
 852          has_body smallint_unsigned NOT NULL,
 853          body_label varchar(255) NOT NULL default '',
 854          min_word_count smallint_unsigned NOT NULL,
 855          custom smallint NOT NULL DEFAULT '0',
 856          modified smallint NOT NULL DEFAULT '0',
 857          locked smallint NOT NULL DEFAULT '0',
 858          orig_type varchar(255) NOT NULL default '',
 859          PRIMARY KEY (type)
 860        )");
 861  
 862        db_query("CREATE TABLE {url_alias} (
 863          pid serial CHECK (pid >= 0),
 864          src varchar(128) NOT NULL default '',
 865          dst varchar(128) NOT NULL default '',
 866          PRIMARY KEY (pid),
 867          UNIQUE (dst)
 868        )");
 869        db_query("CREATE INDEX {url_alias}_src_idx ON {url_alias} (src)");
 870  
 871        db_query("CREATE TABLE {permission} (
 872          rid int_unsigned NOT NULL default '0',
 873          perm text,
 874          tid int_unsigned NOT NULL default '0'
 875        )");
 876        db_query("CREATE INDEX {permission}_rid_idx ON {permission} (rid)");
 877  
 878        db_query("CREATE TABLE {role} (
 879          rid serial CHECK (rid >= 0),
 880          name varchar(64) NOT NULL default '',
 881          PRIMARY KEY (rid),
 882          UNIQUE (name)
 883        )");
 884  
 885        db_query("SELECT setval('{role}_rid_seq',". max(DRUPAL_ANONYMOUS_RID,DRUPAL_AUTHENTICATED_RID) .")");
 886  
 887        db_query("CREATE TABLE {blocks_roles} (
 888          module varchar(64) NOT NULL,
 889          delta varchar(32) NOT NULL,
 890          rid int_unsigned NOT NULL,
 891          PRIMARY KEY (module, delta, rid)
 892        )");
 893  
 894        db_query("CREATE TABLE {sessions} (
 895          uid int_unsigned NOT NULL,
 896          sid varchar(64) NOT NULL default '',
 897          hostname varchar(128) NOT NULL default '',
 898          timestamp int NOT NULL default '0',
 899          cache int NOT NULL default '0',
 900          session text,
 901          PRIMARY KEY (sid)
 902        )");
 903        db_query("CREATE INDEX {sessions}_uid_idx ON {sessions} (uid)");
 904        db_query("CREATE INDEX {sessions}_timestamp_idx ON {sessions} (timestamp)");
 905  
 906  /* Only used for MySQL
 907        db_query("CREATE TABLE {sequences} (
 908          name varchar(255) NOT NULL default '',
 909          id int_unsigned NOT NULL default '0',
 910          PRIMARY KEY (name)
 911        )"); */
 912  
 913        db_query("CREATE TABLE {node_counter} (
 914          nid int NOT NULL default '0',
 915          totalcount bigint_unsigned NOT NULL default '0',
 916          daycount int_unsigned NOT NULL default '0',
 917          timestamp int_unsigned NOT NULL default '0',
 918          PRIMARY KEY (nid)
 919        )");
 920        db_query("CREATE INDEX {node_counter}_totalcount_idx ON {node_counter} (totalcount)");
 921        db_query("CREATE INDEX {node_counter}_daycount_idx ON {node_counter} (daycount)");
 922        db_query("CREATE INDEX {node_counter}_timestamp_idx ON {node_counter} (timestamp)");
 923  
 924        db_query("CREATE TABLE {system} (
 925          filename varchar(255) NOT NULL default '',
 926          name varchar(255) NOT NULL default '',
 927          type varchar(255) NOT NULL default '',
 928          description varchar(255) NOT NULL default '',
 929          status int NOT NULL default '0',
 930          throttle smallint DEFAULT '0' NOT NULL,
 931          bootstrap int NOT NULL default '0',
 932          schema_version smallint NOT NULL default -1,
 933          weight int NOT NULL default '0',
 934          PRIMARY KEY (filename)
 935        )");
 936        db_query("CREATE INDEX {system}_weight_idx ON {system} (weight)");
 937  
 938        db_query("CREATE TABLE {term_data} (
 939          tid serial CHECK (tid >= 0),
 940          vid int_unsigned NOT NULL default '0',
 941          name varchar(255) NOT NULL default '',
 942          description text,
 943          weight smallint NOT NULL default '0',
 944          PRIMARY KEY (tid)
 945        )");
 946        db_query("CREATE INDEX {term_data}_vid_idx ON {term_data} (vid)");
 947  
 948        db_query("CREATE TABLE {term_hierarchy} (
 949          tid int_unsigned NOT NULL default '0',
 950          parent int_unsigned NOT NULL default '0',
 951          PRIMARY KEY (tid, parent)
 952        )");
 953        db_query("CREATE INDEX {term_hierarchy}_tid_idx ON {term_hierarchy} (tid)");
 954        db_query("CREATE INDEX {term_hierarchy}_parent_idx ON {term_hierarchy} (parent)");
 955  
 956        db_query("CREATE TABLE {term_node} (
 957          nid int_unsigned NOT NULL default '0',
 958          tid int_unsigned NOT NULL default '0',
 959          PRIMARY KEY (tid,nid)
 960        )");
 961        db_query("CREATE INDEX {term_node}_nid_idx ON {term_node} (nid)");
 962        db_query("CREATE INDEX {term_node}_tid_idx ON {term_node} (tid)");
 963  
 964        db_query("CREATE TABLE {term_relation} (
 965          tid1 int_unsigned NOT NULL default '0',
 966          tid2 int_unsigned NOT NULL default '0'
 967        )");
 968        db_query("CREATE INDEX {term_relation}_tid1_idx ON {term_relation} (tid1)");
 969        db_query("CREATE INDEX {term_relation}_tid2_idx ON {term_relation} (tid2)");
 970  
 971        db_query("CREATE TABLE {term_synonym} (
 972          tid int_unsigned NOT NULL default '0',
 973          name varchar(255) NOT NULL default ''
 974        )");
 975        db_query("CREATE INDEX {term_synonym}_tid_idx ON {term_synonym} (tid)");
 976        db_query("CREATE INDEX {term_synonym}_name_idx ON {term_synonym} (substr(name, 1, 3))");
 977  
 978        db_query("CREATE TABLE {users} (
 979          uid serial CHECK (uid >= 0),
 980          name varchar(60) NOT NULL default '',
 981          pass varchar(32) NOT NULL default '',
 982          mail varchar(64) default '',
 983          mode smallint NOT NULL default '0',
 984          sort smallint default '0',
 985          threshold smallint default '0',
 986          theme varchar(255) NOT NULL default '',
 987          signature varchar(255) NOT NULL default '',
 988          created int NOT NULL default '0',
 989          access int NOT NULL default '0',
 990          login int NOT NULL default '0',
 991          status smallint NOT NULL default '0',
 992          timezone varchar(8) default NULL,
 993          language varchar(12) NOT NULL default '',
 994          picture varchar(255) NOT NULL DEFAULT '',
 995          init varchar(64) default '',
 996          data text,
 997          PRIMARY KEY (uid),
 998          UNIQUE (name)
 999        )");
1000        db_query("CREATE INDEX {users}_access_idx ON {users} (access)");
1001        db_query("CREATE INDEX {users}_created_idx ON {users} (created)");
1002  
1003        db_query("CREATE TABLE {users_roles} (
1004          uid int_unsigned NOT NULL default '0',
1005          rid int_unsigned NOT NULL default '0',
1006          PRIMARY KEY (uid, rid)
1007        )");
1008  
1009        db_query("CREATE TABLE {variable} (
1010          name varchar(48) NOT NULL default '',
1011          value text NOT NULL,
1012          PRIMARY KEY (name)
1013        )");
1014  
1015        db_query("CREATE TABLE {vocabulary} (
1016          vid serial CHECK (vid >= 0),
1017          name varchar(255) NOT NULL default '',
1018          description text,
1019          help varchar(255) NOT NULL default '',
1020          relations smallint_unsigned NOT NULL default '0',
1021          hierarchy smallint_unsigned NOT NULL default '0',
1022          multiple smallint_unsigned NOT NULL default '0',
1023          required smallint_unsigned NOT NULL default '0',
1024          tags smallint_unsigned NOT NULL default '0',
1025          module varchar(255) NOT NULL default '',
1026          weight smallint NOT NULL default '0',
1027          PRIMARY KEY (vid)
1028        )");
1029  
1030        db_query("CREATE TABLE {vocabulary_node_types} (
1031          vid int_unsigned NOT NULL DEFAULT '0',
1032          type varchar(32) NOT NULL DEFAULT '',
1033          PRIMARY KEY (vid, type)
1034        )");
1035  
1036        db_query("CREATE TABLE {watchdog} (
1037          wid serial,
1038          uid int NOT NULL default '0',
1039          type varchar(16) NOT NULL default '',
1040          message text NOT NULL,
1041          severity smallint_unsigned NOT NULL default '0',
1042          link varchar(255) NOT NULL default '',
1043          location text NOT NULL default '',
1044          referer varchar(128) NOT NULL default '',
1045          hostname varchar(128) NOT NULL default '',
1046          timestamp int NOT NULL default '0',
1047          PRIMARY KEY (wid)
1048        )");
1049        db_query("CREATE INDEX {watchdog}_type_idx ON {watchdog} (type)");
1050        break;
1051    }
1052  
1053    db_query("INSERT INTO {system} (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/engines/phptemplate/phptemplate.engine', 'phptemplate', 'theme_engine', '', 1, 0, 0, 0)");
1054    db_query("INSERT INTO {system} (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES ('themes/garland/page.tpl.php', 'garland', 'theme', 'themes/engines/phptemplate/phptemplate.engine', 1, 0, 0, 0)");
1055  
1056    db_query("INSERT INTO {users} (uid,name,mail) VALUES(0,'','')");
1057  
1058    db_query("INSERT INTO {role} (rid, name) VALUES (". DRUPAL_ANONYMOUS_RID .", 'anonymous user')");
1059    db_query("INSERT INTO {role} (rid, name) VALUES (". DRUPAL_AUTHENTICATED_RID .", 'authenticated user')");
1060  
1061    db_query("INSERT INTO {permission} VALUES (1,'access content',0)");
1062    db_query("INSERT INTO {permission} VALUES (2,'access comments, access content, post comments, post comments without approval',0)");
1063  
1064    db_query("INSERT INTO {variable} (name,value) VALUES('theme_default', 's:7:\"garland\";')");
1065  
1066    db_query("INSERT INTO {blocks} (module,delta,theme,status,pages) VALUES('user', 0, 'garland', 1, '')");
1067    db_query("INSERT INTO {blocks} (module,delta,theme,status,pages) VALUES('user', 1, 'garland', 1, '')");
1068  
1069    db_query("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0)");
1070  
1071    db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Filtered HTML',',1,2,',1)");
1072    db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('PHP code','',0)");
1073    db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('Full HTML','',1)");
1074  
1075    db_query("INSERT INTO {filters} VALUES (1,'filter',3,0)");
1076    db_query("INSERT INTO {filters} VALUES (1,'filter',0,1)");
1077    db_query("INSERT INTO {filters} VALUES (1,'filter',2,2)");
1078  
1079    db_query("INSERT INTO {filters} VALUES (2,'filter',1,0)");
1080  
1081    db_query("INSERT INTO {filters} VALUES (3,'filter',3,0)");
1082    db_query("INSERT INTO {filters} VALUES (3,'filter',2,1)");
1083  
1084    db_query("INSERT INTO {variable} (name,value) VALUES ('filter_html_1','i:1;')");
1085  
1086    db_query("INSERT INTO {variable} (name, value) VALUES ('node_options_forum', '%s')", 'a:1:{i:0;s:6:"status";}');
1087  
1088    db_query("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) VALUES (2, 0, '', 'Primary links', '', 0, 115)");
1089    db_query("INSERT INTO {variable} VALUES ('menu_primary_menu', 'i:2;')");
1090    db_query("INSERT INTO {variable} VALUES ('menu_secondary_menu', 'i:2;')");
1091  }
1092  
1093  // Updates for core
1094  
1095  function system_update_110() {
1096    $ret = array();
1097  
1098    // TODO: needs PGSQL version
1099    if ($GLOBALS['db_type'] == 'mysql') {
1100      /*
1101      ** Search
1102      */
1103  
1104      $ret[] = update_sql('DROP TABLE {search_index}');
1105      $ret[] = update_sql("CREATE TABLE {search_index} (
1106        word varchar(50) NOT NULL default '',
1107        sid int unsigned NOT NULL default '0',
1108        type varchar(16) default NULL,
1109        fromsid int unsigned NOT NULL default '0',
1110        fromtype varchar(16) default NULL,
1111        score int unsigned default NULL,
1112        KEY sid (sid),
1113        KEY fromsid (fromsid),
1114        KEY word (word)
1115        )");
1116  
1117      $ret[] = update_sql("CREATE TABLE {search_total} (
1118        word varchar(50) NOT NULL default '',
1119        count int unsigned default NULL,
1120        PRIMARY KEY word (word)
1121        )");
1122  
1123  
1124      /*
1125      ** Blocks
1126      */
1127  
1128      $ret[] = update_sql('ALTER TABLE {blocks} DROP path');
1129      $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility tinyint NOT NULL');
1130      $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text NOT NULL');
1131    }
1132    elseif ($GLOBALS['db_type'] == 'pgsql') {
1133      /*
1134      ** Search
1135      */
1136      $ret[] = update_sql('DROP TABLE {search_index}');
1137      $ret[] = update_sql("CREATE TABLE {search_index} (
1138        word varchar(50) NOT NULL default '',
1139        sid integer NOT NULL default '0',
1140        type varchar(16) default NULL,
1141        fromsid integer NOT NULL default '0',
1142        fromtype varchar(16) default NULL,
1143        score integer default NULL
1144        )");
1145      $ret[] = update_sql("CREATE INDEX {search_index}_sid_idx on {search_index}(sid)");
1146      $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_idx on {search_index}(fromsid)");
1147      $ret[] = update_sql("CREATE INDEX {search_index}_word_idx on {search_index}(word)");
1148  
1149      $ret[] = update_sql("CREATE TABLE {search_total} (
1150        word varchar(50) NOT NULL default '' PRIMARY KEY,
1151        count integer default NULL
1152        )");
1153  
1154  
1155      /*
1156      ** Blocks
1157      */
1158      // Postgres can only drop columns since 7.4
1159      #$ret[] = update_sql('ALTER TABLE {blocks} DROP path');
1160  
1161      $ret[] = update_sql('ALTER TABLE {blocks} ADD visibility smallint');
1162      $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN visibility set default 0");
1163      $ret[] = update_sql('UPDATE {blocks} SET visibility = 0');
1164      $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN visibility SET NOT NULL');
1165      $ret[] = update_sql('ALTER TABLE {blocks} ADD pages text');
1166      $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN pages set default ''");
1167      $ret[] = update_sql("UPDATE {blocks} SET pages = ''");
1168      $ret[] = update_sql('ALTER TABLE {blocks} ALTER COLUMN pages SET NOT NULL');
1169  
1170    }
1171  
1172    $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'");
1173  
1174    $ret[] = update_sql('UPDATE {blocks} SET status = 1, custom = 2 WHERE status = 0 AND custom = 1');
1175  
1176    return $ret;
1177  }
1178  
1179  function system_update_111() {
1180    $ret = array();
1181  
1182    $ret[] = update_sql("DELETE FROM {variable} WHERE name LIKE 'throttle_%'");
1183  
1184    if ($GLOBALS['db_type'] == 'mysql') {
1185      $ret[] = update_sql('ALTER TABLE {sessions} ADD PRIMARY KEY sid (sid)');
1186    }
1187    elseif ($GLOBALS['db_type'] == 'pgsql') {
1188      $ret[] = update_sql('ALTER TABLE {sessions} ADD UNIQUE(sid)');
1189    }
1190  
1191    return $ret;
1192  }
1193  
1194  function system_update_112() {
1195    $ret = array();
1196  
1197    if ($GLOBALS['db_type'] == 'mysql') {
1198      $ret[] = update_sql("CREATE TABLE {flood} (
1199        event varchar(64) NOT NULL default '',
1200        hostname varchar(128) NOT NULL default '',
1201        timestamp int NOT NULL default '0'
1202       );");
1203    }
1204    elseif ($GLOBALS['db_type'] == 'pgsql') {
1205      $ret[] = update_sql("CREATE TABLE {flood} (
1206        event varchar(64) NOT NULL default '',
1207        hostname varchar(128) NOT NULL default '',
1208        timestamp integer NOT NULL default 0
1209       );");
1210    }
1211  
1212    return $ret;
1213  }
1214  
1215  function system_update_113() {
1216    $ret = array();
1217  
1218    if ($GLOBALS['db_type'] == 'mysql') {
1219      $ret[] = update_sql('ALTER TABLE {accesslog} ADD aid int NOT NULL auto_increment, ADD PRIMARY KEY (aid)');
1220    }
1221    elseif ($GLOBALS['db_type'] == 'pgsql') {
1222      $ret[] = update_sql("SELECT * INTO TEMPORARY {accesslog}_t FROM {accesslog}");
1223      $ret[] = update_sql("DROP TABLE {accesslog}");
1224      $ret[] = update_sql("CREATE TABLE {accesslog} (
1225        aid serial,
1226        title varchar(255) default NULL,
1227        path varchar(255) default NULL,
1228        url varchar(255) default NULL,
1229        hostname varchar(128) default NULL,
1230        uid integer default '0',
1231        timestamp integer NOT NULL default '0'
1232      )");
1233      $ret[] = update_sql("INSERT INTO {accesslog} (title, path, url, hostname, uid, timestamp) SELECT title, path, url, hostname, uid, timestamp FROM {accesslog}_t");
1234  
1235      $ret[] = update_sql("DROP TABLE {accesslog}_t");
1236      $ret[] = update_sql("CREATE INDEX {accesslog}_timestamp_idx ON {accesslog} (timestamp);");
1237  
1238    }
1239  
1240    // Flush the menu cache:
1241    cache_clear_all('menu:', TRUE);
1242  
1243    return $ret;
1244  }
1245  
1246  function system_update_114() {
1247    $ret = array();
1248    if ($GLOBALS['db_type'] == 'mysql') {
1249      $ret[] = update_sql("CREATE TABLE {queue} (
1250        nid int unsigned NOT NULL,
1251        uid int unsigned NOT NULL,
1252        vote int NOT NULL default '0',
1253        PRIMARY KEY (nid, uid)
1254       )");
1255    }
1256    else if ($GLOBALS['db_type'] == 'pgsql') {
1257      $ret[] = update_sql("CREATE TABLE {queue} (
1258        nid integer NOT NULL default '0',
1259        uid integer NOT NULL default '0',
1260        vote integer NOT NULL default '0',
1261        PRIMARY KEY (nid, uid)
1262      )");
1263      $ret[] = update_sql("CREATE INDEX {queue}_nid_idx ON queue(nid)");
1264      $ret[] = update_sql("CREATE INDEX {queue}_uid_idx ON queue(uid)");
1265    }
1266  
1267    $result = db_query("SELECT nid, votes, score, users FROM {node}");
1268    while ($node = db_fetch_object($result)) {
1269      if (isset($node->users)) {
1270        $arr = explode(',', $node->users);
1271        unset($node->users);
1272        foreach ($arr as $value) {
1273          $arr2 = explode('=', trim($value));
1274          if (isset($arr2[0]) && isset($arr2[1])) {
1275            switch ($arr2[1]) {
1276              case '+ 1':
1277                db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], 1);
1278                break;
1279              case '- 1':
1280                db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], -1);
1281                break;
1282              default:
1283                db_query("INSERT INTO {queue} (nid, uid, vote) VALUES (%d, %d, %d)", $node->nid, (int)$arr2[0], 0);
1284            }
1285          }
1286        }
1287      }
1288    }
1289  
1290    if ($GLOBALS['db_type'] == 'mysql') {
1291      // Postgres only supports dropping of columns since 7.4
1292      $ret[] = update_sql("ALTER TABLE {node} DROP votes");
1293      $ret[] = update_sql("ALTER TABLE {node} DROP score");
1294      $ret[] = update_sql("ALTER TABLE {node} DROP users");
1295    }
1296  
1297    return $ret;
1298  }
1299  
1300  function system_update_115() {
1301    $ret = array();
1302  
1303    // This update has been moved to update_fix_watchdog_115 in update.php because it
1304    // is needed for the basic functioning of the update script.
1305  
1306    return $ret;
1307  }
1308  
1309  function system_update_116() {
1310    return array(update_sql("DELETE FROM {system} WHERE name = 'admin'"));
1311  }
1312  
1313  function system_update_117() {
1314    $ret = array();
1315    if ($GLOBALS['db_type'] == 'mysql') {
1316      $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
1317                           vid int NOT NULL default '0',
1318                           type varchar(16) NOT NULL default '',
1319                           PRIMARY KEY (vid, type))");
1320    }
1321    else if ($GLOBALS['db_type'] == 'pgsql') {
1322      $ret[] = update_sql("CREATE TABLE {vocabulary_node_types} (
1323                           vid serial,
1324                           type varchar(16) NOT NULL default '',
1325                            PRIMARY KEY (vid, type)) ");
1326    }
1327    return $ret;
1328  }
1329  
1330  function system_update_118() {
1331    $ret = array();
1332    $node_types = array();
1333    $result = db_query('SELECT vid, nodes FROM {vocabulary}');
1334    while ($vocabulary = db_fetch_object($result)) {
1335      $node_types[$vocabulary->vid] = explode(',', $vocabulary->nodes);
1336    }
1337    foreach ($node_types as $vid => $type_array) {
1338      foreach ($type_array as $type) {
1339        db_query("INSERT INTO {vocabulary_node_types} (vid, type) VALUES (%d, '%s')", $vid, $type);
1340      }
1341    }
1342    if ($GLOBALS['db_type'] == 'mysql') {
1343      $ret[] = update_sql("ALTER TABLE {vocabulary} DROP nodes");
1344    }
1345    return $ret;
1346  }
1347  
1348  function system_update_119() {
1349    $ret = array();
1350  
1351    foreach (node_get_types() as $type => $name) {
1352      $node_options = array();
1353      if (variable_get('node_status_'. $type, 1)) {
1354        $node_options[] = 'status';
1355      }
1356      if (variable_get('node_moderate_'. $type, 0)) {
1357        $node_options[] = 'moderate';
1358      }
1359      if (variable_get('node_promote_'. $type, 1)) {
1360        $node_options[] = 'promote';
1361      }
1362      if (variable_get('node_sticky_'. $type, 0)) {
1363        $node_options[] = 'sticky';
1364      }
1365      if (variable_get('node_revision_'. $type, 0)) {
1366        $node_options[] = 'revision';
1367      }
1368      variable_set('node_options_'. $type, $node_options);
1369      variable_del('node_status_'. $type);
1370      variable_del('node_moderate_'. $type);
1371      variable_del('node_promote_'. $type);
1372      variable_del('node_sticky_'. $type);
1373      variable_del('node_revision_'. $type);
1374    }
1375  
1376    return $ret;
1377  }
1378  
1379  function system_update_120() {
1380    $ret = array();
1381  
1382    // Rewrite old URL aliases. Works for both PostgreSQL and MySQL
1383    $result = db_query("SELECT pid, src FROM {url_alias} WHERE src LIKE 'blog/%%'");
1384    while ($alias = db_fetch_object($result)) {
1385      list(, $page, $op, $uid) = explode('/', $alias->src);
1386      if ($page == 'feed') {
1387        $new = "blog/$uid/feed";
1388        update_sql("UPDATE {url_alias} SET src = '%s' WHERE pid = '%s'", $new, $alias->pid);
1389      }
1390    }
1391  
1392    return $ret;
1393  }
1394  
1395  function system_update_121() {
1396    $ret = array();
1397  
1398    // Remove the unused page table.
1399    $ret[] = update_sql('DROP TABLE {page}');
1400  
1401    return $ret;
1402  }
1403  
1404  function system_update_122() {
1405  
1406    $ret = array();
1407    $ret[] = update_sql("ALTER TABLE {blocks} ADD types text");
1408    return $ret;
1409  
1410  }
1411  
1412  function system_update_123() {
1413    $ret = array();
1414  
1415    if ($GLOBALS['db_type'] == 'mysql') {
1416      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255) NOT NULL default ''");
1417    }
1418    elseif ($GLOBALS['db_type'] == 'pgsql') {
1419      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD module varchar(255)");
1420      $ret[] = update_sql("UPDATE {vocabulary} SET module = ''");
1421      $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET NOT NULL");
1422      $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER COLUMN module SET DEFAULT ''");
1423    }
1424  
1425    $ret[] = update_sql("UPDATE {vocabulary} SET module = 'taxonomy'");
1426    $vid = variable_get('forum_nav_vocabulary', '');
1427    if (!empty($vid)) {
1428      $ret[] = update_sql("UPDATE {vocabulary} SET module = 'forum' WHERE vid = " . $vid);
1429    }
1430  
1431    return $ret;
1432  }
1433  
1434  function system_update_124() {
1435    $ret = array();
1436  
1437    if ($GLOBALS['db_type'] == 'mysql') {
1438      // redo update_105, correctly creating node_comment_statistics
1439      $ret[] = update_sql("DROP TABLE IF EXISTS {node_comment_statistics}");
1440  
1441      $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
1442        nid int unsigned NOT NULL auto_increment,
1443        last_comment_timestamp int NOT NULL default '0',
1444        last_comment_name varchar(60) default NULL,
1445        last_comment_uid int NOT NULL default '0',
1446        comment_count int unsigned NOT NULL default '0',
1447        PRIMARY KEY (nid),
1448        KEY node_comment_timestamp (last_comment_timestamp)
1449        )");
1450    }
1451  
1452    else {
1453      // also drop incorrectly named table for PostgreSQL
1454      $ret[] = update_sql("DROP TABLE {node}_comment_statistics");
1455  
1456      $ret[] = update_sql("CREATE TABLE {node_comment_statistics} (
1457        nid integer NOT NULL,
1458        last_comment_timestamp integer NOT NULL default '0',
1459        last_comment_name varchar(60)  default NULL,
1460        last_comment_uid integer NOT NULL default '0',
1461        comment_count integer NOT NULL default '0',
1462        PRIMARY KEY (nid)
1463      )");
1464  
1465      $ret[] = update_sql("CREATE INDEX {node_comment_statistics}_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp);
1466  ");
1467    }
1468  
1469    // initialize table
1470    $ret[] = update_sql("INSERT INTO {node_comment_statistics} (nid, last_comment_timestamp, last_comment_name, last_comment_uid, comment_count) SELECT n.nid, n.changed, NULL, 0, 0 FROM {node} n");
1471  
1472    // fill table
1473    $result = db_query("SELECT c.nid, c.timestamp, c.name, c.uid, COUNT(c.nid) as comment_count FROM {node} n LEFT JOIN {comments} c ON c.nid = n.nid WHERE c.status = 0 GROUP BY c.nid, c.timestamp, c.name, c.uid");
1474    while ($comment_record = db_fetch_object($result)) {
1475      $count = db_result(db_query('SELECT COUNT(cid) FROM {comments} WHERE nid = %d AND status = 0', $comment_record->nid));
1476      db_query("UPDATE {node_comment_statistics} SET comment_count = %d, last_comment_timestamp = %d, last_comment_name = '%s', last_comment_uid = %d WHERE nid = %d", $count, $comment_record->timestamp, $comment_record->name, $comment_record->uid, $comment_record->nid);
1477    }
1478  
1479    return $ret;
1480  }
1481  
1482  function system_update_125() {
1483    // Postgres only update.
1484    $ret = array();
1485  
1486    if ($GLOBALS['db_type'] == 'pgsql') {
1487  
1488      $ret[] = update_sql("CREATE OR REPLACE FUNCTION if(boolean, anyelement, anyelement) RETURNS anyelement AS '
1489            SELECT CASE WHEN $1 THEN $2 ELSE $3 END;
1490          ' LANGUAGE 'sql'");
1491  
1492      $ret[] = update_sql("CREATE FUNCTION greatest(integer, integer, integer) RETURNS integer AS '
1493                            SELECT greatest($1, greatest($2, $3));
1494                          ' LANGUAGE 'sql'");
1495  
1496    }
1497  
1498    return $ret;
1499  }
1500  
1501  function system_update_126() {
1502    variable_set('forum_block_num_0', variable_get('forum_block_num', 5));
1503    variable_set('forum_block_num_1', variable_get('forum_block_num', 5));
1504    variable_del('forum_block_num');
1505  
1506    return array();
1507  }
1508  
1509  function system_update_127() {
1510    $ret = array();
1511    if ($GLOBALS['db_type'] == 'pgsql') {
1512      $ret[] = update_sql("ALTER TABLE {poll} RENAME voters TO polled");
1513    }
1514    else if ($GLOBALS['db_type'] == 'mysql') {
1515      $ret[] = update_sql("ALTER TABLE {poll} CHANGE voters polled longtext");
1516    }
1517    return $ret;
1518  }
1519  
1520  function system_update_128() {
1521    $ret = array();
1522  
1523    if ($GLOBALS['db_type'] == 'mysql') {
1524      $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
1525    }
1526    elseif ($GLOBALS['db_type'] == 'pgsql') {
1527      $ret[] = update_sql('ALTER TABLE {term_node} ADD PRIMARY KEY (tid,nid)');
1528    }
1529  
1530    return $ret;
1531  }
1532  
1533  function system_update_129() {
1534    $ret = array();
1535  
1536    if ($GLOBALS['db_type'] == 'mysql') {
1537      $ret[] = update_sql("ALTER TABLE {vocabulary} ADD tags tinyint unsigned default '0' NOT NULL");
1538    }
1539    elseif ($GLOBALS['db_type'] == 'pgsql') {
1540      db_add_column($ret, 'vocabulary', 'tags', 'smallint', array('default' => 0, 'not null' => TRUE));
1541    }
1542  
1543    return $ret;
1544  }
1545  
1546  function system_update_130() {
1547    $ret = array();
1548  
1549    // This update has been moved to update_fix_sessions in update.php because it
1550    // is needed for the basic functioning of the update script.
1551  
1552    return $ret;
1553  }
1554  
1555  function system_update_131() {
1556    $ret = array();
1557  
1558    if ($GLOBALS['db_type'] == 'mysql') {
1559      $ret[] = update_sql("ALTER TABLE {boxes} DROP INDEX title");
1560      // Removed recreation of the index, which is not present in the db schema
1561    }
1562    elseif ($GLOBALS['db_type'] == 'pgsql') {
1563      $ret[] = update_sql("ALTER TABLE {boxes} DROP CONSTRAINT {boxes}_title_key");
1564    }
1565  
1566    return $ret;
1567  }
1568  
1569  function system_update_132() {
1570    /**
1571     * PostgreSQL only update.
1572     */
1573    $ret = array();
1574  
1575    if (!variable_get('update_132_done', FALSE)) {
1576      if ($GLOBALS['db_type'] == 'pgsql') {
1577        $ret[] = update_sql('DROP TABLE {search_total}');
1578        $ret[] = update_sql("CREATE TABLE {search_total} (
1579          word varchar(50) NOT NULL default '',
1580               count float default NULL)");
1581        $ret[] = update_sql('CREATE INDEX {search_total}_word_idx ON {search_total}(word)');
1582  
1583        /**
1584         * Wipe the search index
1585         */
1586        include_once './'. drupal_get_path('module', 'search') .'/search.module';
1587        search_wipe();
1588      }
1589  
1590      variable_del('update_132_done');
1591    }
1592  
1593    return $ret;
1594  }
1595  
1596  function system_update_133() {
1597    $ret = array();
1598  
1599    if ($GLOBALS['db_type'] == 'mysql') {
1600      $ret[] = update_sql("CREATE TABLE {contact} (
1601        subject varchar(255) NOT NULL default '',
1602        recipients longtext NOT NULL,
1603        reply longtext NOT NULL
1604        )");
1605      $ret[] = update_sql("ALTER TABLE {users} ADD login int NOT NULL default '0'");
1606    }
1607    elseif ($GLOBALS['db_type'] == 'pgsql') {
1608      // Table {contact} is changed in update_143() so I have moved it's creation there.
1609      // It was never created here for postgres because of errors.
1610  
1611      db_add_column($ret, 'users', 'login', 'int', array('default' => 0, 'not null' => TRUE));
1612    }
1613  
1614    return $ret;
1615  }
1616  
1617  function system_update_134() {
1618    $ret = array();
1619    $ret[] = update_sql('ALTER TABLE {blocks} DROP types');
1620    return $ret;
1621  }
1622  
1623  function system_update_135() {
1624    if (!variable_get('update_135_done', FALSE)) {
1625      $result = db_query("SELECT delta FROM {blocks} WHERE module = 'aggregator'");
1626      while ($block = db_fetch_object($result)) {
1627        list($type, $id) = explode(':', $block->delta);
1628        db_query("UPDATE {blocks} SET delta = '%s' WHERE module = 'aggregator' AND delta = '%s'", $type .'-'. $id, $block->delta);
1629      }
1630  
1631      variable_del('update_135_done');
1632    }
1633    return array();
1634  }
1635  
1636  function system_update_136() {
1637    $ret = array();
1638  
1639    switch ($GLOBALS['db_type']) {
1640      case 'pgsql':
1641        $ret[] = update_sql("DROP INDEX {users}_changed_idx"); // We drop the index first because it won't be renamed
1642        $ret[] = update_sql("ALTER TABLE {users} RENAME changed TO access");
1643        $ret[] = update_sql("CREATE INDEX {users}_access_idx on {users}(access)"); // Re-add the index
1644        break;
1645      case 'mysql':
1646      case 'mysqli':
1647        $ret[] = update_sql("ALTER TABLE {users} CHANGE COLUMN changed access int NOT NULL default '0'");
1648        break;
1649    }
1650  
1651    $ret[] = update_sql('UPDATE {users} SET access = login WHERE login > created');
1652    $ret[] = update_sql('UPDATE {users} SET access = created WHERE access = 0');
1653    return $ret;
1654  }
1655  
1656  function system_update_137() {
1657    $ret = array();
1658  
1659    if (!variable_get('update_137_done', FALSE)) {
1660      if ($GLOBALS['db_type'] == 'mysql') {
1661        $ret[] = update_sql("ALTER TABLE {locales_source} CHANGE location location varchar(255) NOT NULL default ''");
1662      }
1663      elseif ($GLOBALS['db_type'] == 'pgsql') {
1664        db_change_column($ret, 'locales_source', 'location', 'location', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
1665      }
1666      variable_del('update_137_done');
1667    }
1668  
1669    return $ret;
1670  }
1671  
1672  function system_update_138() {
1673    $ret = array();
1674    // duplicate of update_97 which never got into the default database.* files.
1675    $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('node/feed', 'rss.xml')");
1676    return $ret;
1677  }
1678  
1679  function system_update_139() {
1680    $ret = array();
1681    switch ($GLOBALS['db_type']) {
1682      case 'pgsql':
1683        db_add_column($ret, 'accesslog', 'timer', 'int', array('not null' => TRUE, 'default' => 0));
1684        break;
1685      case 'mysql':
1686      case 'mysqli':
1687        $ret[] = update_sql("ALTER TABLE {accesslog} ADD timer int unsigned NOT NULL default '0'");
1688        break;
1689    }
1690  
1691    return $ret;
1692  }
1693  
1694  function system_update_140() {
1695    $ret = array();
1696  
1697    if ($GLOBALS['db_type'] == 'mysql') {
1698      $ret[] = update_sql("ALTER TABLE {url_alias} ADD INDEX (src)");
1699    }
1700    elseif ($GLOBALS['db_type'] == 'pgsql') {
1701      $ret[] = update_sql("CREATE INDEX {url_alias}_src_idx ON {url_alias}(src)");
1702    }
1703    return $ret;
1704  }
1705  
1706  function system_update_141() {
1707    $ret = array();
1708  
1709    variable_del('upload_maxsize_total');
1710  
1711    return $ret;
1712  }
1713  
1714  function system_update_142() {
1715    $ret = array();
1716  
1717    // This update has been moved to update_fix_sessions in update.php because it
1718    // is needed for the basic functioning of the update script.
1719  
1720    return $ret;
1721  }
1722  
1723  function system_update_143() {
1724    $ret = array();
1725  
1726    if ($GLOBALS['db_type'] == 'mysql') {
1727      $ret[] = update_sql("ALTER TABLE {contact} CHANGE subject category VARCHAR(255) NOT NULL ");
1728      $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (category)");
1729    }
1730    elseif ($GLOBALS['db_type'] == 'pgsql') {
1731      // Why the table is created here? See update_133().
1732      $ret[] = update_sql("CREATE TABLE {contact} (
1733        category varchar(255) NOT NULL default '',
1734        recipients text NOT NULL default '',
1735        reply text NOT NULL default '',
1736        PRIMARY KEY (category))");
1737    }
1738  
1739    return $ret;
1740  }
1741  
1742  function system_update_144() {
1743    $ret = array();
1744    if ($GLOBALS['db_type'] == 'mysql') {
1745      $ret[] = update_sql("ALTER TABLE {node} CHANGE type type VARCHAR(32) NOT NULL");
1746    }
1747    elseif ($GLOBALS['db_type'] == 'pgsql') {
1748      $ret[] = update_sql("DROP INDEX {node}_type_idx"); // Drop indexes using "type" column
1749      $ret[] = update_sql("DROP INDEX {node}_title_idx");
1750      db_change_column($ret, 'node', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
1751      // Let's recreate the indexes
1752      $ret[] = update_sql("CREATE INDEX {node}_type_idx ON {node}(type)");
1753      $ret[] = update_sql("CREATE INDEX {node}_title_type_idx ON {node}(title,type)");
1754      $ret[] = update_sql("CREATE INDEX {node}_status_type_nid_idx ON {node}(status,type,nid)");
1755    }
1756    return $ret;
1757  }
1758  
1759  function system_update_145() {
1760    $default_theme = variable_get('theme_default', 'garland');
1761  
1762    $themes = list_themes();
1763    if (!array_key_exists($default_theme, $themes)) {
1764        variable_set('theme_default', 'garland');
1765        $default_theme = 'garland';
1766     }
1767  
1768    $ret = array();
1769  
1770    switch ($GLOBALS['db_type']) {
1771      case 'pgsql':
1772        db_change_column($ret, 'blocks', 'region', 'region', 'varchar(64)', array('default' => "'left'", 'not null' => TRUE));
1773        db_add_column($ret, 'blocks', 'theme', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
1774        break;
1775      case 'mysql':
1776      case 'mysqli':
1777        $ret[] = update_sql("ALTER TABLE {blocks} CHANGE region region varchar(64) default 'left' NOT NULL");
1778        $ret[] = update_sql("ALTER TABLE {blocks} ADD theme varchar(255) NOT NULL default ''");
1779        break;
1780    }
1781  
1782    // Intialize block data for default theme
1783    $ret[] = update_sql("UPDATE {blocks} SET region = 'left' WHERE region = '0'");
1784    $ret[] = update_sql("UPDATE {blocks} SET region = 'right' WHERE region = '1'");
1785    db_query("UPDATE {blocks} SET theme = '%s'", $default_theme);
1786  
1787    // Initialize block data for other enabled themes.
1788    $themes = list_themes();
1789    foreach (array_keys($themes) as $theme) {
1790      if (($theme != $default_theme) && $themes[$theme]->status == 1) {
1791        system_initialize_theme_blocks($theme);
1792      }
1793    }
1794  
1795    return $ret;
1796  }
1797  
1798  function system_update_146() {
1799    $ret = array();
1800  
1801    if ($GLOBALS['db_type'] == 'mysql') {
1802      $ret[] = update_sql("CREATE TABLE {node_revisions}
1803                                  SELECT nid, nid AS vid, uid, type, title, body, teaser, changed AS timestamp, format
1804                                  FROM {node}");
1805  
1806      $ret[] = update_sql("ALTER TABLE {node_revisions} CHANGE nid nid int unsigned NOT NULL default '0'");
1807      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD log longtext");
1808  
1809      $ret[] = update_sql("ALTER TABLE {node} ADD vid int unsigned NOT NULL default '0'");
1810      $ret[] = update_sql("ALTER TABLE {files} ADD vid int unsigned NOT NULL default '0'");
1811      $ret[] = update_sql("ALTER TABLE {book} ADD vid int unsigned NOT NULL default '0'");
1812      $ret[] = update_sql("ALTER TABLE {forum} ADD vid int unsigned NOT NULL default '0'");
1813  
1814      $ret[] = update_sql("ALTER TABLE {book} DROP PRIMARY KEY");
1815      $ret[] = update_sql("ALTER TABLE {forum} DROP PRIMARY KEY");
1816      $ret[] = update_sql("ALTER TABLE {files} DROP PRIMARY KEY");
1817  
1818      $ret[] = update_sql("UPDATE {node} SET vid = nid");
1819      $ret[] = update_sql("UPDATE {forum} SET vid = nid");
1820      $ret[] = update_sql("UPDATE {book} SET vid = nid");
1821      $ret[] = update_sql("UPDATE {files} SET vid = nid");
1822  
1823      $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY vid (vid)");
1824      $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY vid (vid)");
1825      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD PRIMARY KEY vid (vid)");
1826      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY nid (nid)");
1827      $ret[] = update_sql("ALTER TABLE {node_revisions} ADD KEY uid (uid)");
1828  
1829      $ret[] = update_sql("CREATE TABLE {old_revisions} SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
1830  
1831      $ret[] = update_sql("ALTER TABLE {book} ADD KEY nid (nid)");
1832      $ret[] = update_sql("ALTER TABLE {forum} ADD KEY nid (nid)");
1833      $ret[] = update_sql("ALTER TABLE {files} ADD KEY fid (fid)");
1834      $ret[] = update_sql("ALTER TABLE {files} ADD KEY vid (vid)");
1835      $vid = db_next_id('{node}_nid');
1836      $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{node_revisions}_vid', $vid)");
1837    }
1838    else { // pgsql
1839      $ret[] = update_sql("CREATE TABLE {node_revisions} (
1840        nid integer NOT NULL default '0',
1841        vid integer NOT NULL default '0',
1842        uid integer NOT NULL default '0',
1843        title varchar(128) NOT NULL default '',
1844        body text NOT NULL default '',
1845        teaser text NOT NULL default '',
1846        log text NOT NULL default '',
1847        timestamp integer NOT NULL default '0',
1848        format int NOT NULL default '0',
1849        PRIMARY KEY (vid))");
1850      $ret[] = update_sql("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, timestamp, format)
1851        SELECT nid, nid AS vid, uid, title, body, teaser, changed AS timestamp, format
1852        FROM {node}");
1853      $ret[] = update_sql('CREATE INDEX {node_revisions}_nid_idx ON {node_revisions}(nid)');
1854      $ret[] = update_sql('CREATE INDEX {node_revisions}_uid_idx ON {node_revisions}(uid)');
1855      $vid = db_next_id('{node}_nid');
1856      $ret[] = update_sql("CREATE SEQUENCE {node_revisions}_vid_seq INCREMENT 1 START $vid");
1857  
1858      db_add_column($ret, 'node',  'vid', 'int', array('not null' => TRUE, 'default' => 0));
1859      db_add_column($ret, 'files', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
1860      db_add_column($ret, 'book',  'vid', 'int', array('not null' => TRUE, 'default' => 0));
1861      db_add_column($ret, 'forum', 'vid', 'int', array('not null' => TRUE, 'default' => 0));
1862  
1863      $ret[] = update_sql("ALTER TABLE {book} DROP CONSTRAINT {book}_pkey");
1864      $ret[] = update_sql("ALTER TABLE {forum} DROP CONSTRAINT {forum}_pkey");
1865      $ret[] = update_sql("ALTER TABLE {files} DROP CONSTRAINT {files}_pkey");
1866  
1867      $ret[] = update_sql("UPDATE {node} SET vid = nid");
1868      $ret[] = update_sql("UPDATE {forum} SET vid = nid");
1869      $ret[] = update_sql("UPDATE {book} SET vid = nid");
1870      $ret[] = update_sql("UPDATE {files} SET vid = nid");
1871  
1872      $ret[] = update_sql("ALTER TABLE {book} ADD PRIMARY KEY (vid)");
1873      $ret[] = update_sql("ALTER TABLE {forum} ADD PRIMARY KEY (vid)");
1874  
1875      $ret[] = update_sql("CREATE TABLE {old_revisions} AS SELECT nid, type, revisions FROM {node} WHERE revisions != ''");
1876  
1877      $ret[] = update_sql('CREATE INDEX {node}_vid_idx ON {node}(vid)');
1878      $ret[] = update_sql('CREATE INDEX {forum}_nid_idx ON {forum}(nid)');
1879      $ret[] = update_sql('CREATE INDEX {files}_fid_idx ON {files}(fid)');
1880      $ret[] = update_sql('CREATE INDEX {files}_vid_idx ON {files}(vid)');
1881    }
1882  
1883    // Move logs too.
1884    $result = db_query("SELECT nid, log FROM {book} WHERE log != ''");
1885    while ($row = db_fetch_object($result)) {
1886      db_query("UPDATE {node_revisions} SET log = '%s' WHERE vid = %d", $row->log, $row->nid);
1887    }
1888  
1889    $ret[] = update_sql("ALTER TABLE {book} DROP log");
1890    $ret[] = update_sql("ALTER TABLE {node} DROP teaser");
1891    $ret[] = update_sql("ALTER TABLE {node} DROP body");
1892    $ret[] = update_sql("ALTER TABLE {node} DROP format");
1893    $ret[] = update_sql("ALTER TABLE {node} DROP revisions");
1894  
1895    return $ret;
1896  }
1897  
1898  function system_update_147() {
1899    $ret = array();
1900  
1901    // this update is mysql only, pgsql should get it right in the first try.
1902    if ($GLOBALS['db_type'] == 'mysql') {
1903      $ret[] = update_sql("ALTER TABLE {node_revisions} DROP type");
1904    }
1905  
1906    return $ret;
1907  }
1908  
1909  function system_update_148() {
1910    $ret = array();
1911  
1912    // Add support for tracking users' session ids (useful for tracking anon users)
1913    switch ($GLOBALS['db_type']) {
1914      case 'pgsql':
1915        db_add_column($ret, 'accesslog', 'sid', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
1916        break;
1917      case 'mysql':
1918      case 'mysqli':
1919        $ret[] = update_sql("ALTER TABLE {accesslog} ADD sid varchar(32) NOT NULL default ''");
1920        break;
1921    }
1922  
1923    return $ret;
1924  }
1925  
1926  function system_update_149() {
1927    $ret = array();
1928  
1929    switch ($GLOBALS['db_type']) {
1930      case 'pgsql':
1931        db_add_column($ret, 'files', 'description', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
1932        break;
1933      case 'mysql':
1934      case 'mysqli':
1935        $ret[] = update_sql("ALTER TABLE {files} ADD COLUMN description VARCHAR(255) NOT NULL DEFAULT ''");
1936        break;
1937      default:
1938        break;
1939    }
1940  
1941    return $ret;
1942  }
1943  
1944  function system_update_150() {
1945    $ret = array();
1946  
1947    $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'node_cron_last'");
1948    $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'minimum_word_size'");
1949    $ret[] = update_sql("DELETE FROM {variable} WHERE name = 'remove_short'");
1950  
1951    $ret[] = update_sql("DELETE FROM {node_counter} WHERE nid = 0");
1952  
1953    $ret[] = update_sql('DROP TABLE {search_index}');
1954    $ret[] = update_sql('DROP TABLE {search_total}');
1955  
1956    switch ($GLOBALS['db_type']) {
1957      case 'mysqli':
1958      case 'mysql':
1959        $ret[] = update_sql("CREATE TABLE {search_dataset} (
1960                             sid int unsigned NOT NULL default '0',
1961                             type varchar(16) default NULL,
1962                             data longtext NOT NULL,
1963                             KEY sid_type (sid, type)
1964                             )");
1965  
1966        $ret[] = update_sql("CREATE TABLE {search_index} (
1967                             word varchar(50) NOT NULL default '',
1968                             sid int unsigned NOT NULL default '0',
1969                             type varchar(16) default NULL,
1970                             fromsid int unsigned NOT NULL default '0',
1971                             fromtype varchar(16) default NULL,
1972                             score float default NULL,
1973                             KEY sid_type (sid, type),
1974                             KEY from_sid_type (fromsid, fromtype),
1975                             KEY word (word)
1976                             )");
1977  
1978        $ret[] = update_sql("CREATE TABLE {search_total} (
1979                             word varchar(50) NOT NULL default '',
1980                             count float default NULL,
1981                             PRIMARY KEY word (word)
1982                             )");
1983        break;
1984      case 'pgsql':
1985        $ret[] = update_sql("CREATE TABLE {search_dataset} (
1986          sid integer NOT NULL default '0',
1987          type varchar(16) default NULL,
1988          data text NOT NULL default '')");
1989        $ret[] = update_sql("CREATE INDEX {search_dataset}_sid_type_idx ON {search_dataset}(sid, type)");
1990  
1991        $ret[] = update_sql("CREATE TABLE {search_index} (
1992          word varchar(50) NOT NULL default '',
1993          sid integer NOT NULL default '0',
1994          type varchar(16) default NULL,
1995          fromsid integer NOT NULL default '0',
1996          fromtype varchar(16) default NULL,
1997          score float default NULL)");
1998        $ret[] = update_sql("CREATE INDEX {search_index}_sid_type_idx ON {search_index}(sid, type)");
1999        $ret[] = update_sql("CREATE INDEX {search_index}_fromsid_fromtype_idx ON {search_index}(fromsid, fromtype)");
2000        $ret[] = update_sql("CREATE INDEX {search_index}_word_idx ON {search_index}(word)");
2001  
2002        $ret[] = update_sql("CREATE TABLE {search_total} (
2003          word varchar(50) NOT NULL default '',
2004          count float default NULL,
2005          PRIMARY KEY(word))");
2006        break;
2007      default:
2008        break;
2009    }
2010    return $ret;
2011  }
2012  
2013  function system_update_151() {
2014    $ret = array();
2015  
2016    $ts = variable_get('theme_settings', NULL);
2017  
2018    // set up data array so we can loop over both sets of links
2019    $menus = array(0 => array('links_var' => 'primary_links',
2020                              'toggle_var' => 'toggle_primary_links',
2021                              'more_var' => 'primary_links_more',
2022                              'menu_name' => 'Primary links',
2023                              'menu_var' => 'menu_primary_menu',
2024                              'pid' => 0),
2025                   1 => array('links_var' => 'secondary_links',
2026                              'toggle_var' => 'toggle_secondary_links',
2027                              'more_var' => 'secondary_links_more',
2028                              'menu_name' => 'Secondary links',
2029                              'menu_var' => 'menu_secondary_menu',
2030                              'pid' => 0));
2031  
2032    for ($loop = 0; $loop <= 1 ; $loop ++) {
2033      // create new Primary and Secondary links menus
2034      $menus[$loop]['pid'] = db_next_id('{menu}_mid');
2035      $ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " .
2036                           "VALUES ({$menus[$loop]['pid']}, 0, '', '{$menus[$loop]['menu_name']}', '', 0, 115)");
2037  
2038      // Gather links from various settings into a single array.
2039      $phptemplate_links = variable_get("phptemplate_". $menus[$loop]['links_var'], array());
2040      if (empty($phptemplate_links)) {
2041        $phptemplate_links = array('text' => array(), 'link' => array());
2042      }
2043      if (isset($ts) && is_array($ts)) {
2044        if (is_array($ts[$menus[$loop]['links_var']])) {
2045          $theme_links = $ts[$menus[$loop]['links_var']];
2046        }
2047        else {
2048          // Convert old xtemplate style links.
2049          preg_match_all('/<a\s+.*?href=[\"\'\s]?(.*?)[\"\'\s]?>(.*?)<\/a>/i', $ts[$menus[$loop]['links_var']], $urls);
2050          $theme_links['text'] = $urls[2];
2051          $theme_links['link'] = $urls[1];
2052        }
2053      }
2054      else {
2055        $theme_links = array('text' => array(), 'link' => array());
2056      }
2057      $links['text'] = array_merge($phptemplate_links['text'], $theme_links['text']);
2058      $links['link'] = array_merge($phptemplate_links['link'], $theme_links['link']);
2059  
2060      // insert all entries from theme links into new menus
2061      $num_inserted = 0;
2062      for ($i = 0; $i < count($links['text']); $i++) {
2063        if ($links['text'][$i] != "" && $links['link'][$i] != "") {
2064          $num_inserted ++;
2065          $node_unalias = db_fetch_array(db_query("SELECT src FROM {url_alias} WHERE dst = '%s'", $links['link'][$i]));
2066          if (isset($node_unalias) && is_array($node_unalias)) {
2067            $link_path = $node_unalias['src'];
2068          }
2069          else {
2070            $link_path = $links['link'][$i];
2071          }
2072  
2073          $mid = db_next_id('{menu}_mid');
2074          $ret[] = update_sql("INSERT INTO {menu} (mid, pid, path, title, description, weight, type) " .
2075                               "VALUES ($mid, {$menus[$loop]['pid']}, '" . db_escape_string($link_path) .
2076                               "', '" . db_escape_string($links['text'][$i]) .
2077                               "', '" . db_escape_string($links['description'][$i]) . "', 0, 118)");
2078        }
2079      }
2080      // delete Secondary links if not populated.
2081      if ($loop == 1 && $num_inserted == 0) {
2082        db_query("DELETE FROM {menu} WHERE mid={$menus[$loop]['pid']}");
2083      }
2084  
2085      // Set menu_primary_menu and menu_primary_menu variables if links were
2086      // imported. If the user had links but the toggle display was off, they
2087      // will need to disable the new links manually in admins/settings/menu.
2088      if ($num_inserted == 0) {
2089        variable_set($menus[$loop]['menu_var'], 0);
2090      }
2091      else {
2092        variable_set($menus[$loop]['menu_var'], $menus[$loop]['pid']);
2093      }
2094      variable_del('phptemplate_' .$menus[$loop]['links_var']);
2095      variable_del('phptemplate_'. $menus[$loop]['links_var'] .'_more');
2096      variable_del($menus[$loop]['toggle_var']);
2097      variable_del($menus[$loop]['more_var']);
2098      // If user has old xtemplate links in a string, leave them in the var.
2099      if (isset($ts) && is_array($ts) && is_array($ts[$menus[$loop]['links_var']])) {
2100        variable_del($menus[$loop]['links_var']);
2101      }
2102    }
2103  
2104    if (isset($ts) && is_array($ts)) {
2105      variable_set('theme_settings', $ts);
2106    }
2107  
2108    $ret[] = update_sql("UPDATE {system} SET status = 1 WHERE name = 'menu'");
2109  
2110    return $ret;
2111  }
2112  
2113  function system_update_152() {
2114    $ret = array();
2115  
2116    // Postgresql only update
2117    switch ($GLOBALS['db_type']) {
2118      case 'pgsql':
2119        $ret[] = update_sql("ALTER TABLE {forum} DROP shadow");
2120        break;
2121      case 'mysql':
2122      case 'mysqli':
2123        break;
2124    }
2125  
2126    return $ret;
2127  }
2128  
2129  function system_update_153(){
2130    $ret = array();
2131    switch ($GLOBALS['db_type']) {
2132      case 'pgsql':
2133        $ret[] = update_sql("ALTER TABLE {contact} DROP CONSTRAINT {contact}_pkey");
2134        $ret[] = update_sql("CREATE SEQUENCE {contact}_cid_seq");
2135        db_add_column($ret, 'contact', 'cid', 'int', array('not null' => TRUE, 'default' => "nextval('{contact}_cid_seq')"));
2136        $ret[] = update_sql("ALTER TABLE {contact} ADD PRIMARY KEY (cid)");
2137        $ret[] = update_sql("ALTER TABLE {contact} ADD CONSTRAINT {contact}_category_key UNIQUE (category)");
2138        break;
2139      case 'mysql':
2140      case 'mysqli':
2141        $ret[] = update_sql("ALTER TABLE {contact} DROP PRIMARY KEY");
2142        $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN cid int NOT NULL PRIMARY KEY auto_increment");
2143        $ret[] = update_sql("ALTER TABLE {contact} ADD UNIQUE KEY category (category)");
2144        break;
2145    }
2146    return $ret;
2147  }
2148  
2149  function system_update_154() {
2150    $ret = array();
2151    switch ($GLOBALS['db_type']) {
2152      case 'pgsql':
2153        db_add_column($ret, 'contact', 'weight', 'smallint', array('not null' => TRUE, 'default' => 0));
2154        db_add_column($ret, 'contact', 'selected', 'smallint', array('not null' => TRUE, 'default' => 0));
2155        break;
2156      case 'mysql':
2157      case 'mysqli':
2158        $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN weight tinyint NOT NULL DEFAULT 0");
2159        $ret[] = update_sql("ALTER TABLE {contact} ADD COLUMN selected tinyint NOT NULL DEFAULT 0");
2160        break;
2161    }
2162    return $ret;
2163  }
2164  
2165  function system_update_155() {
2166    $ret = array();
2167  
2168    // Postgresql only update
2169    switch ($GLOBALS['db_type']) {
2170      case 'pgsql':
2171        $ret[] = update_sql("DROP TABLE {cache}");
2172        $ret[] = update_sql("CREATE TABLE {cache} (
2173          cid varchar(255) NOT NULL default '',
2174          data bytea default '',
2175          expire integer NOT NULL default '0',
2176          created integer NOT NULL default '0',
2177          headers text default '',
2178          PRIMARY KEY (cid)
2179          )");
2180        $ret[] = update_sql("CREATE INDEX {cache}_expire_idx ON {cache}(expire)");
2181        break;
2182      case 'mysql':
2183      case 'mysqli':
2184        break;
2185    }
2186  
2187    return $ret;
2188  }
2189  
2190  function system_update_156() {
2191    $ret = array();
2192    $ret[] = update_sql("DELETE FROM {cache}");
2193    system_themes();
2194    return $ret;
2195  }
2196  
2197  function system_update_157() {
2198    $ret = array();
2199    $ret[] = update_sql("DELETE FROM {url_alias} WHERE src = 'node/feed' AND dst = 'rss.xml'");
2200    $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('rss.xml', 'node/feed')");
2201    return $ret;
2202  }
2203  
2204  function system_update_158() {
2205    $ret = array();
2206  
2207    switch ($GLOBALS['db_type']) {
2208      case 'mysqli':
2209      case 'mysql':
2210        $ret[] = update_sql("ALTER TABLE {old_revisions} ADD done tinyint NOT NULL DEFAULT 0");
2211        $ret[] = update_sql("ALTER TABLE {old_revisions} ADD INDEX (done)");
2212        break;
2213  
2214      case 'pgsql':
2215        db_add_column($ret, 'old_revisions', 'done', 'smallint', array('not null' => TRUE, 'default' => 0));
2216        $ret[] = update_sql('CREATE INDEX {old_revisions}_done_idx ON {old_revisions}(done)');
2217        break;
2218    }
2219  
2220    return $ret;
2221  }
2222  
2223  /**
2224   * Retrieve data out of the old_revisions table and put into new revision
2225   * system.
2226   *
2227   * The old_revisions table is not deleted because any data which could not be
2228   * put into the new system is retained.
2229   */
2230  function system_update_159() {
2231    $ret = array();
2232  
2233    $result = db_query_range("SELECT * FROM {old_revisions} WHERE done = 0 AND type IN ('page', 'story', 'poll', 'book', 'forum', 'blog') ORDER BY nid DESC", 0, 20);
2234  
2235    if (db_num_rows($result)) {
2236      $vid = db_next_id('{node_revisions}_vid');
2237      while ($node = db_fetch_object($result)) {
2238        $revisions = unserialize($node->revisions);
2239        if (isset($revisions) && is_array($revisions) && count($revisions) > 0) {
2240          $revisions_query = array();
2241          $revisions_args = array();
2242          $book_query = array();
2243          $book_args = array();
2244          $forum_query = array();
2245          $forum_args = array();
2246          foreach ($revisions as $version) {
2247            $revision = array();
2248            foreach ($version['node'] as $node_field => $node_value) {
2249              $revision[$node_field] = $node_value;
2250            }
2251            $revision['uid'] = $version['uid'];
2252            $revision['timestamp'] = $version['timestamp'];
2253            $vid++;
2254            $revisions_query[] = "(%d, %d, %d, '%s', '%s', '%s', '%s', %d, %d)";
2255            $revisions_args = array_merge($revisions_args, array($node->nid, $vid, $revision['uid'], $revision['title'], $revision['body'], $revision['teaser'], $revision['log'], $revision['timestamp'], $revision['format']));
2256            switch ($node->type) {
2257              case 'forum':
2258                if ($revision['tid'] > 0) {
2259                  $forum_query[] = "(%d, %d, %d)";
2260                  $forum_args = array_merge($forum_args, array($vid, $node->nid, $revision['tid']));
2261                }
2262                break;
2263  
2264              case 'book':
2265                $book_query[] = "(%d, %d, %d, %d)";
2266                $book_args = array_merge($book_args, array($vid, $node->nid, $revision['parent'], $revision['weight']));
2267                break;
2268            }
2269          }
2270          if (count($revisions_query)) {
2271            $revision_status = db_query("INSERT INTO {node_revisions} (nid, vid, uid, title, body, teaser, log, timestamp, format) VALUES ". implode(',', $revisions_query), $revisions_args);
2272          }
2273          if (count($forum_query)) {
2274            $forum_status = db_query("INSERT INTO {forum} (vid, nid, tid) VALUES ". implode(',', $forum_query), $forum_args);
2275          }
2276          if (count($book_query)) {
2277            $book_status = db_query("INSERT INTO {book} (vid, nid, parent, weight) VALUES ". implode(',', $book_query), $book_args);
2278          }
2279          $delete = FALSE;
2280          switch ($node->type) {
2281            case 'forum':
2282              if ($forum_status && $revision_status) {
2283                $delete = TRUE;
2284              }
2285              break;
2286  
2287            case 'book':
2288              if ($book_status && $revision_status) {
2289                $delete = TRUE;
2290              }
2291              break;
2292  
2293            default:
2294              if ($revision_status) {
2295                $delete = TRUE;
2296              }
2297              break;
2298          }
2299  
2300          if ($delete) {
2301            db_query('DELETE FROM {old_revisions} WHERE nid = %d', $node->nid);
2302          }
2303          else {
2304            db_query('UPDATE {old_revisions} SET done = 1 WHERE nid = %d', $node->nid);
2305          }
2306  
2307          switch ($GLOBALS['db_type']) {
2308            case 'mysqli':
2309            case 'mysql':
2310              $ret[] = update_sql("UPDATE {sequences} SET id = $vid WHERE name = '{node_revisions}_vid'");
2311              break;
2312  
2313            case 'pgsql':
2314              $ret[] = update_sql("SELECT setval('{node_revisions}_vid_seq', $vid)");
2315              break;
2316          }
2317        }
2318        else {
2319          db_query('UPDATE {old_revisions} SET done = 1 WHERE nid = %d', $node->nid);
2320          watchdog('php', "Recovering old revisions for node $node->nid failed.", WATCHDOG_WARNING);
2321        }
2322      }
2323    }
2324  
2325    if (db_num_rows($result) < 20) {
2326      $ret[] = update_sql('ALTER TABLE {old_revisions} DROP done');
2327    }
2328    else {
2329      $ret['#finished'] = FALSE;
2330    }
2331  
2332    return $ret;
2333  }
2334  
2335  function system_update_160() {
2336    $types = module_invoke('node', 'get_types');
2337    if (is_array($types)) {
2338      foreach ($types as $type) {
2339        if (!is_array(variable_get("node_options_$type", array()))) {
2340          variable_set("node_options_$type", array());
2341        }
2342      }
2343    }
2344    return array();
2345  }
2346  
2347  function system_update_161() {
2348    variable_del('forum_icon_path');
2349    return array();
2350  }
2351  
2352  function system_update_162() {
2353    $ret = array();
2354  
2355    // PostgreSQL only update
2356    switch ($GLOBALS['db_type']) {
2357      case 'pgsql':
2358  
2359        $ret[] = update_sql('DROP INDEX {book}_parent');
2360        $ret[] = update_sql('CREATE INDEX {book}_parent_idx ON {book}(parent)');
2361  
2362        $ret[] = update_sql('DROP INDEX {node_comment_statistics}_timestamp_idx');
2363        $ret[] = update_sql('CREATE INDEX {node_comment_statistics}_last_comment_timestamp_idx ON {node_comment_statistics}(last_comment_timestamp)');
2364  
2365        $ret[] = update_sql('ALTER TABLE {filters} ALTER delta SET DEFAULT 0');
2366        $ret[] = update_sql('DROP INDEX {filters}_module_idx');
2367  
2368        $ret[] = update_sql('DROP INDEX {locales_target}_lid_idx');
2369        $ret[] = update_sql('DROP INDEX {locales_target}_lang_idx');
2370        $ret[] = update_sql('CREATE INDEX {locales_target}_locale_idx ON {locales_target}(locale)');
2371  
2372        $ret[] = update_sql('DROP INDEX {node}_created');
2373        $ret[] = update_sql('CREATE INDEX {node}_created_idx ON {node}(created)');
2374        $ret[] = update_sql('DROP INDEX {node}_changed');
2375        $ret[] = update_sql('CREATE INDEX {node}_changed_idx ON {node}(changed)');
2376  
2377        $ret[] = update_sql('DROP INDEX {profile_fields}_category');
2378        $ret[] = update_sql('CREATE INDEX {profile_fields}_category_idx ON {profile_fields}(category)');
2379  
2380        $ret[] = update_sql('DROP INDEX {url_alias}_dst_idx');
2381        $ret[] = update_sql('CREATE UNIQUE INDEX {url_alias}_dst_idx ON {url_alias}(dst)');
2382  
2383        $ret[] = update_sql('CREATE INDEX {sessions}_uid_idx ON {sessions}(uid)');
2384        $ret[] = update_sql('CREATE INDEX {sessions}_timestamp_idx ON {sessions}(timestamp)');
2385  
2386        $ret[] = update_sql('ALTER TABLE {accesslog} DROP mask');
2387  
2388        db_change_column($ret, 'accesslog', 'path', 'path', 'text');
2389        db_change_column($ret, 'accesslog', 'url', 'url', 'text');
2390        db_change_column($ret, 'watchdog', 'link', 'link', 'text', array('not null' => TRUE, 'default' => "''"));
2391        db_change_column($ret, 'watchdog', 'location', 'location', 'text', array('not null' => TRUE, 'default' => "''"));
2392        db_change_column($ret, 'watchdog', 'referer', 'referer', 'text', array('not null' => TRUE, 'default' => "''"));
2393  
2394        break;
2395    }
2396  
2397    return $ret;
2398  }
2399  
2400  function system_update_163() {
2401    $ret = array();
2402    if ($GLOBALS['db_type'] == 'mysql' || $GLOBALS['db_type'] == 'mysqli') {
2403      $ret[] = update_sql('ALTER TABLE {cache} CHANGE data data LONGBLOB');
2404    }
2405    return $ret;
2406  }
2407  
2408  function system_update_164() {
2409    $ret = array();
2410  
2411    switch ($GLOBALS['db_type']) {
2412      case 'mysql':
2413      case 'mysqli':
2414        $ret[] = update_sql("CREATE TABLE {poll_votes} (
2415            nid int unsigned NOT NULL,
2416            uid int unsigned NOT NULL default 0,
2417            hostname varchar(128) NOT NULL default '',
2418            INDEX (nid),
2419            INDEX (uid),
2420            INDEX (hostname)
2421        )");
2422        break;
2423  
2424      case 'pgsql':
2425        $ret[] = update_sql("CREATE TABLE {poll_votes} (
2426            nid int NOT NULL,
2427            uid int NOT NULL default 0,
2428            hostname varchar(128) NOT NULL default ''
2429        )");
2430        $ret[] = update_sql('CREATE INDEX {poll_votes}_nid_idx ON {poll_votes} (nid)');
2431        $ret[] = update_sql('CREATE INDEX {poll_votes}_uid_idx ON {poll_votes} (uid)');
2432        $ret[] = update_sql('CREATE INDEX {poll_votes}_hostname_idx ON {poll_votes} (hostname)');
2433        break;
2434    }
2435  
2436    $result = db_query('SELECT nid, polled FROM {poll}');
2437    while ($poll = db_fetch_object($result)) {
2438      foreach (explode(' ', $poll->polled) as $polled) {
2439        if ($polled[0] == '_') {
2440          // $polled is a user id
2441          db_query('INSERT INTO {poll_votes} (nid, uid) VALUES (%d, %d)', $poll->nid, substr($polled, 1, -1));
2442        }
2443        else {
2444          // $polled is a host
2445          db_query("INSERT INTO {poll_votes} (nid, hostname) VALUES (%d, '%s')", $poll->nid, $polled);
2446        }
2447      }
2448    }
2449  
2450    $ret[] = update_sql('ALTER TABLE {poll} DROP polled');
2451  
2452    return $ret;
2453  }
2454  
2455  function system_update_165() {
2456    $cron_last = max(variable_get('drupal_cron_last', 0), variable_get('ping_cron_last', 0));
2457    variable_set('cron_last', $cron_last);
2458    variable_del('drupal_cron_last');
2459    variable_del('ping_cron_last');
2460    return array();
2461  }
2462  
2463  function system_update_166() {
2464    $ret = array();
2465  
2466    $ret[] = update_sql("DROP TABLE {directory}");
2467    switch ($GLOBALS['db_type']) {
2468      case 'mysqli':
2469      case 'mysql':
2470        $ret[] = update_sql("CREATE TABLE {client} (
2471          cid int unsigned NOT NULL auto_increment,
2472          link varchar(255) NOT NULL default '',
2473          name varchar(128) NOT NULL default '',
2474          mail varchar(128) NOT NULL default '',
2475          slogan longtext NOT NULL,
2476          mission longtext NOT NULL,
2477          users int NOT NULL default '0',
2478          nodes int NOT NULL default '0',
2479          version varchar(35) NOT NULL default'',
2480          created int NOT NULL default '0',
2481          changed int NOT NULL default '0',
2482          PRIMARY KEY (cid)
2483        )");
2484        $ret[] = update_sql("CREATE TABLE {client_system} (
2485          cid int NOT NULL default '0',
2486          name varchar(255) NOT NULL default '',
2487          type varchar(255) NOT NULL default '',
2488          PRIMARY KEY (cid,name)
2489        )");
2490        break;
2491  
2492      case 'pgsql':
2493        $ret[] = update_sql("CREATE TABLE {client} (
2494          cid SERIAL,
2495          link varchar(255) NOT NULL default '',
2496          name varchar(128) NOT NULL default '',
2497          mail varchar(128) NOT NULL default '',
2498          slogan text NOT NULL default '',
2499          mission text NOT NULL default '',
2500          users integer NOT NULL default '0',
2501          nodes integer NOT NULL default '0',
2502          version varchar(35) NOT NULL default'',
2503          created integer NOT NULL default '0',
2504          changed integer NOT NULL default '0',
2505          PRIMARY KEY (cid)
2506        )");
2507        $ret[] = update_sql("CREATE TABLE {client_system} (
2508          cid integer NOT NULL,
2509          name varchar(255) NOT NULL default '',
2510          type varchar(255) NOT NULL default '',
2511          PRIMARY KEY (cid,name)
2512        )");
2513        break;
2514    }
2515  
2516    return $ret;
2517  }
2518  
2519  function system_update_167() {
2520    $ret = array();
2521  
2522    switch ($GLOBALS['db_type']) {
2523      case 'mysqli':
2524      case 'mysql':
2525        $ret[] = update_sql("ALTER TABLE {vocabulary_node_types} CHANGE type type varchar(32) NOT NULL default ''");
2526        break;
2527      case 'pgsql':
2528        db_change_column($ret, 'vocabulary_node_types', 'type', 'type', 'varchar(32)', array('not null' => TRUE, 'default' => "''"));
2529        $ret[] = update_sql("ALTER TABLE {vocabulary_node_types} ADD PRIMARY KEY (vid, type)");
2530        break;
2531    }
2532  
2533    return $ret;
2534  }
2535  
2536  function system_update_168() {
2537    $ret = array();
2538  
2539    $ret[] = update_sql("ALTER TABLE {term_hierarchy} ADD PRIMARY KEY (tid, parent)");
2540  
2541    return $ret;
2542  }
2543  
2544  function system_update_169() {
2545    // Warn PGSQL admins if their database is set up incorrectly
2546    if ($GLOBALS['db_type'] == 'pgsql') {
2547      $encoding = db_result(db_query('SHOW server_encoding'));
2548      if (!in_array(strtolower($encoding), array('unicode', 'utf8'))) {
2549        $msg = 'Your PostgreSQL database is set up with the wrong character encoding ('. $encoding .'). It is possible it will not work as expected. It is advised to recreate it with UTF-8/Unicode encoding. More information can be found in the <a href="http://www.postgresql.org/docs/7.4/interactive/multibyte.html">PostgreSQL documentation</a>.';
2550        watchdog('php', $msg, WATCHDOG_WARNING);
2551        drupal_set_message($msg, 'status');
2552      }
2553    }
2554  
2555    // Note: 'access' table manually updated in update.php
2556    return _system_update_utf8(array(
2557      'accesslog', 'aggregator_category',
2558      'aggregator_category_feed', 'aggregator_category_item',
2559      'aggregator_feed', 'aggregator_item', 'authmap', 'blocks',
2560      'book', 'boxes', 'cache', 'comments', 'contact',
2561      'node_comment_statistics', 'client', 'client_system', 'files',
2562      'filter_formats', 'filters', 'flood', 'forum', 'history',
2563      'locales_meta', 'locales_source', 'locales_target', 'menu',
2564      'node', 'node_access', 'node_revisions', 'profile_fields',
2565      'profile_values', 'url_alias', 'permission', 'poll', 'poll_votes',
2566      'poll_choices', 'role', 'search_dataset', 'search_index',
2567      'search_total', 'sessions', 'sequences', 'node_counter',
2568      'system', 'term_data', 'term_hierarchy', 'term_node',
2569      'term_relation', 'term_synonym', 'users', 'users_roles', 'variable',
2570      'vocabulary', 'vocabulary_node_types', 'watchdog'
2571    ));
2572  }
2573  
2574  function system_update_170() {
2575    if (!variable_get('update_170_done', FALSE)) {
2576      switch ($GLOBALS['db_type']) {
2577        case 'pgsql':
2578          $ret = array();
2579          db_change_column($ret, 'system', 'schema_version', 'schema_version', 'smallint', array('not null' => TRUE, 'default' => -1));
2580          break;
2581  
2582        case 'mysql':
2583        case 'mysqli':
2584          db_query('ALTER TABLE {system} CHANGE schema_version schema_version smallint not null default -1');
2585          break;
2586      }
2587      // Set schema version -1 (uninstalled) for disabled modules (only affects contrib).
2588      db_query('UPDATE {system} SET schema_version = -1 WHERE status = 0 AND schema_version = 0');
2589    }
2590    return array();
2591  }
2592  
2593  function system_update_171() {
2594    $ret = array();
2595    $ret[] = update_sql('DELETE FROM {users_roles} WHERE rid IN ('. DRUPAL_ANONYMOUS_RID. ', '. DRUPAL_AUTHENTICATED_RID. ')');
2596    return $ret;
2597  }
2598  
2599  function system_update_172() {
2600    // Multi-part update
2601    if (!isset($_SESSION['system_update_172'])) {
2602      $_SESSION['system_update_172'] = 0;
2603      $_SESSION['system_update_172_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments}'));
2604    }
2605  
2606    include_once './'. drupal_get_path('module', 'comment') .'/comment.module';
2607  
2608    $limit = 20;
2609    $result = db_query_range("SELECT cid, thread FROM {comments} WHERE cid > %d ORDER BY cid ASC", $_SESSION['system_update_172'], 0, $limit);
2610    while ($comment = db_fetch_object($result)) {
2611      $_SESSION['system_update_172'] = $comment->cid;
2612      $thread = explode('.', rtrim($comment->thread, '/'));
2613      foreach ($thread as $i => $offset) {
2614        // Decode old-style comment codes: 1,2,...,9,90,91,92,...,99,990,991,...
2615        $thread[$i] = int2vancode((strlen($offset) - 1) * 10 + substr($offset, -1, 1));
2616      }
2617      $thread = implode('.', $thread) .'/';
2618      db_query("UPDATE {comments} SET thread = '%s' WHERE cid = %d", $thread, $comment->cid);
2619    }
2620  
2621    if ($_SESSION['system_update_172'] == $_SESSION['system_update_172_max']) {
2622      unset($_SESSION['system_update_172']);
2623      unset($_SESSION['system_update_172_max']);
2624      return array();
2625    }
2626    return array('#finished' => $_SESSION['system_update_172'] / $_SESSION['system_update_172_max']);
2627  }
2628  
2629  function system_update_173() {
2630    $ret = array();
2631    // State tracker to determine whether we keep a backup of the files table or not.
2632    $safe = TRUE;
2633  
2634    // PostgreSQL needs CREATE TABLE foobar _AS_ SELECT ...
2635    $AS = ($GLOBALS['db_type'] == 'pgsql') ? 'AS' : '';
2636  
2637    // Backup the files table.
2638    $ret[] = update_sql("CREATE TABLE {files_backup} $AS SELECT * FROM {files}");
2639  
2640    // Do some files table sanity checking and cleanup.
2641    $ret[] = update_sql('DELETE FROM {files} WHERE fid = 0');
2642    $ret[] = update_sql('UPDATE {files} SET vid = nid WHERE vid = 0');
2643  
2644    // Create a temporary table to build the new file_revisions and files tables from.
2645    $ret[] = update_sql("CREATE TABLE {files_tmp} $AS SELECT * FROM {files}");
2646    $ret[] = update_sql('DROP TABLE {files}');
2647  
2648    switch ($GLOBALS['db_type']) {
2649      case 'pgsql':
2650        // create file_revisions table
2651        $ret[] = update_sql("CREATE TABLE {file_revisions} (
2652          fid integer NOT NULL default 0,
2653          vid integer NOT NULL default 0,
2654          description varchar(255) NOT NULL default '',
2655          list smallint NOT NULL default 0,
2656          PRIMARY KEY (fid, vid))");
2657        $result = update_sql("INSERT INTO {file_revisions} SELECT DISTINCT ON (fid,vid) fid, vid, description, list FROM {files_tmp}");
2658        $ret[] = $result;
2659        if ($result['success'] === FALSE) {
2660          $safe = FALSE;
2661        }
2662  
2663        // Create normalized files table
2664        $ret[] = update_sql("CREATE TABLE {files} (
2665          fid SERIAL,
2666          nid integer NOT NULL default 0,
2667          filename varchar(255) NOT NULL default '',
2668          filepath varchar(255) NOT NULL default '',
2669          filemime varchar(255) NOT NULL default '',
2670          filesize integer NOT NULL default 0,
2671          PRIMARY KEY (fid))");
2672        $result = update_sql("INSERT INTO {files} SELECT DISTINCT ON (fid) fid, nid, filename, filepath, filemime, filesize FROM {files_tmp}");
2673        $ret[] = $result;
2674        if ($result['success'] === FALSE) {
2675          $safe = FALSE;
2676        }
2677  
2678        $ret[] = update_sql("SELECT setval('{files}_fid_seq', max(fid)) FROM {files}");
2679  
2680        break;
2681  
2682      case 'mysqli':
2683      case 'mysql':
2684        // create file_revisions table
2685        $ret[] = update_sql("CREATE TABLE {file_revisions} (
2686          fid int unsigned NOT NULL default 0,
2687          vid int unsigned NOT NULL default 0,
2688          description varchar(255) NOT NULL default '',
2689          list tinyint unsigned NOT NULL default 0,
2690          PRIMARY KEY (fid, vid)
2691          ) /*!40100 DEFAULT CHARACTER SET utf8 */");
2692  
2693        // Try as you might mysql only does distinct row if you are selecting more than 1 column.
2694        $result = update_sql('INSERT INTO {file_revisions} SELECT DISTINCT fid , vid, description, list FROM {files_tmp}');
2695        $ret[] = $result;
2696        if ($result['success'] === FALSE) {
2697          $safe = FALSE;
2698        }
2699  
2700        $ret[] = update_sql("CREATE TABLE {files} (
2701          fid int unsigned NOT NULL default 0,
2702          nid int unsigned NOT NULL default 0,
2703          filename varchar(255) NOT NULL default '',
2704          filepath varchar(255) NOT NULL default '',
2705          filemime varchar(255) NOT NULL default '',
2706          filesize int unsigned NOT NULL default 0,
2707          PRIMARY KEY (fid)
2708          ) /*!40100 DEFAULT CHARACTER SET utf8 */");
2709        $result = update_sql("INSERT INTO {files} SELECT DISTINCT fid, nid, filename, filepath, filemime, filesize FROM {files_tmp}");
2710        $ret[] = $result;
2711        if ($result['success'] === FALSE) {
2712          $safe = FALSE;
2713        }
2714  
2715        break;
2716    }
2717  
2718    $ret[] = update_sql("DROP TABLE {files_tmp}");
2719  
2720    // Remove original files table if all went well. Otherwise preserve it and notify user.
2721    if ($safe) {
2722      $ret[] = update_sql("DROP TABLE {files_backup}");
2723    }
2724    else {
2725      drupal_set_message('Normalizing files table failed. A backup of the original table called {files_backup} remains in your database.');
2726    }
2727  
2728    return $ret;
2729  }
2730  
2731  function system_update_174() {
2732    // This update (update comments system variables on upgrade) has been removed.
2733    return array();
2734  }
2735  
2736  function system_update_175() {
2737    $result = db_query('SELECT * FROM {url_alias}');
2738    while ($path = db_fetch_object($result)) {
2739      $path->src = urldecode($path->src);
2740      $path->dst = urldecode($path->dst);
2741      db_query("UPDATE {url_alias} SET dst = '%s', src = '%s' WHERE pid = %d", $path->dst, $path->src, $path->pid);
2742    }
2743    return array();
2744  }
2745  
2746  function system_update_176() {
2747    $ret = array();
2748    $ret[] = update_sql('ALTER TABLE {filter_formats} ADD UNIQUE (name)');
2749    return $ret;
2750  }
2751  
2752  function system_update_177() {
2753    $ret = array();
2754    $message_ids = array(
2755      'welcome_subject' => 'Welcome subject',
2756      'welcome_body' => 'Welcome body text',
2757      'approval_subject' => 'Approval subject',
2758      'approval_body' => 'Approval body text',
2759      'pass_subject' => 'Password reset subject',
2760      'pass_body' => 'Password reset body text',
2761    );
2762    foreach ($message_ids as $message_id => $message_text) {
2763      if ($admin_setting = variable_get('user_mail_'. $message_id, FALSE)) {
2764        // Insert newlines and escape for display as HTML
2765        $admin_setting = nl2br(check_plain($message_text ."\n\n". $admin_setting));
2766        watchdog('legacy', $admin_setting);
2767        $last = db_fetch_object(db_query('SELECT max(wid) AS wid FROM {watchdog}'));
2768        // Deleting is required, because _user_mail_text() checks for the existance of the variable.
2769        variable_del('user_mail_'. $message_id);
2770        $ret[] = array(
2771          'query' => strtr('The mail template %message_id has been reset to the default. The old template <a href="@url">has been saved</a>.', array('%message_id' => 'user_mail_'. $message_id, '@url' => url('admin/logs/event/'. $last->wid))),
2772          'success' => TRUE
2773        );
2774      }
2775    }
2776    return $ret;
2777  }
2778  
2779  function _update_178_url_fix($text) {
2780    // Key is the attribute to replace.
2781    $urlpatterns['href'] = "/<a[^>]+href=\"([^\"]+)/i";
2782    $urlpatterns['src']  = "/<img[^>]+src=\"([^\"]+)/i";
2783  
2784    $old = $text;
2785    foreach ($urlpatterns as $type => $pattern) {
2786      if (preg_match_all($pattern, $text, $matches)) {
2787        foreach ($matches[1] as $url) {
2788          if ($url != '' && !strstr($url, 'mailto:') && !strstr($url, '://') && !strstr($url, '../') && !strstr($url, './') && $url[0] != '/' && $url[0] != '#') {
2789            $text = preg_replace('|'. $type .'\s*=\s*"'. preg_quote($url) .'\s*"|', $type. '="'.base_path(). $url  .'"', $text);
2790          }
2791        }
2792      }
2793    }
2794    return $text != $old ? $text : FALSE;
2795  }
2796  
2797  function _update_178_url_formats() {
2798    $formats = array();
2799  
2800    // Any format with the HTML filter in it
2801    $result = db_query("SELECT format FROM {filters} WHERE module = 'filter' AND delta = 0");
2802    while ($format = db_fetch_object($result)) {
2803      $formats[$format->format] = TRUE;
2804    }
2805  
2806    // Any format with only the linebreak filter in it
2807    $result = db_query("SELECT format FROM {filters} WHERE module = 'filter' AND delta = 2");
2808    while ($format = db_fetch_object($result)) {
2809      if (db_result(db_query('SELECT COUNT(*) FROM {filters} WHERE format = %d', $format->format)) == 1) {
2810        $formats[$format->format] = TRUE;
2811      }
2812    }
2813  
2814    // Any format with 'HTML' in its name
2815    $result = db_query("SELECT format FROM {filter_formats} WHERE name LIKE '%HTML%'");
2816    while ($format = db_fetch_object($result)) {
2817      $formats[$format->format] = TRUE;
2818    }
2819  
2820    return $formats;
2821  }
2822  
2823  /**
2824   * Update base paths for relative URLs in node and comment content.
2825   */
2826  function system_update_178() {
2827  
2828    if (variable_get('clean_url', 0) == 1) {
2829      // Multi-part update
2830      if (!isset($_SESSION['system_update_178_comment'])) {
2831        // Check which formats need to be converted
2832        $formats = _update_178_url_formats();
2833        if (count($formats) == 0) {
2834          return array();
2835        }
2836  
2837        // Build format query string
2838        $_SESSION['formats'] = array_keys($formats);
2839        $_SESSION['format_string'] = '('. substr(str_repeat('%d, ', count($formats)), 0, -2) .')';
2840  
2841        // Begin update
2842        $_SESSION['system_update_178_comment'] = 0;
2843        $_SESSION['system_update_178_node'] = 0;
2844        $_SESSION['system_update_178_comment_max'] = db_result(db_query('SELECT MAX(cid) FROM {comments} WHERE format IN '. $_SESSION['format_string'], $_SESSION['formats']));
2845        $_SESSION['system_update_178_node_max'] = db_result(db_query('SELECT MAX(vid) FROM {node_revisions} WHERE format IN '. $_SESSION['format_string'], $_SESSION['formats']));
2846      }
2847  
2848      $limit = 20;
2849  
2850      // Comments
2851      if ($_SESSION['system_update_178_comment'] != $_SESSION['system_update_178_comment_max']) {
2852        $args = array_merge(array($_SESSION['system_update_178_comment']), $_SESSION['formats']);
2853        $result = db_query_range("SELECT cid, comment FROM {comments} WHERE cid > %d AND format IN ". $_SESSION['format_string'] .' ORDER BY cid ASC', $args, 0, $limit);
2854        while ($comment = db_fetch_object($result)) {
2855          $_SESSION['system_update_178_comment'] = $comment->cid;
2856          $comment->comment = _update_178_url_fix($comment->comment);
2857          if ($comment->comment !== FALSE) {
2858            db_query("UPDATE {comments} SET comment = '%s' WHERE cid = %d", $comment->comment, $comment->cid);
2859          }
2860        }
2861      }
2862  
2863      // Node revisions
2864      $args = array_merge(array($_SESSION['system_update_178_node']), $_SESSION['formats']);
2865      $result = db_query_range("SELECT vid, teaser, body FROM {node_revisions} WHERE vid > %d AND format IN ". $_SESSION['format_string'] .' ORDER BY vid ASC', $args, 0, $limit);
2866      while ($node = db_fetch_object($result)) {
2867        $_SESSION['system_update_178_node'] = $node->vid;
2868        $set = array();
2869        $args = array();
2870  
2871        $node->teaser = _update_178_url_fix($node->teaser);
2872        if ($node->teaser !== FALSE) {
2873          $set[] = "teaser = '%s'";
2874          $args[] = $node->teaser;
2875        }
2876  
2877        $node->body = _update_178_url_fix($node->body);
2878        if ($node->body !== FALSE) {
2879          $set[] = "body = '%s'";
2880          $args[] = $node->body;
2881        }
2882  
2883        if (count($set)) {
2884          $args[] = $node->vid;
2885          db_query('UPDATE {node_revisions} SET '. implode(', ', $set) .' WHERE vid = %d', $args);
2886        }
2887  
2888      }
2889  
2890      if ($_SESSION['system_update_178_comment'] == $_SESSION['system_update_178_comment_max'] &&
2891          $_SESSION['system_update_178_node'] == $_SESSION['system_update_178_node_max']) {
2892        unset($_SESSION['system_update_178_comment']);
2893        unset($_SESSION['system_update_178_comment_max']);
2894        unset($_SESSION['system_update_178_node']);
2895        unset($_SESSION['system_update_178_node_max']);
2896        return array();
2897      }
2898      else {
2899        // Report percentage finished
2900        return array('#finished' =>
2901          ($_SESSION['system_update_178_comment'] + $_SESSION['system_update_178_node']) /
2902          ($_SESSION['system_update_178_comment_max'] + $_SESSION['system_update_178_node_max'])
2903        );
2904      }
2905    }
2906  
2907    return array();
2908  }
2909  
2910  /**
2911   * Update base paths for relative URLs in custom blocks, profiles and various variables.
2912   */
2913  function system_update_179() {
2914  
2915    if (variable_get('clean_url', 0) == 1) {
2916      // Multi-part update
2917      if (!isset($_SESSION['system_update_179_uid'])) {
2918        // Check which formats need to be converted
2919        $formats = _update_178_url_formats();
2920        if (count($formats) == 0) {
2921          return array();
2922        }
2923  
2924        // Custom Blocks (too small for multipart)
2925        $format_string = '('. substr(str_repeat('%d, ', count($formats)), 0, -2) .')';
2926        $result = db_query("SELECT bid, body FROM {boxes} WHERE format IN ". $format_string, array_keys($formats));
2927        while ($block = db_fetch_object($result)) {
2928          $block->body = _update_178_url_fix($block->body);
2929          if ($block->body !== FALSE) {
2930            db_query("UPDATE {boxes} SET body = '%s' WHERE bid = %d", $block->body, $block->bid);
2931          }
2932        }
2933  
2934        // Variables (too small for multipart)
2935        $vars = array('site_mission', 'site_footer', 'user_registration_help');
2936        foreach (node_get_types() as $type => $name) {
2937          $vars[] = $type .'_help';
2938        }
2939        foreach ($vars as $var) {
2940          $value = variable_get($var, NULL);
2941          if (!is_null($value)) {
2942            $value = _update_178_url_fix($value);
2943            if ($value !== FALSE) {
2944              variable_set($var, $value);
2945            }
2946          }
2947        }
2948  
2949        // See if profiles need to be updated: is the default format HTML?
2950        if (!isset($formats[variable_get('filter_default_format', 1)])) {
2951          return array();
2952        }
2953        $result = db_query("SELECT fid FROM {profile_fields} WHERE type = 'textarea'");
2954        $fields = array();
2955        while ($field = db_fetch_object($result)) {
2956          $fields[] = $field->fid;
2957        }
2958        if (count($fields) == 0) {
2959          return array();
2960        }
2961  
2962        // Begin multi-part update for profiles
2963        $_SESSION['system_update_179_fields'] = $fields;
2964        $_SESSION['system_update_179_field_string'] = '('. substr(str_repeat('%d, ', count($fields)), 0, -2) .')';
2965        $_SESSION['system_update_179_uid'] = 0;
2966        $_SESSION['system_update_179_fid'] = 0;
2967        $_SESSION['system_update_179_max'] = db_result(db_query('SELECT MAX(uid) FROM {profile_values} WHERE fid IN '. $_SESSION['system_update_179_field_string'], $_SESSION['system_update_179_fields']));
2968      }
2969  
2970      // Fetch next 20 profile values to convert
2971      $limit = 20;
2972      $args = array_merge(array($_SESSION['system_update_179_uid'], $_SESSION['system_update_179_fid'], $_SESSION['system_update_179_uid']), $_SESSION['system_update_179_fields']);
2973      $result = db_query_range("SELECT fid, uid, value FROM {profile_values} WHERE ((uid = %d AND fid > %d) OR uid > %d) AND fid IN ". $_SESSION['system_update_179_field_string'] .' ORDER BY uid ASC, fid ASC', $args, 0, $limit);
2974      while ($field = db_fetch_object($result)) {
2975        $_SESSION['system_update_179_uid'] = $field->uid;
2976        $_SESSION['system_update_179_fid'] = $field->fid;
2977        $field->value = _update_178_url_fix($field->value);
2978        if ($field->value !== FALSE) {
2979          db_query("UPDATE {profile_values} SET value = '%s' WHERE uid = %d AND fid = %d", $field->value, $field->uid, $field->fid);
2980        }
2981  
2982      }
2983  
2984      // Done?
2985      if (db_num_rows($result) == 0) {
2986        unset($_SESSION['system_update_179_uid']);
2987        unset($_SESSION['system_update_179_fid']);
2988        unset($_SESSION['system_update_179_max']);
2989        return array();
2990      }
2991      else {
2992        // Report percentage finished
2993        // (Note: make sure we complete all fields for the last user by not reporting 100% too early)
2994        return array('#finished' => $_SESSION['system_update_179_uid'] / ($_SESSION['system_update_179_max'] + 1));
2995      }
2996    }
2997  
2998    return array();
2999  }
3000  
3001  function system_update_180() {
3002    $ret = array();
3003  
3004    switch ($GLOBALS['db_type']) {
3005      case 'mysql':
3006      case 'mysqli':
3007        $ret[] = update_sql("ALTER TABLE {node} DROP PRIMARY KEY");
3008        $ret[] = update_sql("ALTER TABLE {node} ADD PRIMARY KEY (nid, vid)");
3009        $ret[] = update_sql("ALTER TABLE {node} DROP INDEX vid");
3010        $ret[] = update_sql("ALTER TABLE {node} ADD UNIQUE (vid)");
3011        $ret[] = update_sql("ALTER TABLE {node} ADD INDEX (nid)");
3012  
3013        $ret[] = update_sql("ALTER TABLE {node_counter} CHANGE nid nid int NOT NULL DEFAULT '0'");
3014        break;
3015      case 'pgsql':
3016        $ret[] = update_sql("ALTER TABLE {node} DROP CONSTRAINT {node}_pkey"); // Change PK
3017        $ret[] = update_sql("ALTER TABLE {node} ADD PRIMARY KEY (nid, vid)");
3018        $ret[] = update_sql('DROP INDEX {node}_vid_idx'); // Change normal index to UNIQUE index
3019        $ret[] = update_sql('CREATE UNIQUE INDEX {node}_vid_idx ON {node}(vid)');
3020        $ret[] = update_sql('CREATE INDEX {node}_nid_idx ON {node}(nid)'); // Add index on nid
3021        break;
3022    }
3023  
3024    return $ret;
3025  }
3026  
3027  function system_update_181() {
3028    $ret = array();
3029    switch ($GLOBALS['db_type']) {
3030      case 'mysql':
3031      case 'mysqli':
3032        $ret[] = update_sql("ALTER TABLE {profile_fields} ADD autocomplete TINYint NOT NULL AFTER visibility ;");
3033        break;
3034      case 'pgsql':
3035        db_add_column($ret, 'profile_fields', 'autocomplete', 'smallint', array('not null' => TRUE, 'default' => 0));
3036        break;
3037    }
3038    return $ret;
3039  }
3040  
3041  /**
3042   * The lid field in pgSQL should not be UNIQUE, but an INDEX.
3043   */
3044  function system_update_182() {
3045    $ret = array();
3046  
3047    if ($GLOBALS['db_type'] == 'pgsql') {
3048      $ret[] = update_sql('ALTER TABLE {locales_target} DROP CONSTRAINT {locales_target}_lid_key');
3049      $ret[] = update_sql('CREATE INDEX {locales_target}_lid_idx ON {locales_target} (lid)');
3050    }
3051  
3052    return $ret;
3053  }
3054  
3055  /**
3056   * @defgroup updates-4.7-to-5.0 System updates from 4.7 to 5.0
3057   * @{
3058   */
3059  
3060  function system_update_1000() {
3061    $ret = array();
3062    switch ($GLOBALS['db_type']) {
3063      case 'mysql':
3064      case 'mysqli':
3065      $ret[] = update_sql("CREATE TABLE {blocks_roles} (
3066        module varchar(64) NOT NULL,
3067        delta varchar(32) NOT NULL,
3068        rid int unsigned NOT NULL,
3069        PRIMARY KEY (module, delta, rid)
3070        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
3071      break;
3072  
3073      case 'pgsql':
3074      $ret[] = update_sql("CREATE TABLE {blocks_roles} (
3075        module varchar(64) NOT NULL,
3076        delta varchar(32) NOT NULL,
3077        rid integer NOT NULL,
3078        PRIMARY KEY (module, delta, rid)
3079        );");
3080      break;
3081  
3082    }
3083    return $ret;
3084  }
3085  
3086  function system_update_1001() {
3087    // change DB schema for better poll support
3088    $ret = array();
3089  
3090    switch ($GLOBALS['db_type']) {
3091      case 'mysqli':
3092      case 'mysql':
3093        // alter poll_votes table
3094        $ret[] = update_sql("ALTER TABLE {poll_votes} ADD COLUMN chorder int NOT NULL default -1 AFTER uid");
3095        break;
3096  
3097      case 'pgsql':
3098        db_add_column($ret, 'poll_votes', 'chorder', 'int', array('not null' => TRUE, 'default' => "'-1'"));
3099        break;
3100    }
3101  
3102    return $ret;
3103  }
3104  
3105  function system_update_1002() {
3106    // Make the forum's vocabulary the highest in list, if present
3107    $ret = array();
3108  
3109    if ($vid = (int) variable_get('forum_nav_vocabulary', 0)) {
3110      $ret[] = update_sql('UPDATE {vocabulary} SET weight = -10 WHERE vid = '. $vid);
3111    }
3112  
3113    return $ret;
3114  }
3115  
3116  function system_update_1003() {
3117    // Make use of guid in feed items
3118    $ret = array();
3119    switch ($GLOBALS['db_type']) {
3120      case 'mysql':
3121      case 'mysqli':
3122        $ret[] = update_sql("ALTER TABLE {aggregator_item} ADD guid varchar(255) AFTER timestamp ;");
3123        break;
3124      case 'pgsql':
3125        db_add_column($ret, 'aggregator_item', 'guid', 'varchar(255)');
3126        break;
3127    }
3128    return $ret;
3129  }
3130  
3131  
3132  function system_update_1004() {
3133    // Increase the size of bid in boxes and aid in access
3134    $ret = array();
3135    switch ($GLOBALS['db_type']) {
3136      case 'mysql':
3137      case 'mysqli':
3138      $ret[] = update_sql("ALTER TABLE {access} CHANGE `aid` `aid` int  NOT NULL AUTO_INCREMENT ");
3139      $ret[] = update_sql("ALTER TABLE {boxes} CHANGE `bid` `bid` int NOT NULL AUTO_INCREMENT ");
3140        break;
3141      case 'pgsql':
3142        // No database update required for PostgreSQL because it already uses big SERIAL numbers.
3143        break;
3144    }
3145    return $ret;
3146  }
3147  
3148  function system_update_1005() {
3149    // Add ability to create dynamic node types like the CCK module
3150    $ret = array();
3151  
3152    // The node_type table may already exist for anyone who ever used CCK in 4.7,
3153    // even if CCK is no longer installed. We need to make sure any previously
3154    // created table gets renamed before we create the new node_type table in
3155    // order to ensure that the new table gets created without errors.
3156    // TODO: This check should be removed for Drupal 6.
3157    if (db_table_exists('node_type')) {
3158      switch ($GLOBALS['db_type']) {
3159        case 'mysql':
3160        case 'mysqli':
3161          $ret[] = update_sql('RENAME TABLE {node_type} TO {node_type_content}');
3162          break;
3163  
3164        case 'pgsql':
3165          $ret[] = update_sql('ALTER TABLE {node_type} RENAME TO {node_type_content}');
3166          break;
3167      }
3168    }
3169  
3170    switch ($GLOBALS['db_type']) {
3171      case 'mysqli':
3172      case 'mysql':
3173        // Create node_type table
3174        $ret[] = update_sql("CREATE TABLE {node_type} (
3175          type varchar(32) NOT NULL,
3176          name varchar(255) NOT NULL,
3177          module varchar(255) NOT NULL,
3178          description mediumtext NOT NULL,
3179          help mediumtext NOT NULL,
3180          has_title tinyint unsigned NOT NULL,
3181          title_label varchar(255) NOT NULL default '',
3182          has_body tinyint unsigned NOT NULL,
3183          body_label varchar(255) NOT NULL default '',
3184          min_word_count smallint unsigned NOT NULL,
3185          custom tinyint NOT NULL DEFAULT '0',
3186          modified tinyint NOT NULL DEFAULT '0',
3187          locked tinyint NOT NULL DEFAULT '0',
3188          orig_type varchar(255) NOT NULL default '',
3189          PRIMARY KEY (type)
3190          ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
3191        break;
3192  
3193      case 'pgsql':
3194        // add new unsigned types for pgsql
3195        $ret[] = update_sql("CREATE DOMAIN int_unsigned integer CHECK (VALUE >= 0)");
3196        $ret[] = update_sql("CREATE DOMAIN smallint_unsigned smallint CHECK (VALUE >= 0)");
3197        $ret[] = update_sql("CREATE DOMAIN bigint_unsigned bigint CHECK (VALUE >= 0)");
3198  
3199        $ret[] = update_sql("CREATE TABLE {node_type} (
3200          type varchar(32) NOT NULL,
3201          name varchar(255) NOT NULL,
3202          module varchar(255) NOT NULL,
3203          description text NOT NULL,
3204          help text NOT NULL,
3205          has_title smallint_unsigned NOT NULL,
3206          title_label varchar(255) NOT NULL default '',
3207          has_body smallint_unsigned NOT NULL,
3208          body_label varchar(255) NOT NULL default '',
3209          min_word_count smallint_unsigned NOT NULL,
3210          custom smallint NOT NULL DEFAULT '0',
3211          modified smallint NOT NULL DEFAULT '0',
3212          locked smallint NOT NULL DEFAULT '0',
3213          orig_type varchar(255) NOT NULL default '',
3214          PRIMARY KEY (type)
3215          );");
3216        break;
3217    }
3218  
3219    // Insert default user-defined node types into the database.
3220    $types = array(
3221      array(
3222        'type' => 'page',
3223        'name' => t('Page'),
3224        'module' => 'node',
3225        'description' => t('If you want to add a static page, like a contact page or an about page, use a page.'),
3226        'custom' => TRUE,
3227        'modified' => TRUE,
3228        'locked' => FALSE,
3229      ),
3230      array(
3231        'type' => 'story',
3232        'name' => t('Story'),
3233        'module' => 'node',
3234        'description' => t('Stories are articles in their simplest form: they have a title, a teaser and a body, but can be extended by other modules. The teaser is part of the body too. Stories may be used as a personal blog or for news articles.'),
3235        'custom' => TRUE,
3236        'modified' => TRUE,
3237        'locked' => FALSE,
3238      )
3239    );
3240  
3241    foreach ($types as $type) {
3242      $type = (object) _node_type_set_defaults($type);
3243      node_type_save($type);
3244    }
3245  
3246    cache_clear_all();
3247    system_modules();
3248    menu_rebuild();
3249    node_types_rebuild();
3250  
3251    // Migrate old values for 'minimum_x_size' variables to the node_type table.
3252    $query = db_query('SELECT type FROM {node_type}');
3253    while ($result = db_fetch_object($query)) {
3254      $variable_name = 'minimum_'. $result->type .'_size';
3255      if ($value = db_fetch_object(db_query("SELECT value FROM {variable} WHERE name = '%s'", $variable_name))) {
3256        $value = (int) unserialize($value->value);
3257        db_query("UPDATE {node_type} SET min_word_count = %d, modified = %d WHERE type = '%s'", $value, 1, $result->type);
3258        variable_del($variable_name);
3259      }
3260    }
3261  
3262    node_types_rebuild();
3263  
3264    return $ret;
3265  }
3266  
3267  function system_update_1006() {
3268    // Add a customizable title to all blocks.
3269    $ret = array();
3270    switch ($GLOBALS['db_type']) {
3271      case 'mysql':
3272      case 'mysqli':
3273      $ret[] = update_sql("ALTER TABLE {blocks} ADD title VARCHAR(64) NOT NULL DEFAULT ''");
3274        break;
3275      case 'pgsql':
3276        db_add_column($ret, 'blocks', 'title', 'varchar(64)', array('default' => "''", 'not null' => TRUE));
3277        break;
3278    }
3279    // Migrate custom block titles to new column.
3280    $boxes = db_query('SELECT bid, title from {boxes}');
3281    while ($box = db_fetch_object($boxes)) {
3282      db_query("UPDATE {blocks} SET title = '%s' WHERE delta = %d and module = 'block'", $box->title, $box->bid);
3283    }
3284    switch ($GLOBALS['db_type']) {
3285      case 'mysql':
3286      case 'mysqli':
3287        $ret[] = update_sql('ALTER TABLE {boxes} DROP title');
3288        break;
3289      case 'pgsql':
3290        $ret[] = update_sql('ALTER TABLE {boxes} DROP COLUMN title');
3291        break;
3292    }
3293    return $ret;
3294  }
3295  
3296  function system_update_1007() {
3297    $ret = array();
3298    switch ($GLOBALS['db_type']) {
3299      case 'mysql':
3300      case 'mysqli':
3301        $ret[] = update_sql("ALTER TABLE {aggregator_item} ADD INDEX (fid)");
3302        break;
3303      case 'pgsql':
3304        $ret[] = update_sql("CREATE INDEX {aggregator_item}_fid_idx ON {aggregator_item} (fid)");
3305        break;
3306    }
3307    return $ret;
3308  }
3309  
3310  /**
3311   * Performance update for queries that are related to the locale.module
3312   */
3313  function system_update_1008() {
3314    $ret = array();
3315    switch ($GLOBALS['db_type']) {
3316      case 'mysql':
3317      case 'mysqli':
3318        $ret[] = update_sql('ALTER TABLE {locales_source} ADD KEY source (source(30))');
3319        break;
3320      case 'pgsql':
3321        $ret[] = update_sql("CREATE INDEX {locales_source}_source_idx on {locales_source} (source)");
3322    }
3323  
3324    return $ret;
3325  }
3326  
3327  function system_update_1010() {
3328    $ret = array();
3329  
3330    // Disable urlfilter.module, if it exists.
3331    if (module_exists('urlfilter')) {
3332      module_disable(array('urlfilter'));
3333      $ret[] = update_sql("UPDATE {filter_formats} SET module = 'filter', delta = 3 WHERE module = 'urlfilter'");
3334      $ret[] = t('URL Filter module was disabled; this functionality has now been added to core.');
3335    }
3336  
3337    return $ret;
3338  }
3339  
3340  function system_update_1011() {
3341    $ret = array();
3342    $ret[] = update_sql('UPDATE {menu} SET mid = 2 WHERE mid = 0');
3343    cache_clear_all();
3344    return $ret;
3345  }
3346  
3347  function system_update_1012() {
3348    $ret = array();
3349    switch ($GLOBALS['db_type']) {
3350      case 'mysql':
3351      case 'mysqli':
3352        $ret[] = update_sql("ALTER TABLE {file_revisions} ADD INDEX(vid)");
3353        $ret[] = update_sql("ALTER TABLE {files} ADD INDEX(nid)");
3354        break;
3355      case 'pgsql':
3356        $ret[] = update_sql('CREATE INDEX {file_revisions}_vid_idx ON {file_revisions} (vid)');
3357        $ret[] = update_sql('CREATE INDEX {files}_nid_idx ON {files} (nid)');
3358        break;
3359    }
3360    return $ret;
3361  }
3362  
3363  function system_update_1013() {
3364    $ret = array();
3365    switch ($GLOBALS['db_type']) {
3366      case 'mysql':
3367      case 'mysqli':
3368        $ret[] = update_sql("ALTER TABLE {sessions} CHANGE COLUMN sid sid varchar(64) NOT NULL default ''");
3369        break;
3370      case 'pgsql':
3371        db_change_column($ret, 'sessions', 'sid', 'sid', 'varchar(64)',  array('not null' => TRUE, 'default' => "''"));
3372        break;
3373    }
3374    return $ret;
3375  }
3376  
3377  function system_update_1014() {
3378    variable_del('cron_busy');
3379    return array();
3380  }
3381  
3382  
3383  /**
3384   * Add an index on watchdog type.
3385   */
3386  function system_update_1015() {
3387    $ret = array();
3388    switch ($GLOBALS['db_type']) {
3389      case 'mysql':
3390      case 'mysqli':
3391        $ret[] = update_sql('ALTER TABLE {watchdog} ADD INDEX (type)');
3392        break;
3393      case 'pgsql':
3394        $ret[] = update_sql('CREATE INDEX {watchdog}_type_idx ON {watchdog}(type)');
3395        break;
3396    }
3397    return $ret;
3398  }
3399  
3400  /**
3401   * Allow for longer URL encoded (%NN) UTF-8 characters in the location field of watchdog table.
3402   */
3403  function system_update_1016() {
3404    $ret = array();
3405    switch ($GLOBALS['db_type']) {
3406      case 'mysql':
3407      case 'mysqli':
3408        $ret[] = update_sql("ALTER TABLE {watchdog} CHANGE COLUMN location location text NOT NULL");
3409        break;
3410      case 'pgsql':
3411        db_change_column($ret, 'watchdog', 'location', 'location', 'text',  array('not null' => TRUE, 'default' => "''"));
3412        break;
3413    }
3414    return $ret;
3415  }
3416  
3417  /**
3418   * Allow role names to be up to 64 characters.
3419   */
3420  function system_update_1017() {
3421    $ret = array();
3422    switch ($GLOBALS['db_type']) {
3423      case 'pgsql':
3424        db_change_column($ret, 'role', 'name', 'name', 'varchar(64)', array('not null' => TRUE, 'default' => "''"));
3425        break;
3426      case 'mysql':
3427      case 'mysqli':
3428        $ret[] = update_sql("ALTER TABLE {role} CHANGE name name varchar(64) NOT NULL default ''");
3429        break;
3430    }
3431    return $ret;
3432  }
3433  
3434  /**
3435   * Change break tag (was removed, see 1020).
3436   */
3437  function system_update_1018() {
3438    variable_set('update_1020_ok', TRUE);
3439    return array();
3440  }
3441  
3442  /**
3443   * Change variable format for user-defined e-mails.
3444   */
3445  function system_update_1019() {
3446    $message_ids = array('welcome_subject', 'welcome_body',
3447                         'approval_subject', 'approval_body',
3448                         'pass_subject', 'pass_body',
3449    );
3450    foreach ($message_ids as $id) {
3451      // Replace all %vars with !vars
3452      if ($message = variable_get('user_mail_'. $id, NULL)) {
3453        $fixed = preg_replace('/%([A-Za-z_-]+)/', '!\1', $message);
3454        variable_set('user_mail_'. $id, $fixed);
3455      }
3456    }
3457    return array();
3458  }
3459  
3460  /**
3461   * Change break tag back (was removed from head).
3462   */
3463  function system_update_1020() {
3464    $ret = array();
3465    if (!variable_get('update_1020_ok', FALSE)) {
3466      $ret[] = update_sql("UPDATE {node_revisions} SET body = REPLACE(body, '<break>', '<!--break-->')");
3467    }
3468    variable_del('update_1020_ok');
3469    return $ret;
3470  }
3471  
3472  /**
3473   * Update two more variables that were missing from system_update_1019.
3474   */
3475  function system_update_1021() {
3476    $message_ids = array('admin_body', 'admin_subject');
3477    foreach ($message_ids as $id) {
3478      // Replace all %vars with !vars
3479      if ($message = variable_get('user_mail_'. $id, NULL)) {
3480        $fixed = preg_replace('/%([A-Za-z_-]+)/', '!\1', $message);
3481        variable_set('user_mail_'. $id, $fixed);
3482      }
3483    }
3484    return array();
3485  }
3486  
3487  /**
3488   * @} End of "defgroup updates-4.7-to-5.0"
3489   */
3490  
3491  
3492  /**
3493   * @defgroup updates-5.x-extra Extra system updates for 5.x
3494   * @{
3495   */
3496  
3497  /**
3498   * Add index on users created column.
3499   */
3500  function system_update_1022() {
3501    $ret = array();
3502    switch ($GLOBALS['db_type']) {
3503      case 'mysql':
3504      case 'mysqli':
3505        $ret[] = update_sql('ALTER TABLE {users} ADD KEY created (created)');
3506        break;
3507  
3508      case 'pgsql':
3509        $ret[] = update_sql("CREATE INDEX {users}_created_idx ON {users} (created)");
3510        break;
3511    }
3512    // Also appears as system_update_2004(). Ensure we don't update twice.
3513    variable_set('system_update_1022', TRUE);
3514    return $ret;
3515  }
3516  
3517  /**
3518   * @} End of "defgroup updates-5.x-extra"
3519   */
3520  
3521  /**
3522   * @defgroup updates-5.0-to-x.x System updates from 5.0 to x.x
3523   * @{
3524   * @todo Start this series of updates at 2000.
3525   */
3526  
3527  /**
3528   * @} End of "defgroup updates-5.0-to-x.x"
3529   * The next series of updates should start at 3000.
3530   */


Généré le : Fri Nov 30 16:20:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics