2006-07-13 13:14:25 +00:00
<?php
2009-04-26 16:31:23 +00:00
/**
* @file
2009-05-13 19:42:18 +00:00
* Install, update and uninstall functions for the poll module.
2009-04-26 16:31:23 +00:00
*/
2007-10-05 14:43:26 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_schema().
2007-10-05 14:43:26 +00:00
*/
function poll_schema() {
$schema['poll'] = array(
2008-11-15 13:01:11 +00:00
'description' => 'Stores poll-specific information for poll nodes.',
2007-10-05 14:43:26 +00:00
'fields' => array(
2008-03-15 12:31:29 +00:00
'nid' => array(
2007-10-10 11:39:35 +00:00
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => "The poll's {node}.nid.",
2008-03-15 12:31:29 +00:00
),
2007-10-10 11:39:35 +00:00
'runtime' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'The number of seconds past {node}.created during which the poll is open.',
2008-03-15 12:31:29 +00:00
),
'active' => array(
2007-10-10 11:39:35 +00:00
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'Boolean indicating whether or not the poll is open.',
2007-10-10 11:39:35 +00:00
),
2008-03-15 12:31:29 +00:00
),
2007-10-05 14:43:26 +00:00
'primary key' => array('nid'),
2009-06-01 22:07:10 +00:00
'foreign keys' => array(
2010-08-22 13:55:53 +00:00
'poll_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
2009-06-01 22:07:10 +00:00
),
2008-03-15 12:31:29 +00:00
);
2007-10-05 14:43:26 +00:00
2008-12-05 12:50:28 +00:00
$schema['poll_choice'] = array(
2008-11-15 13:01:11 +00:00
'description' => 'Stores information about all choices for all {poll}s.',
2007-10-05 14:43:26 +00:00
'fields' => array(
2008-03-15 12:31:29 +00:00
'chid' => array(
2007-10-10 11:39:35 +00:00
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
2008-11-15 13:01:11 +00:00
'description' => 'Unique identifier for a poll choice.',
2008-03-15 12:31:29 +00:00
),
'nid' => array(
2007-10-10 11:39:35 +00:00
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'The {node}.nid this choice belongs to.',
2008-03-15 12:31:29 +00:00
),
'chtext' => array(
2007-10-10 11:39:35 +00:00
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'The text for this choice.',
2009-10-16 19:06:25 +00:00
'translatable' => TRUE,
2008-03-15 12:31:29 +00:00
),
2007-10-10 11:39:35 +00:00
'chvotes' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'The total number of votes this choice has received by all users.',
2008-03-15 12:31:29 +00:00
),
2008-05-15 20:56:48 +00:00
'weight' => array(
2007-10-10 11:39:35 +00:00
'type' => 'int',
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'The sort order of this choice among all choices for the same node.',
2007-10-10 11:39:35 +00:00
),
2008-03-15 12:31:29 +00:00
),
2007-10-10 11:39:35 +00:00
'indexes' => array(
2008-03-15 12:31:29 +00:00
'nid' => array('nid'),
),
2007-10-05 14:43:26 +00:00
'primary key' => array('chid'),
2009-06-01 22:07:10 +00:00
'foreign keys' => array(
2010-08-22 13:55:53 +00:00
'choice_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
2009-06-01 22:07:10 +00:00
),
2008-03-15 12:31:29 +00:00
);
2007-10-12 14:10:18 +00:00
2008-12-05 12:50:28 +00:00
$schema['poll_vote'] = array(
2009-02-26 07:30:29 +00:00
'description' => 'Stores per-{users} votes for each {poll}.',
2007-10-05 14:43:26 +00:00
'fields' => array(
2008-05-15 20:56:48 +00:00
'chid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
2009-02-26 07:30:29 +00:00
'description' => "The {users}'s vote for this poll.",
2008-05-15 20:56:48 +00:00
),
2008-03-15 12:31:29 +00:00
'nid' => array(
2007-10-10 11:39:35 +00:00
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
2008-11-15 13:01:11 +00:00
'description' => 'The {poll} node this vote is for.',
2008-03-15 12:31:29 +00:00
),
'uid' => array(
2007-10-10 11:39:35 +00:00
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
2009-02-26 07:30:29 +00:00
'description' => 'The {users}.uid this vote is from unless the voter was anonymous.',
2008-03-15 12:31:29 +00:00
),
2007-10-10 11:39:35 +00:00
'hostname' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => 'The IP address this vote is from unless the voter was logged in.',
2007-10-10 11:39:35 +00:00
),
2009-01-21 14:42:16 +00:00
'timestamp' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The timestamp of the vote creation.',
),
2008-03-15 12:31:29 +00:00
),
2007-12-18 12:59:22 +00:00
'primary key' => array('nid', 'uid', 'hostname'),
2009-06-01 22:07:10 +00:00
'foreign keys' => array(
2010-08-22 13:55:53 +00:00
'poll_node' => array(
'table' => 'node',
'columns' => array('nid' => 'nid'),
),
'voter' => array(
'table' => 'users',
'columns' => array('uid' => 'uid'),
),
2009-06-01 22:07:10 +00:00
),
2007-10-05 14:43:26 +00:00
'indexes' => array(
2008-05-15 20:56:48 +00:00
'chid' => array('chid'),
2007-10-05 14:43:26 +00:00
'hostname' => array('hostname'),
2008-03-15 12:31:29 +00:00
'uid' => array('uid'),
),
);
2007-10-05 14:43:26 +00:00
return $schema;
}
2008-12-05 12:50:28 +00:00
/**
2010-06-21 00:00:38 +00:00
* Use the poll_choice primary key to record votes in poll_votes rather than
* the choice order. Rename chorder to weight.
*
2008-12-05 12:50:28 +00:00
* Rename {poll_choices} table to {poll_choice} and {poll_votes} to {poll_vote}.
*/
function poll_update_7001() {
2010-06-21 00:00:38 +00:00
// 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')
2010-07-01 15:09:11 +00:00
->expression('chid', Database::getConnection()->prefixTables('COALESCE((SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid), 0)'))
2010-06-21 00:00:38 +00:00
->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'));
2009-09-29 15:13:57 +00:00
db_rename_table('poll_votes', 'poll_vote');
2010-06-21 00:00:38 +00:00
db_rename_table('poll_choices', 'poll_choice');
2008-12-05 12:50:28 +00:00
}
2009-01-21 14:42:16 +00:00
/**
2010-01-28 13:52:30 +00:00
* Add timestamp field to {poll_vote}.
2009-01-21 14:42:16 +00:00
*/
function poll_update_7002() {
$field = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
2010-01-28 13:52:30 +00:00
db_add_field('poll_vote', 'timestamp', $field);
2009-01-21 14:42:16 +00:00
}
2010-01-30 00:08:34 +00:00
/**
* Change the weight column to normal int.
*/
function poll_update_7003() {
db_change_field('poll_choice', 'weight', 'weight', array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The sort order of this choice among all choices for the same node.',
));
}
2011-05-23 23:45:57 +00:00
2012-07-16 16:45:43 +00:00
/**
* @addtogroup updates-7.x-extra
* @{
*/
2011-05-23 23:45:57 +00:00
/**
* Update the database to match the schema.
*/
function poll_update_7004() {
// Remove field default.
db_change_field('poll_vote', 'chid', 'chid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE));
}
2012-07-16 16:45:43 +00:00
/**
* @} End of "addtogroup updates-7.x-extra".
*/