You are here

function panels_update_1000 in Panels 6.3

Same name and namespace in other branches
  1. 5.2 panels.install \panels_update_1000()

File

./panels.install, line 402

Code

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;
}