You are here

function plus1_update_6200 in Plus 1 6.2

Upgrade to using VotingAPI 2.

File

./plus1.install, line 36
A simple +1 voting widget module.

Code

function plus1_update_6200() {
  $ret = array();
  if (db_table_exists('plus1_vote')) {

    // Convert v1 style vote table to votingapi. See project page.
    $result = db_query("SELECT * FROM {plus1_vote}");
    while ($row = db_fetch_object($result)) {
      $insert = db_query("INSERT INTO {votingapi_vote} (content_type, content_id, value, value_type, tag, uid, timestamp, vote_source) VALUES('node', {$row->nid}, {$row->vote}, 'points', 'vote', {$row->uid}, {$row->created}, '127.0.0.1')");
      if ($insert !== FALSE) {

        // Deleting the converted records allows this to be re-run if time runs out.
        db_query("DELETE FROM {plus1_vote} WHERE uid = {$row->uid} AND nid = {$row->nid} AND created = {$row->created}");
      }
    }
    db_drop_table($ret, 'plus1_vote');

    // Tell them how to update.
    $ret[] = array(
      'success' => TRUE,
      'query' => t('Set your Votingapi "Vote tallying" option for cron-time and invoke cron. You may then set the option back.'),
    );
  }
  else {
    $ret[] = array(
      'success' => TRUE,
      'query' => t('This is not an update from version 1, so this update was bypassed.'),
    );
  }
  return $ret;
}