updates.inc 88.2 KB
Newer Older
Dries's avatar
 
Dries committed
1 2 3
<?php
/* $Id$ */

Dries's avatar
 
Dries committed
4 5 6 7 8
/**
 * @file
 * All incremental database updates performed between Drupal releases.
 */

Dries's avatar
 
Dries committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
// Define the various updates in an array("date : comment" => "function");
$sql_updates = array(
  "2002-06-22: first update since Drupal 4.0.0 release" => "update_32",
  "2002-07-07" => "update_33",
  "2002-07-31" => "update_34",
  "2002-08-10" => "update_35",
  "2002-08-16" => "update_36",
  "2002-08-19" => "update_37",
  "2002-08-26" => "update_38",
  "2002-09-15" => "update_39",
  "2002-09-17" => "update_40",
  "2002-10-13" => "update_41",
  "2002-10-17" => "update_42",
  "2002-10-26" => "update_43",
  "2002-11-08" => "update_44",
  "2002-11-20" => "update_45",
  "2002-12-10: first update since Drupal 4.1.0 release" => "update_46",
  "2002-12-29" => "update_47",
  "2003-01-03" => "update_48",
  "2003-01-05" => "update_49",
  "2003-01-15" => "update_50",
  "2003-04-19" => "update_51",
  "2003-04-20" => "update_52",
  "2003-05-18" => "update_53",
  "2003-05-24" => "update_54",
  "2003-05-31" => "update_55",
  "2003-06-04" => "update_56",
  "2003-06-08" => "update_57",
  "2003-06-08: first update since Drupal 4.2.0 release" => "update_58",
  "2003-08-05" => "update_59",
  "2003-08-15" => "update_60",
  "2003-08-20" => "update_61",
  "2003-08-27" => "update_62",
  "2003-09-09" => "update_63",
  "2003-09-10" => "update_64",
  "2003-09-29" => "update_65",
  "2003-09-30" => "update_66",
  "2003-10-11" => "update_67",
  "2003-10-20" => "update_68",
  "2003-10-22" => "update_69",
  "2003-10-27" => "update_70",
  "2003-11-17: first update since Drupal 4.3.0 release" => "update_71",
  "2003-11-27" => "update_72",
  "2003-12-03" => "update_73",
  "2003-12-06" => "update_74",
  "2004-01-06" => "update_75",
  "2004-01-11" => "update_76",
  "2004-01-13" => "update_77",
  "2004-02-03" => "update_78",
Dries's avatar
 
Dries committed
58
  "2004-02-21" => "update_79",
Dries's avatar
 
Dries committed
59
  "2004-03-11: first update since Drupal 4.4.0 release" => "update_80",
Dries's avatar
 
Dries committed
60
  "2004-02-20" => "update_81",
61
  "2004-02-27" => "update_82",
62
  "2004-04-15" => "update_83",
Dries's avatar
 
Dries committed
63
  "2004-04-21" => "update_84",
Dries's avatar
 
Dries committed
64
  "2004-04-27" => "update_85",
Dries's avatar
 
Dries committed
65
  "2004-05-10" => "update_86",
Dries's avatar
 
Dries committed
66
  "2004-05-18" => "update_87",
Dries's avatar
 
Dries committed
67
  "2004-06-11" => "update_88",
68
  "2004-06-18" => "update_89",
69
  "2004-06-27" => "update_90",
Dries's avatar
 
Dries committed
70
  "2004-06-30" => "update_91",
Dries's avatar
 
Dries committed
71
  "2004-07-07" => "update_92",
Dries's avatar
 
Dries committed
72
  "2004-07-11" => "update_93",
Dries's avatar
 
Dries committed
73
  "2004-07-22" => "update_94",
Dries's avatar
 
Dries committed
74
  "2004-07-30" => "update_95",
75
  "2004-08-04" => "update_96",
76
  "2004-08-06" => "update_97",
77
  "2004-08-07" => "update_98",
Dries's avatar
 
Dries committed
78 79
  "2004-08-09" => "update_99",
  "2004-08-10" => "update_100",
80
  "2004-08-11" => "update_101",
Dries's avatar
 
Dries committed
81
  "2004-08-12" => "update_102",
Dries's avatar
 
Dries committed
82
  "2004-08-17" => "update_103",
Dries's avatar
 
Dries committed
83
  "2004-08-19" => "update_104",
84
  "2004-09-14" => "update_105",
Dries's avatar
 
Dries committed
85
  "2004-09-15" => "update_106",
86
  "2004-09-17" => "update_107",
87
  "2004-10-16" => "update_108",
88
  "2004-10-18" => "update_109",
Dries's avatar
 
Dries committed
89
  "2004-10-31: first update since Drupal 4.5.0 release" => "update_110",
Dries's avatar
 
Dries committed
90
  "2004-11-07" => "update_111",
91
  "2004-11-15" => "update_112",
Dries's avatar
 
Dries committed
92
  "2004-11-28" => "update_113",
93
  "2004-12-05" => "update_114",
94
  "2005-01-07" => "update_115",
Dries's avatar
 
Dries committed
95 96
  "2005-01-14" => "update_116",
  "2005-01-18" => "update_117",
97
  "2005-01-19" => "update_118",
98
  "2005-01-20" => "update_119",
99
  "2005-01-25" => "update_120",
100
  "2005-01-26" => "update_121",
101
  "2005-01-27" => "update_122",
102
  "2005-01-28" => "update_123",
103
  "2005-02-11" => "update_124",
104
  "2005-02-23" => "update_125",
105
  "2005-03-03" => "update_126",
106
  "2005-03-18" => "update_127",
Dries's avatar
Dries committed
107
  "2005-03-21" => "update_128",
108
  "2005-04-08: first update since Drupal 4.6.0 release" => "update_129",
Dries's avatar
 
Dries committed
109
  "2005-04-10" => "update_130",
Dries's avatar
Dries committed
110
  "2005-04-11" => "update_131",
111
  "2005-04-14" => "update_132",
112
  "2005-04-24" => "update_133",
113
  "2005-04-30" => "update_134",
114
  "2005-05-06" => "update_135",
115
  "2005-05-08" => "update_136",
116
  "2005-05-09" => "update_137",
Dries's avatar
 
Dries committed
117
  "2005-05-10" => "update_138",
118
  "2005-05-11" => "update_139",
119
  "2005-05-12" => "update_140",
120
  "2005-05-22" => "update_141",
Dries's avatar
Dries committed
121 122
  "2005-07-29" => "update_142",
  "2005-07-30" => "update_143"
Dries's avatar
 
Dries committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
);

function update_32() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE users ADD index (sid(4))");
  $ret[] = update_sql("ALTER TABLE users ADD index (timestamp)");
  $ret[] = update_sql("ALTER TABLE users ADD UNIQUE KEY name (name)");
  return $ret;
}

function update_33() {
  $ret = array();
  $result = db_query("SELECT * FROM variable WHERE value NOT LIKE 's:%;'");
  // NOTE: the "WHERE"-part of the query above avoids variables to get serialized twice.
  while ($variable = db_fetch_object($result)) {
    variable_set($variable->name, $variable->value);
  }
  return $ret;
}

function update_34() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE feed MODIFY refresh int(10) NOT NULL default '0'");
  $ret[] = update_sql("ALTER TABLE feed MODIFY timestamp int (10) NOT NULL default '0'");
  $ret[] = update_sql("ALTER TABLE users CHANGE session session TEXT");
  return $ret;
}

function update_35() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE poll_choices ADD INDEX (nid)");
  return $ret;
}

function update_36() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE rating CHANGE old previous int(6) NOT NULL default '0'");
  $ret[] = update_sql("ALTER TABLE rating CHANGE new current int(6) NOT NULL default '0'");
  return $ret;
}

function update_37() {
  $ret = array();

  $ret[] = update_sql("DROP TABLE IF EXISTS sequences");

  $ret[] = update_sql("CREATE TABLE sequences (
    name VARCHAR(255) NOT NULL PRIMARY KEY,
    id INT UNSIGNED NOT NULL
  ) TYPE=MyISAM");

  if ($max = db_result(db_query("SELECT MAX(nid) FROM node"))) {
    $ret[] = update_sql("REPLACE INTO sequences VALUES ('node', $max)");
  }

  if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
    $ret[] = update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
  }
  // NOTE: move the comments bit down as soon as we switched to use the new comment module!

  if ($max = db_result(db_query("SELECT MAX(tid) FROM term_data"))) {
    $ret[] = update_sql("REPLACE INTO sequences VALUES ('term_data', $max)");
  }
  return $ret;
}

function update_38() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE watchdog CHANGE message message text NOT NULL default ''");
  return $ret;
}

function update_39() {
  $ret = array();
  $ret[] = update_sql("DROP TABLE moderate");

  $ret[] = update_sql("ALTER TABLE comments ADD score MEDIUMINT NOT NULL");
  $ret[] = update_sql("ALTER TABLE comments ADD status TINYINT UNSIGNED NOT NULL");
  $ret[] = update_sql("ALTER TABLE comments ADD users MEDIUMTEXT");

  $ret[] = update_sql("CREATE TABLE moderation_votes (
    mid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    vote VARCHAR(255),
    weight TINYINT NOT NULL
  )");

  $ret[] = update_sql("CREATE TABLE moderation_roles (
    rid INT UNSIGNED NOT NULL,
    mid INT UNSIGNED NOT NULL,
    value TINYINT NOT NULL
  )");

  $ret[] = update_sql("ALTER TABLE moderation_roles ADD INDEX (rid)");
  $ret[] = update_sql("ALTER TABLE moderation_roles ADD INDEX (mid)");

  $ret[] = update_sql("CREATE TABLE moderation_filters (
    fid INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    filter VARCHAR(255) NOT NULL,
    minimum SMALLINT NOT NULL
  )");

  $ret[] = update_sql("DELETE FROM moderation_votes");
  $ret[] = update_sql("INSERT INTO moderation_votes VALUES (1, '+1', 0)");
  $ret[] = update_sql("INSERT INTO moderation_votes VALUES (2, '-1', 1)");

  $ret[] = update_sql("DELETE FROM moderation_roles");
  $ret[] = update_sql("INSERT INTO moderation_roles VALUES (2, 1, 1)");
  $ret[] = update_sql("INSERT INTO moderation_roles VALUES (2, 2, -1)");

  $ret[] = update_sql("CREATE TABLE forum (
    nid int unsigned not null primary key,
    icon varchar(255) not null,
    shadow int unsigned not null
  )");
  return $ret;
}

function update_40() {
  $ret = array();
  if ($max = db_result(db_query("SELECT MAX(cid) FROM comments"))) {
    $ret[] = update_sql("REPLACE INTO sequences VALUES ('comments', $max)");
  }
  return $ret;
}

function update_41() {
  $ret = array();
  $ret[] = update_sql("CREATE TABLE statistics (
    nid int(11) NOT NULL,
    totalcount bigint UNSIGNED DEFAULT '0' NOT NULL,
    daycount mediumint UNSIGNED DEFAULT '0' NOT NULL,
    timestamp int(11) UNSIGNED DEFAULT '0' NOT NULL,
    PRIMARY KEY (nid),
    INDEX (totalcount),
    INDEX (daycount),
    INDEX (timestamp)
  )");

  $ret[] = update_sql("CREATE TABLE accesslog (
    nid int(11) UNSIGNED DEFAULT '0',
    url varchar(255),
    hostname varchar(128),
    uid int(10) UNSIGNED DEFAULT '0',
    timestamp int(11) UNSIGNED NOT NULL
  )");
  return $ret;
}

function update_42() {
  $ret = array();
  $ret[] = update_sql("DROP TABLE modules");
  $ret[] = update_sql("DROP TABLE layout");
  $ret[] = update_sql("DROP TABLE referrer");
  return $ret;
}

function update_43() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE blocks DROP remove");
  $ret[] = update_sql("ALTER TABLE blocks DROP name");
  $ret[] = update_sql("UPDATE boxes SET type = 0 WHERE type = 1");
  $ret[] = update_sql("UPDATE boxes SET type = 1 WHERE type = 2");
  return $ret;
}

function update_44() {
  $ret = array();
  $ret[] = update_sql("UPDATE system SET filename = CONCAT('modules/', filename) WHERE type = 'module'");
  return $ret;
}

function update_45() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE page ADD description varchar(128) NOT NULL default ''");
  return $ret;
}

function update_46() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE cache ADD created integer");
  }
  else {
    $ret[] = update_sql("ALTER TABLE cache ADD created int(11) NOT NULL default '0'");
  }
  return $ret;
}

function update_47() {
  $ret = array();
  if ($max = db_result(db_query("SELECT MAX(vid) FROM vocabulary"))) {
    $ret[] = update_sql("REPLACE INTO sequences VALUES ('vocabulary', $max)");
  }
  return $ret;
}

function update_48() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE watchdog ADD link varchar(255) DEFAULT '' NULL");
  return $ret;
}

function update_49() {
  $ret = array();
  /*
  ** Make sure the admin module is added to the system table or the
  ** admin menus won't show up.
  */

  $ret[] = update_sql("DELETE FROM system WHERE name = 'admin';");
  $ret[] = update_sql("INSERT INTO system VALUES ('modules/admin.module','admin','module','',1)");
  return $ret;
}

function update_50() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE forum ADD tid INT UNSIGNED NOT NULL");
  $result = db_queryd("SELECT n.nid, t.tid FROM node n, term_node t WHERE n.nid = t.nid AND type = 'forum'");
  while ($node = db_fetch_object($result)) {
    db_queryd("UPDATE forum SET tid = %d WHERE nid = %d", $node->tid, $node->nid);
  }
  $ret[] = update_sql("ALTER TABLE forum ADD INDEX (tid)");
  return $ret;
}

function update_51() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE blocks CHANGE delta delta varchar(32) NOT NULL default '0'");
  return $ret;
}

function update_52() {
  $ret = array();
  $ret[] = update_sql("UPDATE sequences SET name = 'comments_cid' WHERE name = 'comments';");
  $ret[] = update_sql("UPDATE sequences SET name = 'node_nid' WHERE name = 'node';");

  $ret[] = update_sql("DELETE FROM sequences WHERE name = 'import'");
  $ret[] = update_sql("DELETE FROM sequences WHERE name = 'bundle_bid'");  // in case we would run this entry twice
  $ret[] = update_sql("DELETE FROM sequences WHERE name = 'feed_fid'");    // in case we would run this entry twice

  $bundles = db_result(db_query("SELECT MAX(bid) FROM bundle;"));
  $ret[] = update_sql("INSERT INTO sequences (name, id) VALUES ('bundle_bid', '$bundles')");

  $feeds = db_result(db_query("SELECT MAX(fid) FROM feed;"));
  $ret[] = update_sql("INSERT INTO sequences (name, id) VALUES ('feed_fid', '$feeds')");

  $ret[] = update_sql("UPDATE sequences SET name = 'vocabulary_vid' WHERE name = 'vocabulary';");

  $ret[] = update_sql("UPDATE sequences SET name = 'term_data_tid' WHERE name = 'term_data'");
  return $ret;
}

function update_53() {
  $ret = array();
  $ret[] = update_sql("CREATE INDEX book_parent ON book(parent);");
  return $ret;
}

function update_54() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE locales CHANGE string string BLOB DEFAULT '' NOT NULL");
  return $ret;
}

function update_55() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE site ADD checked INT(11) NOT NULL;");
  $ret[] = update_sql("ALTER TABLE site CHANGE timestamp changed INT(11) NOT NULL;");
  return $ret;
}

function update_56() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE vocabulary CHANGE types nodes TEXT DEFAULT '' NOT NULL");
  return $ret;
}

function update_57() {
  $ret = array();
  $ret[] = update_sql("DELETE FROM variable WHERE name = 'site_charset'");
  return $ret;
}

function update_58() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE {node} ADD path varchar(250) NULL");
    $ret[] = update_sql("ALTER TABLE {node} ALTER COLUMN path SET DEFAULT ''");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {node} ADD path varchar(250) NULL default ''");
  }
  return $ret;
}

function update_59() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255)");
    $ret[] = update_sql("ALTER TABLE {comments} ALTER COLUMN thread SET NOT NULL");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {comments} ADD thread VARCHAR(255) NOT NULL");
  }

  $result = db_query("SELECT DISTINCT(nid) FROM {comments} WHERE thread = ''");

  while ($node = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
431
    $result2 = db_query("SELECT cid, pid FROM {comments} WHERE nid = '%d' ORDER BY timestamp", $node->nid);
Dries's avatar
 
Dries committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
    $comments = array();
    while ($comment = db_fetch_object($result2)) {
      $comments[$comment->cid] = $comment;
    }

    $structure = array();
    $structure = _update_thread_structure($comments, 0, -1, $structure);

    foreach ($structure as $cid => $thread) {
      $new_parts = array();
      foreach(explode(".", $thread) as $part) {
        if ($part > 9) {
          $start = substr($part, 0, strlen($part) - 1);
          $end = substr($part, -1, 1);

          $new_parts[] = str_repeat("9", $start).$end;
        }
        else {
          $new_parts[] = $part;
        }
      }
      $thread = implode(".", $new_parts);

      db_query("UPDATE {comments} SET thread = '%s' WHERE cid = '%d'", $thread."/", $comments[$cid]->cid);
    }
  }
  return $ret;
}

function _update_thread_structure($comments, $pid, $depth, $structure) {
  $ret = array();
  $depth++;

  foreach ($comments as $key => $comment) {
    if ($comment->pid == $pid) {
      if ($structure[$comment->pid]) {
        $structure[$comment->cid] = $structure[$comment->pid]."."._update_next_thread($structure, $structure[$comment->pid]);
      }
      else {
        $structure[$comment->cid] = _update_next_thread($structure, "");
      }

      $structure = _update_thread_structure($comments, $comment->cid, $depth, $structure);
    }
  }

  return $structure;
  return $ret;
}

function update_60() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {forum} DROP icon");
  return $ret;
}

function update_61() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("CREATE TABLE {sessions} (
      uid integer NOT NULL,
      sid varchar(32) NOT NULL default '',
      hostname varchar(128) NOT NULL default '',
      timestamp integer NOT NULL default '0',
      session text,
      PRIMARY KEY (sid)
     );");

    $ret[] = update_sql("ALTER TABLE {users} DROP session;");
    $ret[] = update_sql("ALTER TABLE {users} DROP hostname;");
    $ret[] = update_sql("ALTER TABLE {users} DROP sid;");

  }
  else {
    $ret[] = update_sql("CREATE TABLE IF NOT EXISTS {sessions} (
      uid int(10) unsigned NOT NULL,
      sid varchar(32) NOT NULL default '',
      hostname varchar(128) NOT NULL default '',
      timestamp int(11) NOT NULL default '0',
      session text,
      KEY uid (uid),
      KEY sid (sid(4)),
      KEY timestamp (timestamp)
    )");

    $ret[] = update_sql("ALTER TABLE {users} DROP session;");
    $ret[] = update_sql("ALTER TABLE {users} DROP hostname;");
    $ret[] = update_sql("ALTER TABLE {users} DROP sid;");
  }
  return $ret;
}

function update_62() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("CREATE INDEX accesslog_timestamp ON {accesslog} (timestamp)");

    $ret[] = update_sql("DROP INDEX node_type_idx");
    $ret[] = update_sql("DROP INDEX node_title_idx");
    $ret[] = update_sql("DROP INDEX node_promote_idx");

    $ret[] = update_sql("CREATE INDEX node_type ON {node} (type)");
    $ret[] = update_sql("CREATE INDEX node_title_type ON {node} (title,type)");
    $ret[] = update_sql("CREATE INDEX node_moderate ON {node} (moderate)");
    $ret[] = update_sql("CREATE INDEX node_path ON {node} (path)");
    $ret[] = update_sql("CREATE INDEX node_promote_status ON {node} (promote, status)");

  }
  else {
    $ret[] = update_sql("ALTER TABLE {accesslog} ADD INDEX accesslog_timestamp (timestamp)");

    $ret[] = update_sql("ALTER TABLE {node} DROP INDEX type");
    $ret[] = update_sql("ALTER TABLE {node} DROP INDEX title");
    $ret[] = update_sql("ALTER TABLE {node} DROP INDEX promote");

    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_type (type(4))");
    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_title_type (title,type(4))");
    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_moderate (moderate)");
    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_path (path(5))");
    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_promote_status (promote, status)");
  }
  return $ret;
}

function _update_next_thread($structure, $parent) {
  $ret = array();
  do {
    $val++;
    if ($parent) {
      $thread = "$parent.$val";
    }
    else {
      $thread = $val;
    }

  } while (array_search($thread, $structure));

  return $val;
  return $ret;
}

function update_63() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {users} CHANGE uid uid int(10) unsigned NOT NULL default '0'");
    $ret[] = update_sql("INSERT INTO {users} (uid, name, mail, timestamp) VALUES ('0', '', '', '". time() ."')");
    $users = db_result(db_query("SELECT MAX(uid) FROM {users};"));
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('users_uid', '$users')");
  }
  return $ret;
}

function update_64() {
  $ret = array();
  $ret[] = update_sql("UPDATE {users} SET rid = 1 WHERE uid = 0");
  return $ret;
}

function update_65() {
  $ret = array();
  // PostgreSQL-only update.
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("CREATE FUNCTION \"rand\"() RETURNS float AS '
      BEGIN
        RETURN random();
      END;' LANGUAGE 'plpgsql'");
  }
  return $ret;
}

function update_66() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("CREATE TABLE {path} (
      pid serial,
      src varchar(128) NOT NULL default '',
      dst varchar(128) NOT NULL default '',
      PRIMARY KEY  (pid)
    )");
    $ret[] = update_sql("CREATE INDEX path_src_idx ON {path}(src)");
    $ret[] = update_sql("CREATE INDEX path_dst_idx ON {path}(dst)");
    $result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
    while ($node = db_fetch_object($result)) {
      $ret[] = update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
    }
  }
  else {
    $ret[] = update_sql("CREATE TABLE {path} (
      pid int(10) unsigned NOT NULL auto_increment,
      src varchar(128) NOT NULL default '',
      dst varchar(128) NOT NULL default '',
      PRIMARY KEY  (pid),
      UNIQUE KEY src (src),
      UNIQUE KEY dst (dst)
    )");
    // Migrate the existing paths:
    $result = db_query("SELECT nid, path FROM {node} WHERE path != ''");
    while ($node = db_fetch_object($result)) {
      $ret[] = update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')");
    }

    $ret[] = update_sql("ALTER TABLE {node} DROP path");
  }
  return $ret;
}

function update_67() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    // Taking no action.  PostgreSQL is not always capable of dropping columns.
  }
  else {
    $ret[] = update_sql("ALTER TABLE {users} DROP homepage");
  }
  return $ret;
}

function update_68() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    // Unneccesary. The PostgreSQL port was already using a sequence.
  }
  else {
    $max = db_result(db_query("SELECT MAX(aid) FROM {access};"));
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('access_aid', '$max')");
    $ret[] = update_sql("ALTER TABLE {access} CHANGE aid aid tinyint(10) NOT NULL ");
  }
  return $ret;
}

function update_69() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    /* Rename the statistics table to node_counter */
    $ret[] = update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
    $ret[] = update_sql("DROP INDEX  {statistics}_totalcount_idx");
    $ret[] = update_sql("DROP INDEX  {statistics}_daycount_idx");
    $ret[] = update_sql("DROP INDEX  {statistics}_timestamp_idx");
    $ret[] = update_sql("CREATE INDEX {node_counter}_totalcount_idx ON {node_counter}(totalcount)");
    $ret[] = update_sql("CREATE INDEX {node_counter}_daycount_idx ON {node_counter}(daycount)");
    $ret[] = update_sql("CREATE INDEX {node_counter}_timestamp_idx ON {node_counter}(timestamp)");

    /* Rename the path table to url_alias */
    $ret[] = update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
    $ret[] = update_sql("ALTER TABLE {path}_pid_seq RENAME TO {url_alias}_pid_seq");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {statistics} RENAME TO {node_counter}");
    $ret[] = update_sql("ALTER TABLE {path} RENAME TO {url_alias}");
    $ret[] = update_sql("UPDATE {sequences} SET name = '{url_alias}_pid' WHERE name = '{path}_pid'");
  }

  $ret[] = update_sql("UPDATE {users} SET name = '' WHERE uid = 0;");
  return $ret;
}

function update_70() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {variable} CHANGE name name varchar(48) NOT NULL");
  return $ret;
}

function update_71() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE {system} ADD bootstrap integer");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {system} ADD bootstrap int(2)");
  }
  return $ret;
}

function update_72() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE {blocks} ADD throttle smallint");
    $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET DEFAULT '0'");
    $ret[] = update_sql("UPDATE {blocks} SET throttle = 0");
    $ret[] = update_sql("ALTER TABLE {blocks} ALTER COLUMN throttle SET NOT NULL");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {blocks} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
  }
  return $ret;
}

function update_73() {
  $ret = array();
  /* MySQL only update */
  if ($GLOBALS["db_type"] == "mysql") {
    $ret[] = update_sql("ALTER TABLE {book} CHANGE log log longtext");
    $ret[] = update_sql("ALTER TABLE {boxes} CHANGE body body longtext");
    $ret[] = update_sql("ALTER TABLE {cache} CHANGE data data longtext");
    $ret[] = update_sql("ALTER TABLE {comments} CHANGE comment comment longtext");
    $ret[] = update_sql("ALTER TABLE {comments} CHANGE users users longtext");
    $ret[] = update_sql("ALTER TABLE {directory} CHANGE slogan slogan longtext");
    $ret[] = update_sql("ALTER TABLE {directory} CHANGE mission mission longtext");
    $ret[] = update_sql("ALTER TABLE {feed} CHANGE description description longtext");
    $ret[] = update_sql("ALTER TABLE {item} CHANGE description description longtext");
    $ret[] = update_sql("ALTER TABLE {node} CHANGE users users longtext");
    $ret[] = update_sql("ALTER TABLE {node} CHANGE teaser teaser longtext");
    $ret[] = update_sql("ALTER TABLE {node} CHANGE body body longtext");
    $ret[] = update_sql("ALTER TABLE {node} CHANGE revisions revisions longtext");
    $ret[] = update_sql("ALTER TABLE {permission} CHANGE perm perm longtext");
    $ret[] = update_sql("ALTER TABLE {poll} CHANGE voters voters longtext");
    $ret[] = update_sql("ALTER TABLE {sessions} CHANGE session session longtext");
    $ret[] = update_sql("ALTER TABLE {term_data} CHANGE description description longtext");
    $ret[] = update_sql("ALTER TABLE {users} CHANGE data data longtext");
    $ret[] = update_sql("ALTER TABLE {variable} CHANGE value value longtext");
    $ret[] = update_sql("ALTER TABLE {vocabulary} CHANGE description description longtext");
    $ret[] = update_sql("ALTER TABLE {vocabulary} CHANGE nodes nodes longtext");
    $ret[] = update_sql("ALTER TABLE {watchdog} CHANGE message message longtext");
  }
  return $ret;
}

function update_74() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE {system} ADD throttle smallint");
    $ret[] = update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET DEFAULT '0'");
    $ret[] = update_sql("UPDATE {system} SET throttle = 0");
    $ret[] = update_sql("ALTER TABLE {system} ALTER COLUMN throttle SET NOT NULL");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {system} ADD throttle tinyint(1) NOT NULL DEFAULT '0'");
  }
  return $ret;
}

function update_75() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE {feed} ADD etag text");
    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET DEFAULT ''");
    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN etag SET NOT NULL");

    $ret[] = update_sql("ALTER TABLE {feed} ADD modified integer");
    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET DEFAULT '0'");
    $ret[] = update_sql("UPDATE {feed} SET modified = 0");
    $ret[] = update_sql("ALTER TABLE {feed} ALTER COLUMN modified SET NOT NULL");

    $ret[] = update_sql("ALTER TABLE {feed} RENAME timestamp TO checked");

    $ret[] = update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
    $ret[] = update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {feed} ADD etag varchar(255) NOT NULL DEFAULT ''");
    $ret[] = update_sql("ALTER TABLE {feed} ADD modified int(10) NOT NULL DEFAULT 0");
    $ret[] = update_sql("ALTER TABLE {feed} CHANGE timestamp checked int(10) NOT NULL DEFAULT 0");
    $ret[] = update_sql("UPDATE {blocks} SET module = 'aggregator' WHERE module = 'import'");
    $ret[] = update_sql("UPDATE {system} SET filename = 'modules/aggregator.module', name = 'aggregator' WHERE filename = 'modules/import.module'");
  }
  return $ret;
}

function update_76() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
    $ret[] = update_sql("ALTER TABLE {feed} ADD image text");
  } else {
    $ret[] = update_sql("ALTER TABLE {feed} ADD image longtext");
  }
  return $ret;
}

function update_77() {
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {cache} ADD headers text");
  return $ret;
}

function update_78() {
  $ret = array();
  if ($GLOBALS["db_type"] == "mysql") {
    $ret[] = update_sql("CREATE TABLE {filters} (
      module varchar(64) NOT NULL default '',
      weight tinyint(2) DEFAULT '0' NOT NULL,
815
      KEY module (module)
Dries's avatar
 
Dries committed
816 817 818
    )");
  }
  else {
819 820 821 822 823
    $ret[] = update_sql("CREATE TABLE {filters} (
      module varchar(64) NOT NULL DEFAULT '',
      weight smallint NOT NULL DEFAULT 0
      );");
    $ret[] = update_sql("CREATE INDEX {filters_weight} ON {filters} (weight);");
Dries's avatar
 
Dries committed
824 825 826 827 828 829 830 831 832 833 834 835
  }
  return $ret;
}

function update_79() {
  $ret = array();
  // Works for both mysql and postgresql
  $ret[] = update_sql("ALTER TABLE {node} DROP attributes");
  $ret[] = update_sql("ALTER TABLE {comments} DROP link");
  return $ret;
}

Dries's avatar
 
Dries committed
836
function update_80() {
Dries's avatar
 
Dries committed
837 838 839 840
  if ($GLOBALS['db_type'] == 'mysql') {
    // Add a 'created' field to the users table:
    $ret[] = update_sql('ALTER TABLE {users} ADD created INT(11) NOT NULL');
    $ret[] = update_sql('ALTER TABLE {users} CHANGE timestamp changed INT(11) NOT NULL');
Dries's avatar
 
Dries committed
841

Dries's avatar
 
Dries committed
842 843 844
    // Add some indices to speed up the update process:
    $ret[] = update_sql('ALTER TABLE {comments} ADD index (timestamp)');
    $ret[] = update_sql('ALTER TABLE {node} ADD index (created)');
Dries's avatar
 
Dries committed
845

Dries's avatar
 
Dries committed
846 847
    // Assign everyone a created timestamp to begin with:
    $ret[] = update_sql("UPDATE {users} SET created = changed WHERE created = ''");
Dries's avatar
 
Dries committed
848

Dries's avatar
 
Dries committed
849 850 851 852 853 854 855 856 857 858 859 860
  }
  else {
    // Add a 'created' field to the users table:
    $ret[] = update_sql('ALTER TABLE {users} ADD created INTEGER');
    $ret[] = update_sql("ALTER TABLE {users} ALTER COLUMN created SET DEFAULT '0'");
    $ret[] = update_sql("UPDATE {users} SET created = 0");
    $ret[] = update_sql("ALTER TABLE {users} ALTER COLUMN created SET NOT NULL");

    $ret[] = update_sql('ALTER TABLE {users} RENAME timestamp TO changed');

    $ret[] = update_sql("UPDATE {users} SET created = changed WHERE created = 0");
  }
Dries's avatar
 
Dries committed
861

Steven Wittens's avatar
Steven Wittens committed
862 863
  // Print a status message:"
  print '<p>Note: this might take a while ...</p>';
Dries's avatar
 
Dries committed
864

Steven Wittens's avatar
Steven Wittens committed
865 866 867 868 869 870 871 872 873
  // Try updating the user records using the comment table:
  $result = db_query('SELECT DISTINCT(u.uid) FROM {comments} c LEFT JOIN {users} u ON c.uid = u.uid WHERE c.timestamp < u.created');
  while ($account = db_fetch_object($result)) {
    // Retrieve the proper timestamp:
    $timestamp = db_result(db_query('SELECT MIN(timestamp) FROM {comments} WHERE uid = %d', $account->uid));

    // Update this user record as well as older records with an older timestamp:
    db_query('UPDATE {users} SET created = %d WHERE created > %d AND uid <= %d', $timestamp, $timestamp, $account->uid);
  }
Dries's avatar
 
Dries committed
874

Steven Wittens's avatar
Steven Wittens committed
875 876 877 878 879 880 881 882 883 884
  // Try updating the user records using the node table:
  $result = db_query('SELECT DISTINCT(u.uid) FROM {node} n LEFT JOIN {users} u ON n.uid = u.uid WHERE n.created < u.created');
  while ($account = db_fetch_object($result)) {
    // Retrieve the proper timestamp:
    $timestamp = db_result(db_query('SELECT MIN(created) FROM {node} WHERE uid = %d', $account->uid));

    // Update this user record as well as older records with an older timestamp:
    db_query('UPDATE {users} SET created = %d WHERE created > %d AND uid <= %d', $timestamp, $timestamp, $account->uid);
  }

Dries's avatar
 
Dries committed
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941
  if ($GLOBALS['db_type'] == 'mysql') {
    // Add profile module related tables:
    $ret[] = update_sql("CREATE TABLE {profile_fields} (
      fid int(10) NOT NULL auto_increment,
      title varchar(255) default NULL,
      name varchar(128) default NULL,
      explanation TEXT default NULL,
      category varchar(255) default NULL,
      type varchar(128) default NULL,
      weight tinyint(1) DEFAULT '0' NOT NULL,
      overview tinyint(1) DEFAULT '0' NOT NULL,
      options text,
      KEY category (category),
      UNIQUE KEY name (name),
      PRIMARY KEY (fid)
     );");

    $ret[] = update_sql("CREATE TABLE {profile_values} (
      fid int(11) unsigned default '0',
      uid int(11) unsigned default '0',
      value text,
      KEY uid (uid),
      KEY fid (fid)
     );");
    $ret[] = update_sql("ALTER TABLE {users} ADD picture varchar(255) NOT NULL DEFAULT ''");
  }
  else {

    $ret[] = update_sql("CREATE TABLE profile_fields (
      fid serial,
      title varchar(255) default NULL,
      name varchar(128) default NULL,
      explanation TEXT default NULL,
      category varchar(255) default NULL,
      type varchar(128) default NULL,
      weight smallint DEFAULT '0' NOT NULL,
      overview smallint DEFAULT '0' NOT NULL,
      options text,
      UNIQUE (name),
      PRIMARY KEY (fid)
    )");
    $ret[] = update_sql("CREATE INDEX profile_fields_category ON profile_fields (category)");

    $ret[] = update_sql("CREATE TABLE profile_values (
      fid integer default '0',
      uid integer default '0',
      value text
    )");
    $ret[] = update_sql("CREATE INDEX profile_values_uid ON profile_values (uid)");
    $ret[] = update_sql("CREATE INDEX profile_values_fid ON profile_values (fid)");

    $ret[] = update_sql("ALTER TABLE {users} ADD picture varchar(255)");
    $ret[] = update_sql("ALTER TABLE {users} ALTER COLUMN picture SET DEFAULT ''");
    $ret[] = update_sql("UPDATE {users} SET picture = ''");
    $ret[] = update_sql("ALTER TABLE {users} ALTER COLUMN picture SET NOT NULL");

  }
942

Steven Wittens's avatar
Steven Wittens committed
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971
  // Migrate the old profile data to the new scheme:
  $fields = array(
    array("Name", "realname", "textfield", NULL, 0),
    array("Address", "address", "textfield", NULL, 0),
    array("City", "city", "textfield", NULL, 0),
    array("State, province or region", "state", "textfield", NULL, 0),
    array("Zip or postal code", "zip", "textfield", NULL, 0),
    array("Country", "country", "textfield", NULL, 1),
    array("Gender", "gender", "selection", "male\nfemale", 1),
    array("Job title", "job", "textfield", NULL, 0),
    array("ICQ messenger ID", "icq", "textfield", NULL, 0),
    array("MSN messenger ID", "msn", "textfield", NULL, 0),
    array("Yahoo messenger ID", "yahoo", "textfield", NULL, 0),
    array("AIM messenger ID", "aim", "textfield", NULL, 0),
    array("URL of homepage", "homepage", "url", NULL, 1),
    array("Biography", "biography", "textarea", NULL, 0),
    array("Interests", "interests", "textarea", NULL, 0),
    array("Public key", "publickey", "textarea", NULL, 0),
    array("Birthday", "birthday", "date", NULL, 0)
  );

  // Remove existing data (debug mode):
  db_query('DELETE FROM {profile_fields}');
  db_query('DELETE FROM {profile_values}');

  foreach ($fields as $field) {
    db_query("INSERT INTO {profile_fields} (title, name, type, category, options, overview) VALUES ('%s', '%s', '%s', 'Personal information', '%s', %d)", $field[0], $field[1], $field[2], $field[3], $field[4]);
  }

Dries's avatar
 
Dries committed
972
  $result = db_query("SELECT uid FROM {users} WHERE uid > 0");
Dries's avatar
 
Dries committed
973
  while ($account = db_fetch_object($result)) {
Steven Wittens's avatar
Steven Wittens committed
974 975 976
    // Load the user record:
    $account = user_load(array('uid' => $account->uid));
    $edit = array();
977

Steven Wittens's avatar
Steven Wittens committed
978
    // Modify the user record:
979
    foreach ($fields as $field) {
Steven Wittens's avatar
Steven Wittens committed
980 981 982 983 984
      $old = "profile_". $field[1];
      $new = $field[1];
      if ($account->$old) {
        $edit[$new] = $account->$old;
      }
985 986
      // Force deletion of old field
      $edit[$old] = NULL;
987 988
    }

Steven Wittens's avatar
Steven Wittens committed
989 990 991
    // Birthday format change:
    if ($edit['birthday']) {
      $edit['birthday'] = array('day' => $edit['birthday'], 'month' => $account->profile_birthmonth, 'year' => $account->profile_birthyear);
992 993 994
      // Force deletion of old field
      $edit['profile_birthmonth'] = NULL;
      $edit['profile_birthyear'] = NULL;
995 996
    }

Steven Wittens's avatar
Steven Wittens committed
997 998 999
    // Gender specific changes:
    if ($edit['gender'] == 'f') $edit['gender'] = 'female';
    if ($edit['gender'] == 'm') $edit['gender'] = 'male';
1000

Steven Wittens's avatar
Steven Wittens committed
1001 1002 1003
    // Avatar specific changes:
    if ($account->profile_avatar) {
      $edit['picture'] = $account->profile_avatar;
1004 1005
      // Force deletion of old field
      $edit['profile_avatar'] = NULL;
1006
    }
Steven Wittens's avatar
Steven Wittens committed
1007 1008

    // Save the update record:
Dries's avatar
 
Dries committed
1009
    user_save($account, $edit, 'Personal information');
Steven Wittens's avatar
Steven Wittens committed
1010
  }
1011

1012
  // This variable is needed to distinguish between 4.5-RC sites which ran a faulty
1013 1014 1015
  // update_80() and 4.5-final sites. See update_108.
  variable_set('update_80_fix', true);

Dries's avatar
 
Dries committed
1016
  return $ret;
Dries's avatar
 
Dries committed
1017 1018
}

Dries's avatar
 
Dries committed
1019
function update_81() {
1020 1021 1022 1023 1024 1025 1026
  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql('ALTER TABLE {profile_fields} ADD page varchar(255) default NULL');
  }
  else {
    $ret[] = update_sql('ALTER TABLE {profile_fields} ADD page varchar(255)');
    $ret[] = update_sql('ALTER TABLE {profile_fields} ALTER COLUMN page SET default NULL');
  }
1027
  $ret[] = update_sql("UPDATE {profile_fields} SET type = 'url' WHERE name = 'homepage'");
Dries's avatar
 
Dries committed
1028 1029
  return $ret;
}
1030

Dries's avatar
 
Dries committed
1031
function update_82() {
1032 1033 1034 1035 1036 1037 1038 1039 1040
  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql("ALTER TABLE {profile_fields} ADD required tinyint(1) DEFAULT '0' NOT NULL");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {profile_fields} ADD required smallint");
    $ret[] = update_sql("ALTER TABLE {profile_fields} ALTER COLUMN required SET DEFAULT '0'");
    $ret[] = update_sql("UPDATE {profile_fields} SET required = '0'");
    $ret[] = update_sql("ALTER TABLE {profile_fields} ALTER COLUMN required SET NOT NULL");
  }
Dries's avatar
 
Dries committed
1041 1042 1043
  return $ret;
}

1044 1045 1046
function update_83() {
  $ret = array();
  if ($GLOBALS["db_type"] == "mysql") {
Dries's avatar
Dries committed
1047
    $ret[] = update_sql("CREATE TABLE {menu} (
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
      mid int(10) unsigned NOT NULL default '0',
      pid int(10) unsigned NOT NULL default '0',
      path varchar(255) NOT NULL default '',
      title varchar(255) NOT NULL default '',
      weight tinyint(4) NOT NULL default '0',
      visibility int(1) unsigned NOT NULL default '0',
      status int(1) unsigned NOT NULL default '0',
      PRIMARY KEY  (mid)
     );");
  }
  else {
Dries's avatar
Dries committed
1059
    $ret[] = update_sql("CREATE TABLE {menu} (
Dries's avatar
 
Dries committed
1060
  mid serial,
1061 1062 1063 1064 1065 1066 1067 1068 1069
  pid integer NOT NULL default '0',
  path varchar(255) NOT NULL default '',
  title varchar(255) NOT NULL default '',
  weight smallint NOT NULL default '0',
  visibility smallint NOT NULL default '0',
  status smallint NOT NULL default '0',
  PRIMARY KEY  (mid)
);");

1070
  }
1071
  db_next_id('{menu}_mid');
1072 1073 1074
  return $ret;
}

1075 1076 1077
function update_84() {
  $ret = array();
  if ($GLOBALS["db_type"] == "mysql") {
1078
    $ret[] = update_sql("ALTER TABLE {vocabulary} ADD help VARCHAR(255) NOT NULL DEFAULT '' AFTER description;");
1079 1080
  }
  else {
1081 1082 1083 1084
    $ret[] = update_sql("ALTER TABLE {vocabulary} ADD help VARCHAR(255)");
    $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER help SET DEFAULT ''");
    $ret[] = update_sql("UPDATE {vocabulary} SET help = ''");
    $ret[] = update_sql("ALTER TABLE {vocabulary} ALTER help SET NOT NULL");
1085 1086 1087 1088
  }
  return $ret;
}

Dries's avatar
 
Dries committed
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
function update_85() {
  $ret = array();
  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql("ALTER TABLE {bundle} RENAME TO {aggregator_category}");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} DROP attributes");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} CHANGE bid cid int(10) NOT NULL auto_increment");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} ADD description longtext NOT NULL");
    $ret[] = update_sql("UPDATE {sequences} SET name = '{aggregator_category}_cid' WHERE name = '{bundle}_bid'");
    $ret[] = update_sql("ALTER TABLE {feed} RENAME TO {aggregator_feed}");
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} DROP attributes");
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} ADD block tinyint(2) NOT NULL");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} ADD block tinyint(2) NOT NULL");
    $ret[] = update_sql("UPDATE {sequences} SET name = '{aggregator_feed}_fid' WHERE name = '{feed}_fid'");
    $ret[] = update_sql("ALTER TABLE {item} RENAME TO {aggregator_item}");
    $ret[] = update_sql("ALTER TABLE {aggregator_item} DROP attributes");
Dries's avatar
 
Dries committed
1104
    $max = db_result(db_query_range("SELECT iid FROM {aggregator_item} ORDER BY iid DESC", 0, 1));
Dries's avatar
 
Dries committed
1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
    if ($max) {
      $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{aggregator_item}_iid', $max)");
    }
    $ret[] = update_sql("CREATE TABLE {aggregator_category_feed} (
      fid int(10) NOT NULL,
      cid int(10) NOT NULL,
      PRIMARY KEY (fid, cid)
     )");
    $ret[] = update_sql("CREATE TABLE {aggregator_category_item} (
      iid int(10) NOT NULL,
      cid int(10) NOT NULL,
      PRIMARY KEY (iid, cid)
     )");
Dries's avatar
 
Dries committed
1118 1119 1120 1121
    $ret[] = update_sql("ALTER TABLE {aggregator_category} MODIFY description longtext NULL");
    $ret[] = update_sql("ALTER TABLE {aggregator_item} MODIFY description longtext NULL");
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} MODIFY description longtext NULL");
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} MODIFY image longtext NULL");
Dries's avatar
 
Dries committed
1122

Dries's avatar
 
Dries committed
1123 1124
  }
  else {
1125 1126 1127
    $ret[] = update_sql("ALTER TABLE {bundle} RENAME TO {aggregator_category}");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} DROP attributes");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} RENAME bid TO cid");
Dries's avatar
 
Dries committed
1128 1129 1130 1131
    $lastvalue = db_result(db_query('SELECT last_value from {bundle}_bid_seq'));
    $ret[] = update_sql("CREATE SEQUENCE {aggregator_category}_cid_seq START $lastvalue MINVALUE 0");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} ALTER cid SET DEFAULT nextval('public.{aggregator_category}_cid_seq'::text)");

1132 1133 1134
    $ret[] = update_sql("ALTER TABLE {aggregator_category} ADD description text");
    $ret[] = update_sql("UPDATE {aggregator_category} SET description = ''");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} ALTER COLUMN description SET NOT NULL");
Dries's avatar
 
Dries committed
1135

1136
    $ret[] = update_sql("ALTER TABLE {feed} RENAME TO {aggregator_feed}");
Dries's avatar
 
Dries committed
1137 1138 1139 1140
    $lastvalue = db_result(db_query('SELECT last_value from {feed}_fid_seq'));
    $ret[] = update_sql("CREATE SEQUENCE {aggregator_feed}_fid_seq START $lastvalue MINVALUE 0");
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} ALTER fid SET DEFAULT nextval('public.{aggregator_feed}_fid_seq'::text)");

1141 1142 1143 1144 1145 1146 1147
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} DROP attributes");
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} ADD block smallint");
    $ret[] = update_sql("UPDATE {aggregator_feed} SET block = 0");
    $ret[] = update_sql("ALTER TABLE {aggregator_feed} ALTER COLUMN block SET NOT NULL");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} ADD block smallint");
    $ret[] = update_sql("UPDATE {aggregator_category} SET block = 0");
    $ret[] = update_sql("ALTER TABLE {aggregator_category} ALTER COLUMN block SET NOT NULL");
Dries's avatar
 
Dries committed
1148

1149
    $ret[] = update_sql("ALTER TABLE {item} RENAME TO {aggregator_item}");
Dries's avatar
 
Dries committed
1150 1151 1152 1153
    $lastvalue = db_result(db_query('SELECT last_value from {item}_iid_seq'));
    $ret[] = update_sql("CREATE SEQUENCE {aggregator_item}_iid_seq START $lastvalue MINVALUE 0");
    $ret[] = update_sql("ALTER TABLE {aggregator_item} ALTER iid SET DEFAULT nextval('public.{aggregator_item}_iid_seq'::text)");

1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
    $ret[] = update_sql("ALTER TABLE {aggregator_item} DROP attributes");
    $ret[] = update_sql("CREATE TABLE {aggregator_category_feed} (
      fid integer NOT NULL default '0',
      cid integer NOT NULL default '0',
      PRIMARY KEY  (fid,cid)
    );");
    $ret[] = update_sql("CREATE TABLE {aggregator_category_item} (
      iid integer NOT NULL default '0',
      cid integer NOT NULL default '0',
      PRIMARY KEY  (iid,cid)
     )");
Dries's avatar
 
Dries committed
1165 1166 1167 1168
  }
  return $ret;
}

Dries's avatar
 
Dries committed
1169 1170 1171 1172
function update_86() {
  $ret = array();
  $ret[] = update_sql("INSERT INTO {users_roles} (uid, rid) SELECT uid, rid FROM {users}");
  // TODO: should we verify the insert above worked before dropping rid?
1173 1174 1175 1176
  if ($GLOBALS['db_type'] == 'mysql') {
    //only the most recent versions of postgres support dropping columns
    $ret[] = update_sql("ALTER TABLE {users} DROP rid");
  }
Dries's avatar
Dries committed
1177
  return $ret;
Dries's avatar
 
Dries committed
1178 1179
}

Dries's avatar
 
Dries committed
1180
function update_87() {
1181
  // Works for both postgres and mysql
Dries's avatar
 
Dries committed
1182 1183 1184 1185 1186 1187 1188
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {comments} ADD name varchar(60) DEFAULT NULL");
  $ret[] = update_sql("ALTER TABLE {comments} ADD mail varchar(64) DEFAULT NULL");
  $ret[] = update_sql("ALTER TABLE {comments} ADD homepage varchar(255) DEFAULT NULL");
  return $ret;
}

Dries's avatar
 
Dries committed
1189 1190
function update_88() {
  $ret = array();
1191 1192 1193 1194 1195

  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql("ALTER TABLE {menu} DROP status");
    $ret[] = update_sql("ALTER TABLE {menu} DROP visibility");
    $ret[] = update_sql("ALTER TABLE {menu} ADD type INT(2) UNSIGNED DEFAULT '0' NOT NULL");
Dries's avatar
 
Dries committed
1196
  }
1197 1198 1199 1200 1201 1202
  else {
    $ret[] = update_sql("ALTER TABLE {menu} ADD type smallint");
    $ret[] = update_sql("ALTER TABLE {menu} ALTER COLUMN type SET DEFAULT '0'");
    $ret[] = update_sql("UPDATE {menu} SET type = '0'");
    $ret[] = update_sql("ALTER TABLE {menu} ALTER COLUMN type SET NOT NULL");
  }
Dries's avatar
 
Dries committed
1203 1204 1205 1206
  $ret[] = update_sql("DELETE FROM {menu}");
  return $ret;
}

Dries's avatar
 
Dries committed
1207 1208
function update_89() {
  $ret = array();
Dries's avatar
 
Dries committed
1209

1210 1211 1212 1213 1214 1215
  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql("ALTER TABLE {node} CHANGE static sticky INT(2) DEFAULT '0' NOT NULL");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {node} RENAME static TO sticky;");
  }
Dries's avatar
 
Dries committed
1216 1217 1218 1219 1220

  // Change the node settings, so that it uses node_sticky_$type instead of node_static_$type
  $result = db_query("SELECT * FROM {variable} WHERE name LIKE 'node_static_%'");
  while ($variable = db_fetch_object($result)) {
    //get the node type name, place it into $name_arr. The name can be found with $name_arr[2]
1221 1222
    $name_arr = explode("_", $variable->name, 3);
    $ret[] = update_sql("INSERT INTO {variable} (name,value) VALUES ('node_sticky_". $name_arr[2] ."','". $variable->value. "')");
Dries's avatar
 
Dries committed
1223 1224 1225 1226 1227 1228
  }
  $ret[] = db_query("DELETE FROM {variable} WHERE name LIKE 'node_static_%'");

  return $ret;
}

1229
function update_90() {
1230 1231 1232 1233 1234 1235 1236

  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql("ALTER TABLE {profile_fields} CHANGE overview visibility INT(1) UNSIGNED DEFAULT '0' NOT NULL");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {profile_fields} RENAME overview TO visibility");
  }
1237 1238 1239 1240 1241
  $ret[] = update_sql("UPDATE {profile_fields} SET visibility = 2 WHERE visibility = 1");
  $ret[] = update_sql("UPDATE {profile_fields} SET visibility = 1 WHERE visibility = 0");
  return $ret;
}

1242 1243 1244
function update_91() {
  $ret = array();
  if ($GLOBALS["db_type"] == "pgsql") {
1245
    // node_created was created implicitly somewhere else
1246 1247 1248 1249 1250 1251 1252 1253 1254
    $ret[] = update_sql("CREATE INDEX node_changed ON {node} (changed)");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_created (created)");
    $ret[] = update_sql("ALTER TABLE {node} ADD INDEX node_changed (changed)");
  }
  return $ret;
}

Dries's avatar
 
Dries committed
1255
function update_92() {
Dries's avatar
Dries committed
1256
  $ret = array();
Dries's avatar
 
Dries committed
1257
  $ret[] = update_sql("DELETE FROM {cache}");
Dries's avatar
Dries committed
1258
  return $ret;
Dries's avatar
 
Dries committed
1259 1260
}

Dries's avatar
 
Dries committed
1261 1262 1263 1264 1265 1266 1267 1268
function update_93() {
  $ret = array();
  if ($GLOBALS['db_type'] == 'pgsql') {
    $ret[] = update_sql('DROP INDEX url_alias_src_idx');
  }
  else {
    $ret[] = update_sql('ALTER TABLE {url_alias} DROP INDEX src');
  }
Dries's avatar
 
Dries committed
1269
  $ret[] = update_sql("INSERT INTO {url_alias} (src, dst) VALUES ('node/feed', 'rss.xml')");
Dries's avatar
 
Dries committed
1270 1271 1272
  return $ret;
}

1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
function update_94() {
  /**
  * Postgres only update
  */
  $ret = array();
  if ($GLOBALS['db_type'] == 'pgsql') {
    $ret[] = update_sql('DROP FUNCTION "greatest"(integer, integer)');
    $ret[] = update_sql("
      CREATE FUNCTION greatest(integer, integer) RETURNS integer AS '
        BEGIN
          IF $2 IS NULL THEN
            RETURN $1;
          END IF;
          IF $1 > $2 THEN
            RETURN $1;
          END IF;
          RETURN $2;
        END;
      ' LANGUAGE 'plpgsql';
    ");
  }
  return $ret;
}

Dries's avatar
 
Dries committed
1297 1298 1299
function update_95() {
 $ret = array();

1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql("CREATE TABLE {node_access} (
     nid int(10) unsigned NOT NULL default '0',
     gid int(10) unsigned NOT NULL default '0',
     realm varchar(255) NOT NULL default '',
     grant_view tinyint(1) unsigned NOT NULL default '0',
     grant_update tinyint(1) unsigned NOT NULL default '0',
     grant_delete tinyint(1) unsigned NOT NULL default '0',
     PRIMARY KEY  (nid,gid,realm)
     )");
  }
  else {
    $ret[] = update_sql("CREATE TABLE {node_access} (
    nid SERIAL,
    gid integer NOT NULL default '0',
    realm text NOT NULL default '',
    grant_view smallint NOT NULL default '0',
    grant_update smallint NOT NULL default '0',
    grant_delete smallint NOT NULL default '0',
    PRIMARY KEY  (nid,gid,realm)
    )");

    $ret[] = update_sql("CREATE FUNCTION \"concat\"(text, text) RETURNS text AS '
        BEGIN
          RETURN $1 || $2;
        END;
        ' LANGUAGE 'plpgsql';");
  }
Dries's avatar
 
Dries committed
1328
  $ret[] = update_sql("INSERT INTO {node_access} VALUES (0, 0, 'all', 1, 0, 0);");
Dries's avatar
 
Dries committed
1329 1330 1331
  return $ret;
}

Dries's avatar
 
Dries committed
1332 1333
function update_96() {
  $ret = array();
Dries's avatar
 
Dries committed
1334

Dries's avatar
 
Dries committed
1335
  $ret[] = update_sql('ALTER TABLE {accesslog} ADD path VARCHAR(255) DEFAULT NULL');
1336 1337 1338 1339 1340
  $ret[] = update_sql('UPDATE {accesslog} SET path = CONCAT("node/", nid) WHERE nid != 0');
  $ret[] = update_sql('ALTER TABLE {accesslog} ADD title VARCHAR(255) DEFAULT NULL');
  /* Only supported by MySQL 4.0.4 and up
  $ret[] = update_sql('UPDATE {accesslog} a, {node} n SET a.title = n.title WHERE a.nid = n.nid');*/
  $ret[] = update_sql('ALTER TABLE {accesslog} DROP nid');
Dries's avatar
 
Dries committed
1341

1342 1343 1344 1345 1346 1347 1348 1349 1350
  if ($GLOBALS['db_type'] == 'mysql') {
    $ret[] = update_sql("ALTER TABLE {menu} ADD description varchar(255) DEFAULT '' NOT NULL");
  }
  else {
    $ret[] = update_sql("ALTER TABLE {menu} ADD description smallint");
    $ret[] = update_sql("ALTER TABLE {menu} ALTER COLUMN description SET DEFAULT '0'");
    $ret[] = update_sql("UPDATE {menu} SET description = '0'");
    $ret[] = update_sql("ALTER TABLE {menu} ALTER COLUMN description SET NOT NULL");
  }
Dries's avatar
 
Dries committed
1351

Dries's avatar
 
Dries committed
1352 1353 1354
  return $ret;
}

1355
function update_97() {
Dries's avatar
 
Dries committed
1356 1357 1358
  /**
   * Works for both PostgreSQL and MySQL
   */
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
  $convert = array('node/view/' => 'node/', 'book/view/' => 'book/', 'user/view/' => 'user/');
  foreach ($convert as $from => $to) {
    $result = db_query("SELECT pid, src FROM {url_alias} WHERE src LIKE '%s%%'", $from);
    while ($alias = db_fetch_object($result)) {
      db_query("UPDATE {url_alias} SET src = '%s' WHERE pid = '%s'", str_replace($from, $to, $alias->src), $alias->pid);
    }
  }

  return array();
}

1370
function update_98() {
Dries's avatar
 
Dries committed
1371 1372 1373
  /**
   * Works for both PostgreSQL and MySQL
   */
Dries's avatar
 
Dries committed
1374
  $result = db_query("SELECT pid, src FROM {url_alias} WHERE src LIKE 'taxonomy/%%'");
1375 1376 1377 1378 1379
  while ($alias = db_fetch_object($result)) {
    list(, $page, $op, $terms) = explode('/', $alias->src);
    if ($page == 'feed' || $page == 'page') {
      switch ($op) {
        case 'or':
1380
          $new = 'taxonomy/term/'. str_replace(',', '+', $terms);
1381 1382
          break;
        case 'and':
1383
          $new = 'taxonomy/term/'. $terms;
1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
          break;
      }
      if ($new) {
        if ($page == 'feed') {
          $new .= '/0/feed';
        }
        db_query("UPDATE {url_alias} SET src = '%s' WHERE pid = '%s'", $new, $alias->pid);
      }
    }
  }

  return array();
}

1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441
function update_99() {