You are here

function advpoll_update_5 in Advanced Poll 5

Same name and namespace in other branches
  1. 6 advpoll.install \advpoll_update_5()
  2. 6.2 advpoll.install \advpoll_update_5()

Conform to Drupal coding standards.

File

./advpoll.install, line 214

Code

function advpoll_update_5() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {advpoll} CHANGE uselist use_list tinyint default '0'");
      $ret[] = update_sql("ALTER TABLE {advpoll} CHANGE startdate start_date int NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {advpoll} CHANGE enddate end_date int NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {advpoll} CHANGE maxchoices max_choices int NOT NULL default '0'");
      $ret[] = update_sql("ALTER TABLE {advpoll} CHANGE showvotes show_votes tinyint NOT NULL default '1'");
      break;
    case 'pgsql':
      db_change_column($ret, 'advpoll', 'uselist', 'use_list', 'smallint', array(
        'default' => '0',
      ));
      db_change_column($ret, 'advpoll', 'startdate', 'start_date', 'integer', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_change_column($ret, 'advpoll', 'enddate', 'end_date', 'integer', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_change_column($ret, 'advpoll', 'maxchoices', 'max_choices', 'integer', array(
        'not null' => TRUE,
        'default' => '0',
      ));
      db_change_column($ret, 'advpoll', 'showvotes', 'show_votes', 'smallint', array(
        'not null' => TRUE,
        'default' => '1',
      ));
      break;
  }

  // Migrate per-content type variables that changed names.
  $content_types = array(
    'advpoll_binary',
    'advpoll_ranking',
  );
  $settings = array(
    'maxchoices' => 'max_choices',
    'showvotes' => 'show_votes',
  );
  foreach ($content_types as $type) {
    foreach ($settings as $old => $new) {
      $old_name = 'advpoll_' . $old . '_' . $type;
      if (!is_null($value = variable_get($old_name, NULL))) {
        variable_set('advpoll_' . $new . '_' . $type, $value);
        variable_del($old_name);
      }
    }
  }

  // Update the block name.
  $ret[] = update_sql("UPDATE {blocks} SET delta = 'latest_poll' WHERE delta = 'mostrecent'");

  // Update Voting API cache.
  $ret[] = update_sql("UPDATE {votingapi_cache} SET function = 'view_score' WHERE function = 'viewscore' AND content_type = 'advpoll'");
  $ret[] = update_sql("UPDATE {votingapi_cache} SET function = 'raw_score' WHERE function = 'rawscore' AND content_type = 'advpoll'");
  return $ret;
}