You are here

function system_update_145 in Drupal 5

Same name and namespace in other branches
  1. 4 database/updates.inc \system_update_145()

File

modules/system/system.install, line 1777

Code

function system_update_145() {
  $default_theme = variable_get('theme_default', 'garland');
  $themes = list_themes();
  if (!array_key_exists($default_theme, $themes)) {
    variable_set('theme_default', 'garland');
    $default_theme = 'garland';
  }
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'pgsql':
      db_change_column($ret, 'blocks', 'region', 'region', 'varchar(64)', array(
        'default' => "'left'",
        'not null' => TRUE,
      ));
      db_add_column($ret, 'blocks', 'theme', 'varchar(255)', array(
        'not null' => TRUE,
        'default' => "''",
      ));
      break;
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {blocks} CHANGE region region varchar(64) default 'left' NOT NULL");
      $ret[] = update_sql("ALTER TABLE {blocks} ADD theme varchar(255) NOT NULL default ''");
      break;
  }

  // Intialize block data for default theme
  $ret[] = update_sql("UPDATE {blocks} SET region = 'left' WHERE region = '0'");
  $ret[] = update_sql("UPDATE {blocks} SET region = 'right' WHERE region = '1'");
  db_query("UPDATE {blocks} SET theme = '%s'", $default_theme);

  // Initialize block data for other enabled themes.
  $themes = list_themes();
  foreach (array_keys($themes) as $theme) {
    if ($theme != $default_theme && $themes[$theme]->status == 1) {
      system_initialize_theme_blocks($theme);
    }
  }
  return $ret;
}