Skip to content
panels.install 38.2 KiB
Newer Older
<?php
// $Id$

/**
 * Test requirements for installation and running.
 */
function panels_requirements($phase) {
  $requirements = array();
  $t = get_t();
  // Assume that if the user is running an installation profile that both
  // Panels and CTools are the same release.
  if ($phase == 'install' && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install')) {
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 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 431 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 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 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 942 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 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
    // apparently the install process doesn't include .module files,
    // so we need to force the issue in order for our versioning
    // check to work.
    if (!defined('PANELS_REQUIRED_CTOOLS_API')) {
      include_once drupal_get_path('module', 'panels') . '/panels.module';
    }

    // In theory we should check module_exists, but Drupal's gating should
    // actually prevent us from getting here otherwise.
    if (!defined('CTOOLS_API_VERSION')) {
      include_once drupal_get_path('module', 'ctools') . '/ctools.module';
    }
    if (!module_invoke('ctools', 'api_version', PANELS_REQUIRED_CTOOLS_API)) {
       $requirements['panels_ctools'] = array(
         'title' => $t('CTools API Version'),
         'value' => CTOOLS_API_VERSION,
         'severity' => REQUIREMENT_ERROR,
         'description' => t('The CTools API version is too old for Panels. Panels needs at least %version.', array('%version' => PANELS_REQUIRED_CTOOLS_API))
       );
    }
  }
  return $requirements;
}

/**
 * Implementation of hook_schema().
 */
function panels_schema() {
  // This should always point to our 'current' schema. This makes it relatively easy
  // to keep a record of schema as we make changes to it.
  return panels_schema_1();
}

/**
 * Schema version 1 for Panels in D6.
 *
 * Schema v1 is now LOCKED; any changes should be done via panels_schema_2.
 */
function panels_schema_1() {
  $schema = array();

  $schema['panels_display'] = array(
    'export' => array(
      'object' => 'panels_display',
      'bulk export' => FALSE,
      'can disable' => FALSE,
      'identifier' => 'display',
    ),
    'fields' => array(
      'did' => array(
        'type' => 'serial',
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'layout' => array(
        'type' => 'varchar',
        'length' => '32',
        'default' => '',
      ),
      'layout_settings' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'panel_settings' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'cache' => array(
        'type' => 'text',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => '255',
        'default' => '',
      ),
      'hide_title' => array(
        'type' => 'int',
        'size' => 'tiny',
        'default' => 0,
      ),
    ),
    'primary key' => array('did'),
  );

  $schema['panels_pane'] = array(
    'export' => array(
      'can disable' => FALSE,
      'identifier' => 'pane',
      'bulk export' => FALSE,
    ),
    'fields' => array(
      'pid' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'did' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'no export' => TRUE,
      ),
      'panel' => array(
        'type' => 'varchar',
        'length' => '32',
        'default' => '',
      ),
      'type' => array(
        'type' => 'varchar',
        'length' => '32',
        'default' => '',
      ),
      'subtype' => array(
        'type' => 'varchar',
        'length' => '64',
        'default' => '',
      ),
      'shown' => array(
        'type' => 'int',
        'size' => 'tiny',
        'default' => 1,
      ),
      'access' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'configuration' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'cache' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'style' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'css' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'extras' => array(
        'type' => 'text',
        'size' => 'big',
        'serialize' => TRUE,
        'object default' => array(),
        'initial ' => array(),
      ),
      'position' => array(
        'type' => 'int',
        'size' => 'small',
        'default' => 0,
      ),
    ),
    'primary key' => array('pid'),
    'indexes' => array(
      'did_idx' => array('did')
    ),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
 */
function panels_install() {
  drupal_install_schema('panels');
}

/**
 * Implementation of hook_uninstall().
 */
function panels_uninstall() {
  drupal_uninstall_schema('panels');
}

function panels_update_1000() {
  // Panels D6 2 had *no* update functions in it, so the schema version is
  // completely wrong. If we run this update with no schema version, we
  // were actually that version and we must therefore skip to the proper
  // update.
  if (db_table_exists('panels_pane')) {
    $GLOBALS['SKIP_PANELS_UPDATES'] = TRUE;
    return array();
  }
  $ret   = array();

  $ret[] = update_sql("ALTER TABLE {panels_info} RENAME {panels_page}");
  $ret[] = update_sql("ALTER TABLE {panels_page} CHANGE COLUMN did pid int(10) NOT NULL DEFAULT 0;");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN did int(10) NOT NULL DEFAULT 0 AFTER pid");
  $ret[] = update_sql("UPDATE {panels_page} SET did = pid");

  $max_pid = db_result(db_query("SELECT MAX(pid) FROM {panels_page}"));
  if ($max_pid) {
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_page}_pid', $max_pid)");
  }

  $ret[]  = update_sql("ALTER TABLE {panels_area} RENAME {panels_pane}");
  $ret[]  = update_sql("ALTER TABLE {panels_pane} ADD COLUMN pid int(10) NOT NULL DEFAULT 0 FIRST");
  $ret[]  = update_sql("ALTER TABLE {panels_pane} CHANGE area panel varchar(32)");
  $result = db_query("SELECT * FROM {panels_pane}");
  while ($pane = db_fetch_object($result)) {
    $count++;
    $ret[] = update_sql("UPDATE {panels_pane} SET pid = $count WHERE did = $pane->did AND panel = '$pane->panel' AND position = $pane->position");
  }
  if ($count) {
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_pane}_pid', $count)");
  }

  $ret[] = update_sql(<<<EOT
    CREATE TABLE {panels_display} (
      did INT(10) NOT NULL DEFAULT 0 PRIMARY KEY,
      layout VARCHAR(32)
    ) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
  );
  $result = db_query("SELECT did, layout FROM {panels_page}");
  $max_did = 0;
  while ($display = db_fetch_object($result)) {
    $ret[] = update_sql("INSERT INTO {panels_display} VALUES ($display->did, '$display->layout')");
    if ($display->did > $max_did) {
      $max_did = $display->did;
    }
  }
  $ret[] = update_sql("ALTER TABLE {panels_page} DROP COLUMN layout");
  if ($max_did) {
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_display}_did', $max_did)");
  }
  return $ret;
}

function panels_update_1001() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret   = array();
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN no_blocks int(1)");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu int(1) DEFAULT 0");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab int(1)");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_weight int(4)");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_title varchar(255)");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_default int(1)");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_tab_default_parent_type varchar(10)");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_parent_title varchar(255)");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN menu_parent_tab_weight int(4)");
  return $ret;
}

// Create a field for the layout settings
function panels_update_1002() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret   = array();
  $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN layout_settings longtext");
  $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN access varchar(128) AFTER type");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN css longtext AFTER css_id");
  return $ret;
}

// Create a field for the panel settings.
function panels_update_1003() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN panel_settings longtext");
  return $ret;
}

// Kept up updates from older versions of Panels 2 for D5 to smooth updates.
// Create a field for the panel settings.
// Renumbering to proper numbering scheme.
function panels_update_5204() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret   = array();
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN name varchar(255) UNIQUE");
  $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN name varchar(255) UNIQUE");
  // Give all our panels a name.
  $ret[] = update_sql("UPDATE {panels_page} SET name = CONCAT('panel_page_', pid)");
  $ret[] = update_sql("UPDATE {panels_display} SET name = CONCAT('display_', did)");
  return $ret;
}

// Add the arguments field
function panels_update_5205() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN arguments longtext");
  return $ret;
}

// Add a field so that panes can remember their subtype so we can retrieve
// context information about it.
function panels_update_5206() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN subtype varchar(64)");
  return $ret;
}

// Add fields for displays and extra contexts
function panels_update_5207() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret   = array();
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN displays longtext");
  $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN contexts longtext");
  return $ret;
}

// Correct the mistaken {panels_display}_id when it should be {panels_display}_did
function panels_update_5208() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret   = array();
  $count = db_result(db_query("SELECT MAX(did) FROM {panels_display}"));
  $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{panels_display}_did'");
  $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{panels_display}_id'");
  if ($count) {
    $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{panels_display}_did',
    $count)");
  }

  return $ret;
}

// Update argument, relationship and context code to be more correct.
function panels_update_5209() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret    = array();
  $ret[]  = update_sql("ALTER TABLE {panels_page} ADD COLUMN relationships longtext");
  $result = db_query("SELECT * FROM {panels_page}");

  // This code removed due to call to panels_get_argument(). People with
  // older versions will just have to suffer.
  return $ret;
  panels_load_include('plugins');

  while ($page = db_fetch_object($result)) {
    $args = unserialize($page->arguments);
    $arguments = $ids = $keywords = array();
    if (!empty($args)) {
      // Update each argument
      foreach ($args as $id => $argument) {
        $name = $argument['name'];
        $info = panels_get_argument($name);
        if (!$info) {
          continue;
        }
        // Make sure the id is valid
        if (empty($argument['id'])) {
          if (empty($ids[$name])) {
            $ids[$name] = 1;
          }
          else {
            $ids[$name]++;
          }

          $argument['id'] = $ids[$name];
        }

        // Give it an identifier if it doesn't already have one
        if (empty($argument['identifier'])) {
          $argument['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
          error_log($argument['identifier']);
        }

        // Give it a unique keyword if it doesn't already have one
        if (empty($argument['keyword'])) {
          $keyword = $base = $info['keyword'];
          $count = 0;
          while (!empty($keywords[$keyword])) {
            $keyword = $base . '_' . ++$count;
          }
          $keywords[$keyword] = TRUE;
          $argument['keyword'] = $keyword;
          error_log($argument['keyword']);
        }
        $arguments[$id] = $argument;
      }
    }
    // Move old relationships (stored as contexts) to relationships, where
    // the belong
    $rels = unserialize($page->contexts);
    // Not resetting $keywords!
    $relationships = $ids = array();
    if (!empty($rels)) {
      foreach ($rels as $id => $relationship) {
        $name = $relationship['name'];
        $info = panels_get_relationship($name);
        if (!$info) {
          continue;
        }
        // Make sure the id is valid
        if (empty($relationship['id'])) {
          if (empty($ids[$name])) {
            $ids[$name] = 1;
          }
          else {
            $ids[$name]++;
          }

          $relationship['id'] = $ids[$name];
        }

        // Give it an identifier if it doesn't already have one
        if (empty($relationship['identifier'])) {
          $relationship['identifier'] = $info['title'] . ($id > 1 ? ' ' . $id : '');
        }

        // Give it a unique keyword if it doesn't already have one
        if (empty($relationship['keyword'])) {
          $keyword = $base = $info['keyword'];
          $count = 0;
          while (!empty($keywords[$keyword])) {
            $keyword = $base . '_' . ++$count;
          }
          $keywords[$keyword] = TRUE;
          $relationship['keyword'] = $keyword;
        }
        $relationships[$id] = $relationship;
      }
    }
    db_query("UPDATE {panels_page} " .
      "SET arguments = '%s', " .
      "relationships = '%s', " .
      "contexts = '%s' " .
      "WHERE pid = $page->pid", serialize($arguments), serialize($relationships), serialize(array()), $page->pid
    );
  }
  return $ret;
}

function panels_update_5210() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = 10 WHERE name = 'panels'");
  return $ret;
}

/**
 * Force a menu update
 */
function panels_update_5211() {
//  menu_rebuild();
  return array();
}

/**
 * Add a field to store pane caching information.
 */
function panels_update_5213() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN cache longtext AFTER configuration");
      $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN cache longtext AFTER panel_settings");
      break;

    case 'pgsql':
      db_add_column($ret, 'panels_pane', 'cache', 'text');
      db_add_column($ret, 'panels_display', 'cache', 'text');
  }
  return $ret;
}

/**
 * Create a new table for object caching. This isn't part of the cache
 * system.
 */
function panels_update_5214() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  return $ret;
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql(<<<EOT
        CREATE TABLE {panels_object_cache} (
          sid varchar(64),
          did integer,
          obj varchar(255),
          timestamp integer,
          data text,
          KEY (sid, obj, did),
          KEY (timestamp)
        ) /*!40100 DEFAULT CHARACTER SET utf8 */
EOT
      );
    case 'pgsql':
  }
  return !empty($ret) ? $ret : $ret;
}

/**
 * Increase the size of the data column in the {panels_object_cache} table
 * on MySQL.
 *
 * Also gets rid of some duplicate indexes resulting the CREATE TABLE queries
 * in the install() of schema 5214
 */
function panels_update_5215() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {panels_pane} ADD PRIMARY KEY (pid)");
      break;

    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {panels_pane} ADD PRIMARY KEY (pid)");
  }
  return $ret;
}

/**
 * Adds the 'shown' field to the panels_pane table in order to accomodate
 * the new show/hide panes feature.
 */
function panels_update_5216() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN shown int(1) DEFAULT 1 AFTER subtype");
      $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN title varchar(128) AFTER cache");
      $ret[] = update_sql("ALTER TABLE {panels_display} ADD COLUMN hide_title int(1) AFTER title");
      $ret[] = update_sql("ALTER TABLE {panels_display} DROP COLUMN name");
      $ret[] = update_sql("ALTER TABLE {panels_pane} ADD COLUMN visibility text AFTER access");
      break;

    case 'pgsql':
      db_add_column($ret, 'panels_pane', 'shown', 'tinyint', array('default' => 1));
      db_add_column($ret, 'panels_display', 'title', 'varchar(128)');
      db_add_column($ret, 'panels_display', 'hide_title', 'tinyint', array('default' => 0));
      $ret = update_sql("ALTER TABLE {panels_display} DROP name");
      db_add_column($ret, 'panels_pane', 'visibility', 'text');
  }
  return $ret;
}

/**
 * Add the switcher fields to the database
 */
function panels_update_5217() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_type varchar(128) AFTER no_blocks");
      $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_name varchar(128) AFTER no_blocks");
      $ret[] = update_sql("ALTER TABLE {panels_page} ADD COLUMN switcher_options longtext AFTER switcher_type");
      break;

    case 'pgsql':
      db_add_column($ret, 'panels_page', 'switcher_type', 'varchar(128)');
      db_add_column($ret, 'panels_page', 'switcher_name', 'varchar(128)');
      db_add_column($ret, 'panels_page', 'switcher_options', 'text');
  }
  return $ret;
}


/**
 * Oversight in 5216: 'tinyint' is not a field type in pgsql; the type we wanted
 * was 'smallint.'
 */
function panels_update_5218() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = array('success' => TRUE, 'query' => t('Update #5218 only has changes for PostgreSQL. There are no updates for MySQL databases - since you\'re running MySQL, you should consider this update successful.'));
      break;

    case 'pgsql':
      db_add_column($ret, 'panels_pane', 'shown', 'smallint', array('default' => 1));
      db_add_column($ret, 'panels_display', 'hide_title', 'smallint', array('default' => 0));
      $ret[] = array('success' => TRUE, 'query' => t('You can disregard failed attempts to add new columns in update #5216 as long as the two queries preceding this text were successful.'));
  }
  return $ret;
}

/**
 * Update from 5.x v2
 */
function panels_update_5299() {
  if (!empty($GLOBALS['SKIP_PANELS_UPDATES'])) {
    return array();
  }
  $ret = array();
  // Fetch schema version 1.
  $schema = panels_schema_1();

  // Certain really old versions of Panels had errors that would cause invalid
  // panes to be written. This wipes them so that the conversion won't fail:
  $ret[] = update_sql("DELETE FROM {panels_pane} WHERE pid = 0");

  // update pid and did to be serial
  db_drop_primary_key($ret, 'panels_pane');
  db_change_field($ret, 'panels_pane', 'pid', 'pid', $schema['panels_pane']['fields']['pid'], array('primary key' => array('pid')));
  db_drop_primary_key($ret, 'panels_display');
  db_change_field($ret, 'panels_display', 'did', 'did', $schema['panels_display']['fields']['did'], array('primary key' => array('did')));

  drupal_set_message(t('Please note that the Panels upgrade from Drupal 5 to Drupal 6 is far from perfect, especially where Views and CCK are involved. Please check all your panels carefully and compare them against the originals. You may need to do some rework to regain your original functionality.'));

  return $ret;
}

/**
 * Update from 6.x v2.
 */
function panels_update_6290() {

  $ret = array();

  // Fetch schema version 1.
  $schema = panels_schema_1();

  // Update size of pane 'access' field.
  db_change_field($ret, 'panels_pane', 'access', 'access', $schema['panels_pane']['fields']['access']);

  // Remove the no longer used visibility field
  if (db_column_exists('panels_pane', 'visibility')) {
    db_drop_field($ret, 'panels_pane', 'visibility');
  }

  // Remove panels_object_cache table
  if (db_table_exists('panels_object_cache')) {
    db_drop_table($ret, 'panels_object_cache');
  }

  // Doublecheck that ctools is enabled. If not, automatically disable the module.
  if (!module_exists('ctools')) {
    // Try to enable it:
    drupal_install_modules(array('ctools'));

    // If that fails, shut off all Panels.
    if (!module_exists('ctools')) {
      drupal_set_message(t('Panels now requires the Chaos Tool Suite (ctools) module to function. Panels has been disabled until you can add this module.'));
      module_disable(array('panels', 'panels_mini', 'panels_export', 'panels_node', 'panels_simple_cache'));
    }
  }

  if (!module_exists('page_manager') && db_table_exists('panels_page')) {
    drupal_set_message('Page manager module has been automatically enabled to replace the Panels pages module.');
    drupal_install_modules(array('page_manager'));
  }

  $ret[] = update_sql("DELETE FROM {system} WHERE name IN ('panels_page', 'panels_views')");

  return $ret;
}

/**
 * Special update function for the alpha2 to alpha3 transition after
 * I messed it up.
 */
function panels_update_6291() {
  $ret = array();
  // Fetch schema version 1.
  $schema = panels_schema_1();


  // Add some new fields
  db_add_field($ret, 'panels_pane', 'style', $schema['panels_pane']['fields']['style']);
  db_add_field($ret, 'panels_pane', 'css', $schema['panels_pane']['fields']['css']);
  db_add_field($ret, 'panels_pane', 'extras', $schema['panels_pane']['fields']['extras']);

  return $ret;
}

/**
 * Update panels pane fields using batch API.
 */
function panels_update_6292(&$sandbox) {
  $ret = array();

  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    // We'll -1 to disregard the uid 0...
    $sandbox['max'] = db_result(db_query('SELECT COUNT(*) FROM {panels_pane}'));
  }

  // configuration
  $result = db_query_range("SELECT pid, access, configuration FROM {panels_pane} ORDER BY pid ASC", $sandbox['progress'], 20);
  while ($pane = db_fetch_object($result)) {
    // access
    if (!empty($pane->access)) {
      $rids = explode(', ', $pane->access);
      // For safety, eliminate any non-numeric rids, as we occasionally had
      // problems with nulls and such getting in here:
      foreach ($rids as $id => $rid) {
        if (!is_numeric($rid)) {
          unset($rids[$id]);
        }
      }

      if (empty($rids)) {
        $pane->access = array();
      }
      else {
        // The old access style was just a role based system, so let's convert
        // it to that.
        $pane->access = array(
          'plugins' => array(
            array(
              'name' => 'role',
              'context' => 'logged-in-user',
              'settings' => array(
                'rids' => array_values($rids),
              )
            ),
          ),
        );
      }
    }
    else {
      $pane->access = array();
    }

    // Move style from configuration.
    $pane->configuration = unserialize($pane->configuration);
    $pane->style = array();
    if (!empty($pane->configuration['style'])) {
      $pane->style['style'] = $pane->configuration['style'];
      unset($pane->configuration['style']);
    }

    $pane->css = array();
    // Move css configuration from configuration
    if (isset($pane->configuration['css_id'])) {
      $pane->css['css_id'] = $pane->configuration['css_id'];
      unset($pane->configuration['css_id']);
    }

    if (isset($pane->configuration['css_class'])) {
      $pane->css['css_class'] = $pane->configuration['css_class'];
      unset($pane->configuration['css_class']);
    }

    // Make sure extras is an array. This isn't used by anything in Panels
    // yet, so an empty array is just fine.
    $pane->extras = array();
    db_query("UPDATE {panels_pane} SET " .
      "access = '%s', css = '%s', style = '%s', configuration = '%s', extras = '%s'" .
      " WHERE pid = %d",
      serialize($pane->access),
      serialize($pane->css),
      serialize($pane->style),
      serialize($pane->configuration),
      serialize($pane->extras),
      $pane->pid);

    $sandbox['progress']++;
  }

  $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
  if ($ret['#finished'] === 1) {
    $ret[] = array('success' => TRUE, 'query' => t('Panel panes were updated'));
  }
  return $ret;
}

/**
 * Update panels display fields using batch API.
 */
function panels_update_6293(&$sandbox) {
  $ret = array();

  if (!isset($sandbox['progress'])) {
    $sandbox['progress'] = 0;
    // We'll -1 to disregard the uid 0...
    $sandbox['max'] = db_result(db_query('SELECT COUNT(*) FROM {panels_display}'));
  }

  // configuration
  $result = db_query_range("SELECT did, panel_settings FROM {panels_display} ORDER BY did ASC", $sandbox['progress'], 20);
  while ($display = db_fetch_object($result)) {
    if (empty($display->panel_settings)) {
      $display->panel_settings = array();
    }
    else {
      $display->panel_settings = unserialize($display->panel_settings);
      if (!is_array($display->panel_settings)) {
        $display->panel_settings = array();
      }
    }

    if (isset($display->panel_settings['panel'])) {
      foreach ($display->panel_settings['panel'] as $key => $settings) {
        $display->panel_settings[$key] = $settings;
      }
      unset($display->panel_settings['panel']);
    }

    if (isset($display->panel_settings['individual'])) {
      unset($display->panel_settings['individual']);
    }

    db_query("UPDATE {panels_display} SET " .
      "panel_settings = '%s'" .
      " WHERE did = %d",
      serialize($display->panel_settings),
      $display->did);

     $sandbox['progress']++;
  }

  $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
  if ($ret['#finished'] === 1) {
    $ret[] = array('success' => TRUE, 'query' => t('Panel displays were updated'));
  }
  return $ret;
}

/**
 * Establish a baseline schema version for 6.x-3.x
 */
function panels_update_6300() {
  return array();
}

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

  if (!module_exists('page_manager') && db_table_exists('panels_page')) {
    $ret['#abort'] = array('success' => FALSE, 'query' => t('Conversion of panels pages cannot be completed without page manager module from CTools installed. Please install CTools, activate page manager, and attempt the update again.'));
    return $ret;
  }

  if (!db_table_exists('panels_page')) {
    return $ret;
  }

  // Store the node edit handlers because we merged the edit/add path and we
  // need to be able to keep these together to make sure the names work ok.
  $node_edit_handlers = array();
  page_manager_get_task('page');
  $result = db_query("SELECT * FROM {panels_page}");
  while ($p = db_fetch_object($result)) {
    $page = page_manager_page_new();
    $page->default_handlers = array();
    // Should we check for uniqueness here? It doesn't seem really
    // plausible that there could be page manager pages already.
    $page->name = $p->name;
    $page->task = 'page'; // could become custom later.
    $page->subtask = $p->name;
    $page->admin_title = $p->name;
    $page->path = $p->path;
    // convert access
    if (!empty($p->access)) {
      $rids = explode(', ', $p->access);
      // For safety, eliminate any non-numeric rids, as we occasionally had
      // problems with nulls and such getting in here:
      foreach ($rids as $id => $rid) {
        if (!is_numeric($rid)) {
          unset($rids[$id]);
        }
      }

      if (empty($rids)) {
        $page->access = array();
      }
      else {
        // The old access style was just a role based system, so let's convert
        // it to that.
        $page->access = array(
          'plugins' => array(
            array(
              'name' => 'role',
              'context' => 'logged-in-user',
              'settings' => array(
                'rids' => array_values($rids),
              )
            ),
          ),
        );
      }
    }

    // Convert menu stuff.
    $page->menu = array(
      'type' => 'none',
      'title' => '',
      'weight' => 0,
      'name' => 'navigation',
      'parent' => array(
        'type' => 'none',
        'title' => '',
        'weight' => 0,
        'name' => 'navigation',
      ),
    );

    if ($p->menu) {
      if ($p->menu_tab) {
        if ($p->menu_tab_default) {
          $page->menu['type'] = 'default tab';
          $page->menu['parent']['type'] = $p->menu_tab_default_parent_type;
          $page->menu['parent']['title'] = $p->menu_parent_title;
          $page->menu['parent']['weight'] = $p->menu_parent_tab_weight;
        }
        else {
          $page->menu['type'] = 'tab';
        }
      }
      else {
        $page->menu['type'] = 'normal';
      }

      $page->menu['title'] = $p->menu_title;
      $page->menu['weight'] = $p->menu_tab_weight;
    }

    $page->conf = array();
    $displays = unserialize($p->displays);
    $arguments = unserialize($p->arguments);

    foreach ($arguments as $id => $argument) {
      $page->arguments[$argument['keyword']] = array(
        'name' => $argument['name'],
        'identifier' => $argument['identifier'],
        'title' => $argument['title'],
        'id' => $argument['id'],
        'settings' => isset($argument['argument_settings']) ? $argument['argument_settings'] : array(),
      );

      $match = FALSE;
      $bits = explode('/', $page->path);
      foreach ($bits as $pos => $bit) {
        if ($bit == '%') {