You are here

function system_update_145 in Drupal 4

Same name and namespace in other branches
  1. 5 modules/system/system.install \system_update_145()

File

database/updates.inc, line 667

Code

function system_update_145() {
  $default_theme = variable_get('theme_default', 'bluemarine');
  $themes = list_themes();
  if (!array_key_exists($default_theme, $themes)) {
    variable_set('theme_default', 'bluemarine');
    $default_theme = 'bluemarine';
  }
  $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);

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