You are here

function radioactivity_update_1 in Radioactivity 5

File

./radioactivity.install, line 45

Code

function radioactivity_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {radioactivity} DROP PRIMARY KEY");
      $ret[] = update_sql("ALTER TABLE {radioactivity} CHANGE COLUMN nid id int NOT NULL");
      $ret[] = update_sql("ALTER TABLE {radioactivity} ADD COLUMN class varchar(7) NULL AFTER id");
      $ret[] = update_sql("UPDATE {radioactivity} SET class='node'");
      $ret[] = update_sql("ALTER TABLE {radioactivity} MODIFY COLUMN class varchar(7) NOT NULL");
      $ret[] = update_sql("ALTER TABLE {radioactivity} ADD PRIMARY KEY (id, class, decay_profile)");
      break;
    case 'pgsql':
      $ret[] = update_sql("ALTER TABLE {radioactivity} DROP CONSTRAINT radioactivity_pkey");
      $ret[] = update_sql("ALTER TABLE {radioactivity} RENAME COLUMN nid TO id");
      $ret[] = update_sql("ALTER TABLE {radioactivity} ADD COLUMN class varchar(7) NULL");
      $ret[] = update_sql("UPDATE {radioactivity} SET class='node'");
      $ret[] = update_sql("ALTER TABLE {radioactivity} ALTER COLUMN class SET NOT NULL");
      $ret[] = update_sql("ALTER TABLE {radioactivity} ADD PRIMARY KEY (id, class, decay_profile)");
      break;
  }

  // update decay profiles
  $profiles = variable_get('radioactivity_profiles', NULL);
  $new_profiles = array();
  if (is_array($profiles)) {
    foreach ($profiles as $dpid => $profile) {
      $new_profiles[$dpid] = _radioactivity_upgrade_profile($profile);
      $ret[] = array(
        'success' => TRUE,
        'query' => t('Profile %label (id=%id) upgraded', array(
          '%label' => $new_profiles[$dpid]['label'],
          '%id' => $dpid,
        )),
      );
    }
    variable_set('radioactivity_profiles', $new_profiles);
  }

  // enable radioactivity_node
  module_rebuild_cache();
  module_list(TRUE, FALSE);
  drupal_install_modules(array(
    'radioactivity_node',
  ));
  $ret[] = array(
    'success' => TRUE,
    'query' => t('Installed module %m', array(
      '%m' => 'radioactivity_node',
    )),
  );
  $ret[] = update_sql("INSERT INTO {radioactivity_node_clicks} (nid,uid,remote_address,click_timestamp) " . "SELECT nid,uid,remote_address,click_timestamp FROM {radioactivity_clicks}");
  $ret[] = update_sql("DROP TABLE {radioactivity_clicks}");
  return $ret;
}