Commit 3cca50da authored by webchick's avatar webchick

#817216 by ctmattice1, chx, Stevel, Damien Tournoud: Fixed system_update_7008...

#817216 by ctmattice1, chx, Stevel, Damien Tournoud: Fixed system_update_7008 does not work, deal with invalid poll choices, and move poll-related upgrade logic to Poll module.
parent 2cca6c57
......@@ -138,11 +138,28 @@ function poll_schema() {
}
/**
* Use the poll_choice primary key to record votes in poll_votes rather than
* the choice order. Rename chorder to weight.
*
* Rename {poll_choices} table to {poll_choice} and {poll_votes} to {poll_vote}.
*/
function poll_update_7001() {
db_rename_table('poll_choices', 'poll_choice');
// 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_update('poll_votes')
->expression('chid', DatabaseConnection::prefixTables('COALESCE((SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid), 0)'))
->execute();
// Delete invalid votes.
db_delete('poll_votes')->condition('chid', 0)->execute();
// Remove old chorder column.
db_drop_field('poll_votes', 'chorder');
// 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'));
db_rename_table('poll_votes', 'poll_vote');
db_rename_table('poll_choices', 'poll_choice');
}
/**
......
......@@ -1794,18 +1794,7 @@ function system_update_7007() {
* the choice order. Rename chorder to weight.
*/
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'));
}
// Moved to poll_update_7001().
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment