system_update_7008

Versions
7
system_update_7008()

Use the poll_choice primary key to record votes in poll_votes rather than the choice order. Rename chorder to weight.

Related topics

Code

modules/system/system.install, line 1893

<?php
function system_update_7008() {
  if (db_table_exists('poll_votes')) {
    // Add chid column and convert existing votes.
    db_add_field('poll_votes', 'chid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
    db_add_index('poll_votes', 'chid', array('chid'));
    db_query("UPDATE {poll_votes} SET chid = (SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid)");
    // Remove old chorder column.
    db_drop_field('poll_votes', 'chorder');
  }
  if (db_table_exists('poll_choices')) {
    // Change the chorder column to weight in poll_choices.
    db_change_field('poll_choices', 'chorder', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
  }
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.